swagger-api / swagger-api/swagger-codegen
Float values in nested examples get scrambled
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Issue with float values in nested schema examples. Those values are converted into lengthy floats with rounding errors.
Swagger-codegen version
Latest web version
Swagger declaration file content or url
swagger: '2.0'
info:
version: '0.1'
title: title
schemes:
- http
consumes:
- application/json
paths:
/example:
get:
parameters:
- name: parameter_name
in: body
description: description
schema:
$ref: '#/definitions/ExampleBody'
responses:
'200':
description: OK
definitions:
ExampleBody:
type: object
properties:
items:
type: array
items:
$ref: '#/definitions/FooItem'
example:
items:
- 123.45
- 678.91
FooItem:
properties:
price:
type: number
format: float
Command line used for generation
Tested w/ python-flask and go-server, but probably more/all are affected.
Steps to reproduce
- Paste above YAML into editor, note the example value "678.91"
- Generate server
- Look at generated YAML file, note the "new" value "678.9099999999999681676854379475116729736328125"
Suggest a fix/enhancement
Prevent recursion when parsing floats during code generation. First level float values are correct in the resulting YAML, this only occurs if you provide example for nested items like above.
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
No source file or test is named. Start by reproducing the supplied Swagger YAML through the python-flask and go-server generators, then trace how nested examples are parsed and serialized. Done means the nested values remain 123.45 and 678.91 in the generated YAML without floating-point expansion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, python, yaml
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100