Skip to content

feat(golang): support for wrapped and xml name#21899

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
sruehl:feat/golang_xml_wrapped_support
Sep 4, 2025
Merged

feat(golang): support for wrapped and xml name#21899
wing328 merged 3 commits into
OpenAPITools:masterfrom
sruehl:feat/golang_xml_wrapped_support

Conversation

@sruehl

@sruehl sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

Resolves #21898

This PR enables wrapped and xml name support in Golang

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

@wing328 low hanging fruit with a easy fix and big impact. Ready to review and to be merged.

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d @lwj5 ready for review

@wing328

wing328 commented Sep 4, 2025

Copy link
Copy Markdown
Member

@sruehl thanks for the PR

what about updating modules/openapi-generator/src/test/resources/3_0/go/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml with some test schemas to cover this change moving forward?

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

the test are already contained in pestore.yaml, or do you have something specific in mind?
image
(Edit: source

)

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

I added two array types for wrapped to that file you mentioned

@sruehl
sruehl force-pushed the feat/golang_xml_wrapped_support branch from 3a14e19 to 8426f4b Compare September 4, 2025 15:36
@wing328

wing328 commented Sep 4, 2025

Copy link
Copy Markdown
Member

@wing328

wing328 commented Sep 4, 2025

Copy link
Copy Markdown
Member

the test are already contained in pestore.yaml, or do you have something specific in mind?

that's the general one. Go petstore samples use a different one

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

https://github.com/OpenAPITools/openapi-generator/actions/runs/17469134703/job/49613034587?pr=21899

please commit the new files as well

whoops, will do, wasn't aware that that ends up in a sample, sorry :(

@sruehl

sruehl commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

@wing328 samples updated

@wing328

wing328 commented Sep 4, 2025

Copy link
Copy Markdown
Member

i did a test locally with the withXml option enabled (set to true) and got the following in one of the models:

--- a/samples/openapi3/client/petstore/go/go-petstore/model_pet.go
+++ b/samples/openapi3/client/petstore/go/go-petstore/model_pet.go
@@ -20,14 +20,14 @@ var _ MappedNullable = &Pet{}

 // Pet struct for Pet
 type Pet struct {
-       Id *int64 `json:"id,omitempty"`
-       Category *Category `json:"category,omitempty"`
-       Name string `json:"name"`
-       PhotoUrls []string `json:"photoUrls"`
-       Tags []Tag `json:"tags,omitempty"`
+       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>photoUrl"`
+       Tags []Tag `json:"tags,omitempty" xml:"tags>tag"`
        // pet status in the store
        // Deprecated
-       Status *string `json:"status,omitempty"`
+       Status *string `json:"status,omitempty" xml:"status"`
        AdditionalProperties map[string]interface{}
 }

does the change (e.g. xml:"photoUrls>photoUrl") look good to you?

@wing328

wing328 commented Sep 4, 2025

Copy link
Copy Markdown
Member

let's give it a try

i'll add some tests for the withXml option later

thanks for the contribution

@wing328
wing328 merged commit 08733aa into OpenAPITools:master Sep 4, 2025
15 checks passed
@sruehl

sruehl commented Sep 5, 2025

Copy link
Copy Markdown
Contributor Author

does the change (e.g. xml:"photoUrls>photoUrl") look good to you?

yes I does

@wing328

wing328 commented Sep 6, 2025

Copy link
Copy Markdown
Member

fyi. merged #21913 to add tests for the withXml option

@sruehl

sruehl commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

thx, I left some comments there

Goopher pushed a commit to Goopher/openapi-generator that referenced this pull request Sep 9, 2025
* feat(golang): support for wrapped and xml name

* test(golang): add two test cases for wrapped

- with name
- without name

* chore(golang): update samples
@sruehl sruehl mentioned this pull request Nov 3, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Golang] xml wrapped and name is ignored

2 participants