swagger-api / swagger-api/swagger-parser
Enum of type boolean and array omitted
Open
@gracekarina is already working on this.
Since Feb 16, 2019.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Problem:
When defining a model with a boolean enum with only one value, true for example, the swagger-parser does not load in the enum value.
Use Case:
This is needed when setting a required parameter that only accepts true for example.
yaml definition:
swagger: '2.0'
info:
description: "some text"
version: 1.0.0
title: other text
host: fake.com
basePath: /v1
schemes:
- http
paths:
/route:
post:
summary: Create a TypeHolderEnum
description: ''
operationId: createTypeHolderEnum
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: typeHolderEnum
description: object that needs to be created
required: true
schema:
$ref: '#/definitions/TypeHolderEnum'
responses:
200:
description: Success
definitions:
TypeHolderEnum:
type: object
required:
- string_item
- number_item
- integer_item
- bool_item_1
- array_item
properties:
string_item:
type: string
enum:
- what
number_item:
type: number
format: double
enum:
- 1.234
integer_item:
type: integer
format: int32
enum:
- -2
bool_item_1:
type: boolean
enum:
- true
bool_item_2:
type: boolean
enum:
- True
bool_item_3:
type: boolean
enum:
- TRUE
bool_item_4:
type: boolean
format: int32
enum:
- True
bool_item_5:
type: boolean
format: int32
enum:
- true
bool_item_6:
type: boolean
enum: [true]
bool_item_7:
type: boolean
enum: [True]
bool_item_8:
type: boolean
enum: [ true ]
bool_item_9:
type: boolean
enum: [ True ]
array_item:
type: array
enum:
- [0, 1, 2, 3]
items:
type: integer
Get the spec parsing results with:
java -DdebugSwagger -jar /usr/local/Cellar/swagger-codegen/HEAD-e15bbc9/libexec/swagger-codegen-cli.jar generate -l python -i client.yaml -o client/ -DpackageName=client
Parsed spec, definitions result:
"definitions" : {
"TypeHolderEnum" : {
"type" : "object",
"required" : [ "array_item", "bool_item_1", "integer_item", "number_item", "string_item" ],
"properties" : {
"string_item" : {
"type" : "string",
"enum" : [ "what" ]
},
"number_item" : {
"type" : "number",
"format" : "double",
"enum" : [ 1.234 ]
},
"integer_item" : {
"type" : "integer",
"format" : "int32",
"enum" : [ -2 ]
},
"bool_item_1" : {
"type" : "boolean"
},
"bool_item_2" : {
"type" : "boolean"
},
"bool_item_3" : {
"type" : "boolean"
},
"bool_item_4" : {
"type" : "boolean",
"format" : "int32"
},
"bool_item_5" : {
"type" : "boolean",
"format" : "int32"
},
"bool_item_6" : {
"type" : "boolean"
},
"bool_item_7" : {
"type" : "boolean"
},
"bool_item_8" : {
"type" : "boolean"
},
"bool_item_9" : {
"type" : "boolean"
},
"array_item" : {
"type" : "array",
"items" : {
"type" : "integer"
}
}
}
}
}
}
We see that none of the booleans bool_item_1 to bool_item_9 loaded in true as an enum value.
Please fix the parser so it correctly sets the boolean enum value.
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.
Assessment
This issue has not been assessed yet.