Swagger-codegen: Path Variable uppercase in RequestMapping but lowercase in PathVariable

Created on 12 Apr 2017  路  7Comments  路  Source: swagger-api/swagger-codegen

Description


The swagger file contain the following definition (I can't share everything):

`'/pets/{PetId}':

get:
  tags:
    - Pets
  summary: Get a single pet
  description: Get a single pet
  operationId: GetSinglePet
  produces:
    - application/json
  parameters:
    - name: PetId
      in: path
      description: Unique identification of pets.
      required: true
      type: string`

The generated code is:
`

@RequestMapping(value = "/pets/{PetId}",
    produces = { "application/json" }, 
    method = RequestMethod.GET)
ResponseEntity<PetStorePetsSetupPOSTResponse> getSingleImmediatePets(@ApiParam(value = "Unique identification of Pets.",required=true ) @PathVariable("petId") String petId);

`

As you can see, the variable PetId is correct in RequestMapping and wrong in PathVariable.

it causes the following error:
{"timestamp":"2017-04-12T11:16:28.156Z","status":500,"error":"Internal Server Error","exception":"org.springframework.web.bind.MissingPathVariableException","message":"Missing URI template variable 'petId' for method parameter of type String","path":"/robtesting/pets/123"}

I don't want to manually modify the interface, could you please help me to fix this?

Ciao
Roberto

Bug

All 7 comments

@erreobi may I know which generator is that?

Please try the latest master as we've been fixing path variable naming. Please see https://github.com/swagger-api/swagger-codegen/issues/4898 for more information.

I used the maven plug in swagger-codegen-maven-plugin version 2.2.2
Here is my configuration:
<plugin> <groupId>io.swagger</groupId> <artifactId>swagger-codegen-maven-plugin</artifactId> <version>2.2.2</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>src/main/resources/pets.json</inputSpec> <language>spring</language> <apiPackage>com.rob.petstore.swagger.api</apiPackage> <modelPackage>com.rob.petstore.swagger.model</modelPackage> <invokerPackage>com.rob.petstore.swagger.invoker</invokerPackage> <modelNamePrefix>petstore</modelNamePrefix> <useJaxbAnnotations>true</useJaxbAnnotations> <ignoreFileOverride>./swagger-codegen-ignore</ignoreFileOverride> </configuration> </execution> </executions> </plugin>

You will need to build the JAR from the latest master to enjoy the fix (or you can use docker instead)

@wing328 Thanks!!

I can not download it from the public repository, is it my fault? or, when will it be in the public maven repo?

We don't do nightly build for the latest master. Can you try building it locally: mvn clean package? or use docker instead.

I cloned it and it works fine! Thanks again!

When is it planned to push it in master?

https://github.com/swagger-api/swagger-codegen/wiki/FAQ#how-long-does-it-take-to-release-a-stable-version-eg-215--216

Was this page helpful?
0 / 5 - 0 ratings