swagger-api / swagger-api/swagger-codegen
[openapi] Types are missing when YAML spec is converted to JSON
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am converting YAML spec to JSON via swagger-codegen-cli-v3. The issue is that even though the data types are defined in the source YAML schema, they are missing in the JSON output.
Swagger-codegen version
I use the latest swaggerapi/swagger-codegen-cli-v3 image.
Steps to reproduce
Here is an example.
I have a source YAML spec.yaml file like this that contains data types for properties id and type:
openapi: 3.1.0
info:
title: Test Service
version: 1.0.0
paths:
"/test":
get:
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/TestResponse"
components:
schemas:
TestResponse:
title: TestResponse
type: object
required:
- type
- id
properties:
type:
type: string
id:
type: number
I run the following command in the spec.yaml file directory:
docker run -v $(pwd):/api swaggerapi/swagger-codegen-cli-v3 generate -l openapi -i /api/spec.yaml -o /api/gen -DoutputFile=api.json
and get the JSON result without data types (string and number keywords are missing):
{
"openapi" : "3.1.0",
"info" : {
"title" : "Test Service",
"version" : "1.0.0"
},
"servers" : [ {
"url" : "/"
} ],
"paths" : {
"/test" : {
"get" : {
"responses" : {
"200" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/TestResponse"
}
}
}
}
}
}
}
},
"components" : {
"schemas" : {
"TestResponse" : {
"title" : "TestResponse",
"required" : [ "id", "type" ],
"properties" : {
"type" : { },
"id" : { }
}
}
}
}
}
Command line used for generation
docker run -v $(pwd):/api swaggerapi/swagger-codegen-cli-v3 generate -l openapi -i /api/spec.yaml -o /api/gen -DoutputFile=api.json
Related issues/PRs
Haven't found a related issue.
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 conversion with spec.yaml using the documented swagger-codegen-cli-v3 Docker command and inspect the OpenAPI generator entry point. The JSON output in /api/gen/api.json should preserve the string and number types for TestResponse.properties.type and TestResponse.properties.id.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, yaml
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100