Skip to content

Golang client can use pattern-based discriminator between oneOf#18760

Merged
wing328 merged 2 commits into
OpenAPITools:masterfrom
flussonic:master
Jun 13, 2024
Merged

Golang client can use pattern-based discriminator between oneOf#18760
wing328 merged 2 commits into
OpenAPITools:masterfrom
flussonic:master

Conversation

@maxlapshin
Copy link
Copy Markdown
Contributor

@maxlapshin maxlapshin commented May 25, 2024

Golang cannot read oneOf without clear discriminator, because it doesn't do validation and cannot choose between different options.

This is why I had to change decoding of oneOf from just parsing JSON to parsing + validating to select, which of oneOf options is ok. Sorry, but it seems to be the only correct way to work with oneOf

This PR works for me, but I suppose that I need to enhance it.

My example is in modules/openapi-generator/src/test/resources/3_0/go/oneof-with-pattern-discriminator.yaml

Maybe I need to put it to bin/configs?

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 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @lwj5 - this is for golang

@wing328
Copy link
Copy Markdown
Member

wing328 commented May 26, 2024

@maxlapshin
Copy link
Copy Markdown
Contributor Author

Would you kindly give a hint, how can I launch only particular in my cloned repo?

@wing328
Copy link
Copy Markdown
Member

wing328 commented May 27, 2024

to run the tests locally, please run mvn integration-test -f samples/openapi3/client/petstore/go/pom.xml

you will need to run a petstore server locally: https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#how-to-add-integration-tests-for-new-petstore-samples

@wing328 wing328 added this to the 7.7.0 milestone May 27, 2024
@maxlapshin
Copy link
Copy Markdown
Contributor Author

@wing328 thanks for the hints. I've checked, found my bug and updated PR. Seems that tests are passing now.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Jun 13, 2024

looks good. let's give it a try

thanks for the PR

@wing328
Copy link
Copy Markdown
Member

wing328 commented Aug 16, 2024

FYI. I've merged #19358 to improve the handling of backtick in the pattern (regex).

Please give it a try with the latest snapshot version (https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.8.0-SNAPSHOT/) and let us know if you spot any issue.

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.

2 participants