swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
Open generated file java-petstore\src\main\java\io\swagger\client\api\PetApi.java
Notice the signature of the method deletePet() is public void deletePet(Integer petId) but should actually be public void deletePet(Long petId).
The underlying problem is that the Schema instance generated for parameter petId is of type Schema rather than IntegerSchema. The schema does, however, have the correct values for type and format:
Thus, the method DefaultCodegenConfig.getTypeOfSchema() (used through getSchemaType()) runs into the else branch and then just returns schema.getType() - which returns "integer" rather than the expected "long".
Description
Using Codegen 3 against a Swagger 2.0 file "misinterprets" some data type (at least
int
, but there may be others).Swagger-codegen version
3.0.3
Swagger declaration file content or url
test.yaml
Command line used for generation
java -Dapis -cp swagger-codegen-cli-3.0.3.jar io.swagger.codegen.v3.cli.SwaggerCodegen generate --input-spec test.yaml --lang java --output generated/java-petstore
Steps to reproduce
java-petstore\src\main\java\io\swagger\client\api\PetApi.java
deletePet()
ispublic void deletePet(Integer petId)
but should actually bepublic void deletePet(Long petId)
.The underlying problem is that the
Schema
instance generated for parameterpetId
is of typeSchema
rather thanIntegerSchema
. The schema does, however, have the correct values fortype
andformat
:Thus, the method
DefaultCodegenConfig.getTypeOfSchema()
(used throughgetSchemaType()
) runs into theelse
branch and then just returnsschema.getType()
- which returns"integer"
rather than the expected"long"
.Related issues/PRs
None I could find.
Suggest a fix/enhancement
None.