Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swag init generates swagger.yaml file in reverse order #1765

Open
itaranto opened this issue Feb 20, 2024 · 2 comments
Open

swag init generates swagger.yaml file in reverse order #1765

itaranto opened this issue Feb 20, 2024 · 2 comments

Comments

@itaranto
Copy link

itaranto commented Feb 20, 2024

Describe the bug

swag init generates the swagger.yaml file in reverse order. The swagger.json file of the same spec is in correct order.

To Reproduce

Steps to reproduce the behavior:

  1. Run the following:
swag init \
    --generalInfo "${some_dir}/router.go" \
    --output "${some_dir}i/docs" \
    --outputTypes json,yaml
  1. Go to "${some_dir}" and open the swagger.yaml and swagger.json files
  2. See the contents of both files

Expected behavior
Both swagger.yaml and swagger.json files are in correct order.

Screenshots
swagger.yaml file in reverse order but swagger.json it's not.

For example, for the YAML file the description is last, for the JSON file the description is first and so on.

Your swag version
e.g. 1.16.3

Your go version
e.g. 1.21.6

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser: Firefox
  • Version: 122.0.1

Additional context
Add any other context about the problem here.

@sdghchj
Copy link
Member

sdghchj commented Feb 21, 2024

yaml file is converted from json and will lose orders as a result of using map[string]interface{} during json decoding.
if we marshal spec.Swagger directly into yaml, the generated file may be huge with many useless lines, because spec.Swagger haven't set omitempty for yaml encoding.

go-openapi/spec has not considered to marshal into yaml, I think, refer to https://github.com/go-openapi/spec/blob/master/swagger.go

@itaranto
Copy link
Author

yaml file is converted from json and will lose orders as a result of using map[string]interface{} during json decoding. if we marshal spec.Swagger directly into yaml, the generated file may be huge with many useless lines, because spec.Swagger haven't set omitempty for yaml encoding.

go-openapi/spec has not considered to marshal into yaml, I think, refer to https://github.com/go-openapi/spec/blob/master/swagger.go

OK, so I guess this could be improved by implementing a YAML marshaller in go-openapi.

As I imagine, that's no small task. I'll consider looking at the code and see if I can do a PR there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants