swagger-api / swagger-api/swagger-codegen

Generated Python API returns wrong JSON

Open
#12,457 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

Somewhere in the generated api_client.py __deserialize code the returned JSON:

 {'key:top': [{'name': 'Gunnar', 'surname': 'Green', 'age': 34, 'shoe-size': 47}]}

is wrongly converted to:

 {'keytop': [{'age': 34, 'name': 'Gunnar', 'shoe_size': 47, 'surname': 'Green'}]}

Note how the colon character has disappeared in 'key:top' !

Using colons like this is according to the how YANG data is encoding namespaces in JSON,
see: https://datatracker.ietf.org/doc/html/rfc7951#page-5

Reference to what I believe is the source code:
https://github.com/swagger-api/swagger-codegen/blob/61cfeac3b9d855b4eb8bffa0d118bece117bcb7d/modules/swagger-codegen/src/main/resources/python/api_client.mustache#L250

Cheers, Toby

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-codegen/src/main/resources/python/api_client.mustache at the referenced __deserialize code, then compare its handling of the sample JSON with RFC 7951's namespace encoding. Reproduce the conversion using the reported key:top and shoe-size values; done means the colon is preserved while the existing nested values still deserialize correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.