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

swaggo use structs field name instead of xml tag #427

Open
nikgalushko opened this issue Jun 30, 2019 · 6 comments
Open

swaggo use structs field name instead of xml tag #427

nikgalushko opened this issue Jun 30, 2019 · 6 comments

Comments

@nikgalushko
Copy link

nikgalushko commented Jun 30, 2019

Describe the bug
Hi. Swaggo doesn't use structs xml tag when it generate a swagger.yml/swagger.json
I have a struct like this:

type Data struct {
    Name string `xml:"name_field"`
    Photo int `xml:"super_photo_id"`
}

and my swagger.yml is wrong and include this:

  pkg.Data:
    properties:
      name:
        type: string
      photo:
        type: integer
    type: object

Expected behavior

  pkg.Data:
    properties:
      name_field:
        type: string
      super_photo_id:
        type: integer
    type: object

Your swag version
1.5.1

Your go version
1.12.5

Desktop (please complete the following information):

  • OS: Mac OS 10.14.5

I think you should check more than just json tag in the line parser.go

@nikgalushko
Copy link
Author

This issue is not simple. What we should do when a struct has both tags (xml & json) ?

@ubogdan
Copy link
Contributor

ubogdan commented Jul 8, 2019

Documentation is generated using Struct field name when json tags are missing.

If you are going to accept json and xml payload on the same route based on http "Accept" header, I don't see a real reason to have different field name for each encoding.

Please read the following section "Why JSON is Better Than XML" from this link https://www.w3schools.com/js/js_json_xml.asp and if you still consider XML should be a must , will see what we can do.

@nikgalushko
Copy link
Author

Hi, XML wasn't my choice and I have not any chance to change it to JSON. Ok, double tags is not a real option.

@ubogdan
Copy link
Contributor

ubogdan commented Jul 8, 2019

This apparently small change needs huge modifications in the parser, and I don't see them done very fast at least if someone have some time to do it for you.
Meanwhile you may finish your project , so my proposay is to add json tags to your struct , so the docuemntation will be generated as you need.
And you should ask @easonlin404 for an aproval of this feature.

@nikgalushko
Copy link
Author

nikgalushko commented Jul 8, 2019

Ok, but I have a local patch to swag (for both tickets).

@ubogdan
Copy link
Contributor

ubogdan commented Jul 18, 2019

We may change it to listen xml tag names if "@produce xml" is declared in controller annotation and json tag name is empty.

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

No branches or pull requests

2 participants