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] Generator results in missing objects when defining inline anyOf, or oneOf #14801

Closed
5 of 6 tasks
phegyi81 opened this issue Feb 23, 2023 · 2 comments · Fixed by #17141
Closed
5 of 6 tasks

[BUG][Go] Generator results in missing objects when defining inline anyOf, or oneOf #14801

phegyi81 opened this issue Feb 23, 2023 · 2 comments · Fixed by #17141

Comments

@phegyi81
Copy link

phegyi81 commented Feb 23, 2023

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If an inline oneOf or anyOf definition is used below an allOf or oneOf, the generated code will contain the name of the inline defined structure, but the structure itself will not be generated.

If the schema is rearranged to avoid using the inline definition, the missing part is also generated.
One possible way to do this is to define the inline oneOf or anyOf at the top level and reference it from below allOf or oneOf.

openapi-generator version

6.4.0

OpenAPI declaration file content or url
oneOf below allOf

Inline version
Referenced version

anyOf below oneOf

Inline version
Referenced version

Generation Details

Nothing special is needed beyond the steps specified in the next section. That is, download the 4 samples and compile them with the linked generator. Two of the samples are the wrongly compilable inline version, while two of them are the properly compilable referenced version.

Steps to reproduce
  • Download the gists linked above
  • Download the generator script also
  • Run the script generate.sh
  • Recognise that
    • AnyOfstringstring is missing from go-anyOf-below-oneOf-inline directory, while it is referenced in model_b.go
    • OneOfDE and NullableOneOfDE are missing from go-oneOf-below-allOf-inline directory, while it is referenced in model_a_all_of_attributes.go
    • The generated openapi.yaml files are not the same by byte, but they cover practically the same structure
Related issues/PRs

#11842
#6161

Suggest a fix
@phegyi81
Copy link
Author

A slightly different embedded inline/referenced spec issue is found. If an allOf is embedded in another allOf inline, then the generated type is *interface{}. If it is defined on top level and just referenced, the proper type is generated and applied in the go code.

Inline version
Referenced version

Generator:

#!/bin/bash
OPENAPI_GENERATOR_IMG=openapitools/openapi-generator-cli
OPENAPI_GENERATOR_TAG=v6.4.0
GENERATED_DIR=api_generated

rm -rf ${GENERATED_DIR}
for i in A-inline A-referenced; do 
  docker run --user $(id -u):$(id -g) --rm -v "${PWD}:/local" ${OPENAPI_GENERATOR_IMG}:${OPENAPI_GENERATOR_TAG} generate -p enumClassPrefix=true --enable-post-process-file -i /local/${i}.yaml -g go -o /local/${GENERATED_DIR}/go${i}
done

@wing328
Copy link
Member

wing328 commented Nov 20, 2023

If an inline oneOf or anyOf definition is used below an allOf or oneOf, the generated code will contain the name of the inline defined structure, but the structure itself will not be generated.

please give it another try with the latest master as I've just fixed it with #17141

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

Successfully merging a pull request may close this issue.

2 participants