swagger-api / swagger-api/swagger-codegen
[ALL] Wrong Schema generation
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
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
- Generate Java client from file mentioned above
- Open generated file
java-petstore\src\main\java\io\swagger\client\api\PetApi.java - Notice the signature of the method
deletePet()ispublic void deletePet(Integer petId)but should actually bepublic 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:
class Schema {
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
type: integer
not: null
properties: null
additionalProperties: null
description: null
format: int64
$ref: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
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".
Related issues/PRs
None I could find.
Suggest a fix/enhancement
None.
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 test.yaml and the Java generation command, then trace DefaultCodegenConfig.getTypeOfSchema() through getSchemaType(). Compare the generated signature in java-petstore/src/main/java/io/swagger/client/api/PetApi.java with the schema's integer/int64 values. Done means deletePet() uses Long for petId and regression coverage verifies the mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100