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

Use yaml.Unmarshal for swagger.yaml #1932

Merged
merged 3 commits into from Dec 21, 2018

Conversation

@blp1526
Copy link
Contributor

@blp1526 blp1526 commented Dec 15, 2018

Converting JSON to YAML, we need yaml.Unmarshal to keep the right number type.

via https://github.com/ghodss/yaml/blob/f5bccc04aa10faf16af8a8c9664a452bf7d80101/yaml.go#L65-L81

An example is here.

apidsl.Attribute("id", design.Integer, "Unique bottle ID", func() {
  apidsl.Example(1234567)
})

Using json.Unmarshal, goagen swagger generates this swagger.yaml.

id:
  description: Unique bottle ID
  example: 1.234567e+06
  format: int64
  type: integer

After using yaml.Unmarshal, goagen swagger generates this swagger.yaml.

id:
  description: Unique bottle ID
  example: 1234567
  format: int64
  type: integer
@raphael
Copy link
Member

@raphael raphael commented Dec 16, 2018

This is great! Do you think you could write a test that would fail without this change and add it to generator_test.go? thank you!

@blp1526
Copy link
Contributor Author

@blp1526 blp1526 commented Dec 20, 2018

@raphael

Thank you for your review.
I add two commits.
e299f72 has a test which fails by json.Unmarshal.
d62bf94 passes a test by using yaml.Unmarshal.

@raphael
Copy link
Member

@raphael raphael commented Dec 21, 2018

This is great, thank you! One last ask :) - could you backport this fix to the v1 branch please? (simply cherry-pick the merge commit into a new branch created off of v1).

@raphael raphael merged commit 4a2fb39 into goadesign:master Dec 21, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@blp1526 blp1526 deleted the use_yaml_unmarshal_for_swagger_yaml branch Dec 22, 2018
blp1526 added a commit to blp1526/goa that referenced this issue Dec 22, 2018
* Use yaml.Unmarshal for swagger.yaml

* Add jsonToYAML to goagen/gen_swagger/generator.go

* Update jsonToYAML
raphael added a commit that referenced this issue Jan 29, 2019
* Use yaml.Unmarshal for swagger.yaml

* Add jsonToYAML to goagen/gen_swagger/generator.go

* Update jsonToYAML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants