swagger-api / swagger-api/swagger-codegen
python flask server: *integer* allowed values generated as array of *strings* like ["1", "2", "3"]
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Python flask server has integer allowed values presented as strings like ["1", "2", "3"].
Should be [1,2,3].
Allowed-values check is in the code of the property setter of the corresponding Model.
The following code will always raise ValueError:
# allowed values are designed to be 1, 2 and 3 but checked to be "1", "2" or "3"
mymodel.my_property = 1 # <- ValueError('Invalid value for `my_property`')
Swagger-codegen version
Current https://editor.swagger.io generator
Swagger declaration file content or url
components:
schemas:
ServiceStatus:
type: object
properties:
controlNode:
type: integer
enum: [1, 2, 3]
Generated model code
Type spec suggests "int" while allowed values are all strings!
@control_node.setter
def control_node(self, control_node: int):
"""Sets the control_node of this ServiceStatus.
:param control_node: The control_node of this ServiceStatus.
:type control_node: int
"""
allowed_values = ["1", "2", "3"] # noqa: E501
if control_node not in allowed_values:
raise ValueError(
"Invalid value for `control_node` ({0}), must be one of {1}"
.format(control_node, allowed_values)
)
self._control_node = control_node
Command line used for generation
point and click on https://editor.swagger.io
Suggest a fix/enhancement
In case of integer type the allowed values check line should be:
allowed_values = [1, 2, 3]
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 from the Python Flask generated model property's setter, especially how the OpenAPI integer enum [1, 2, 3] becomes the allowed_values list. Trace the generator entry point or template responsible for this validation and check the generated model behavior. Done means integer enum values remain integers and assigning 1 no longer raises ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100