swagger-api / swagger-api/swagger-codegen

swagger-codegen is messing up the order of the generated json

Open
#6,922 0 comments 1 reaction 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

Description

Generating a json file using swagger-codegen messes up the order and does not follow the order as in yaml

Swagger-codegen version

2.2.3

Swagger declaration file content or url
Command line used for generation

swagger-codegen generate -i lotr.yaml -l swagger

Steps to reproduce

install swagger-codegen using homebrew
generate a json file from yaml file
the generated json file order of keys does not follow that in the yaml.

Doing a file> download json from http://editor.swagger.io/ preserves the ordering. But running the codegen command locally (on a mac) doesn't.

Related issues/PRs
Suggest a fix/enhancement

Either follow the YAML order or give an option that allows following the YAML order. JSON generated from swagger-codegen locally and from the online editor should not have any diff.

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 by reproducing the issue with lotr.yaml and swagger-codegen generate -i lotr.yaml -l swagger, then compare the generated JSON with the YAML and with the Swagger Editor download. Done means the local generated JSON preserves the YAML key order or clearly supports the requested ordering option without differing from the editor output.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, yaml
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.