swagger-api / swagger-api/swagger-codegen
swagger-codegen-maven-plugin - does not generate correct @RequestMapping path for servers property
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The @RequestMapping does not generate properly when servers property exists inside swagger.yaml API definition
Swagger-codegen version
I am using the swagger-codegen-maven-plugin inside a SpringBoot project:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.31</version>
<executions>
<execution>
<id>generate-root-classes</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${basedir}/src/main/resources/swagger/swagger.yaml</inputSpec>
<language>spring</language>
<apiPackage>${project.groupId}.example.api.v1</apiPackage>
<modelPackage>${project.groupId}.example.model.v1</modelPackage>
<invokerPackage>${project.groupId}.example.invoker.v1</invokerPackage>
<configOptions>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>
ApiClient.java,ApiException.java,Configuration.java,JSON.java,Pair.java,StringUtil.java,TypeRef.java,ApiKeyAuth.java,Authentication.java,HttpBasicAuth.java,OAuth.java,OAuthFlow.java
</supportingFilesToGenerate>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>spring-boot</library>
<delegatePattern>true</delegatePattern>
</configOptions>
<additionalProperties>
<additionalProperty>useTags=true</additionalProperty>
<additionalProperty>errorOnUnknownEnum=true</additionalProperty>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
With:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.13</version>
</dependency>
Swagger declaration file content or url
openapi: 3.0.0
servers:
- url: /api
info:
description: Description
version: 1.0.0
title: Title
#----------------------------------
paths:
/image:
I would expect that in the generated class, the @RequestMapping parameter to contain "/api/image" but instead there is only "/image".
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2022-01-19T12:06:46.329239500+02:00[Europe/Athens]")
@Validated
public interface ExampleApi {
......
@RequestMapping(value = "/image",
produces = { "application/json", "*/*" },
method = RequestMethod.GET)
With swagger 2.0 this wasn't happening, the @RequestMapping attribute being present on class definition with the value of "basePath", and on method definition the value of the "path".
Is this a bug in the generator or there is some missing property on my side on the plugin configuration?
Also, I put the swagger file on the online editor (https://editor.swagger.io/) and the path to the API is being generated in a correct manner.
Thanks.
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
Reproduce the issue with the shown swagger.yaml, swagger-codegen-maven-plugin configuration, and SpringCodegen output. Compare the generated ExampleApi @RequestMapping values with the OpenAPI editor result, then trace how the servers URL and path are handled; done means the generated mapping includes /api/image for the provided specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100