OpenAPITools / OpenAPITools/openapi-generator
[BUG] OpenAPI tags elements is ignored while generating Spring API interface
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [ x] Have you tested with the latest master to confirm the issue still exists?
- [ x] Have you searched for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [x ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Currently the tags attribute on root level of OpenAPI is not respected while generating Spring MVC API interfaces.
The @Api annotation only contains value and description.
This leads to problems while using SwaggerUI in Spring Boot which will always generates in this case default groups which mostly do not contain any endpoint.
In my opinion the reason for this is that the moustache template is not complete.
see https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
----> @Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
openapi-generator version
5.0.0 of generator plugin
OpenAPI declaration file content
openapi: "3.0.0"
info:
title: Echo Dummy API
version: 2.0.0
servers:
- url: http://echoapi.frank-herling.de
description: URL for PROD
- url: http://localhost:8090
description: URL for the local dev
tags:
- name: echoapi
paths:
/echo:
get:
tags:
- echoapi
operationId: getEcho
summary: 'will return the give message with prefix Echo'
parameters:
- name: "message"
in: query
schema:
type: string
style: form
required: true
allowEmptyValue: false
responses:
'200':
description: |-
200 response
content:
application/json:
schema:
$ref: '#/components/schemas/echoResponse'
example: { "message": "Echo: something" }
components:
schemas:
defaultResponse:
required:
- id
type: object
properties:
id:
type: string
description: 'Dummy ID'
echoResponse:
required:
- message
type: object
properties:
message:
type: string
description: 'The message'
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: [ ] # use the same name as above
Generation Details
Maven Plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/api.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>de.frankherling.k8s.dummy.api</apiPackage>
<modelPackage>de.frankherling.k8s.dummy.api.model</modelPackage>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<httpUserAgent>echodummyapi-client</httpUserAgent>
<delegatePattern>false</delegatePattern>
<openApiNullable>false</openApiNullable>
<interfaceOnly>true</interfaceOnly>
<hideGenerationTimestamp>false</hideGenerationTimestamp>
<serializableModel>true</serializableModel>
<snapshotVersion>true</snapshotVersion>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Just run code generation and check for missing tags attribute in @Api annotation
Related issues/PRs
Suggest a fix
Enhance @Api annotation by tags attribute
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/JavaSpring/api.mustache, identified in the issue as the template producing the @Api annotation. Generate the supplied OpenAPI specification with the Spring generator and inspect the generated interface. Done means the root tags value is represented in the generated @Api annotation so Swagger UI groups the endpoint correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100