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

[BUG] [GO] can't generate codes with xml tag #4733

Closed
5 tasks done
gold-kou opened this issue Dec 9, 2019 · 6 comments
Closed
5 tasks done

[BUG] [GO] can't generate codes with xml tag #4733

gold-kou opened this issue Dec 9, 2019 · 6 comments

Comments

@gold-kou
Copy link
Contributor

gold-kou commented Dec 9, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [] [Optional] Bounty to sponsor the fix (example)
Description

even though i use withXml=true, can't generate codes with xml tag .

actual:

type ResponseSample struct {

	StatusCode int64 `json:"status_code"`

	Message string `json:"message"`
}

expected(like this):

type ResponseSample struct {

        XMLName xml.Name `xml:"response"`

	StatusCode int64 `xml:"status_code"`

	Message string `xml:"message"`
}

My Go version:
go version go1.12.13 darwin/amd64

openapi-generator version

v4.1.2

OpenAPI declaration file content or url
ResponseSample:
      type: object
      properties:
        status_code:
          type: integer
          format: int64
          example: 0
        message:
          type: string
          example: 'success'
      xml:
        name: response
      required:
        - status_code
        - message
Command line used for generation
docker run -v ${PWD}:/local openapitools/openapi-generator-cli:v4.1.2 generate \
  -i /local/openapi/openapi.yaml \
  -g go-server \
  -p withXml=true \
  --output /local/${GENERATE_PATH}
Steps to reproduce

please paste the above yaml, then docker run.

Related issues/PRs

#490

Suggest a fix
@auto-labeler
Copy link

auto-labeler bot commented Dec 9, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Dec 12, 2019

-p withXml=true \

Don't think this will work.

Can you try --additional-properties withXml=true instead?

I can confirm the templates still use withXml

modules/openapi-generator/src/main/resources/go/model.mustache:38: {{name}} {{#isNullable}}*{{/isNullable}}{{{dataType}}} json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}

@gold-kou
Copy link
Contributor Author

gold-kou commented Dec 12, 2019

@wing328
Thanks for your reply.

Although tried --additional-properties withXml=true, json tag still remains 🤔

type ResponseSample struct {

	StatusCode int64 `json:"status_code"`

	Message string `json:"message"`
}

What's your openapi-generator version?

BTW, the reason why i used -p is what i got the below message when used -D.

[DEPRECATED] -D arguments after 'generate' are application arguments and not Java System Properties, please consider changing to -p, or apply your options to JAVA_OPTS, or move the -D arguments before the jar option.

@wing328
Copy link
Member

wing328 commented Dec 12, 2019

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/go -i $SPEC -g $GENERATOR -o $STUB_DIR --additional-properties packageName=petstore,withXml=true,withGoCodegenComment=true $@"

That's what we use in the Go Petstore (xml) shell script so it looks to me the following is correct:
--additional-properties withXml=true

@wing328
Copy link
Member

wing328 commented Dec 12, 2019

Just did a test with the following and it works for me:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o /tmp/go_xml/ --additional-properties withXml=true -g go

and here is the Pet model:

package openapi
// Pet A pet for sale in the pet store
type Pet struct {
    Id int64 `json:"id,omitempty" xml:"id"`
    Category Category `json:"category,omitempty" xml:"category"`
    Name string `json:"name" xml:"name"`
    PhotoUrls []string `json:"photoUrls" xml:"photoUrls"`
    Tags []Tag `json:"tags,omitempty" xml:"tags"`
    // pet status in the store
    Status string `json:"status,omitempty" xml:"status"`
}

Can you try the latest stable docker image instead?

@wing328
Copy link
Member

wing328 commented Dec 13, 2019

If it's still an issue, please ping me via Slack.

Closing this for the time being.

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