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] Go model generated from allOf is unusable when $ref is a simple data type model #19900

Open
5 of 6 tasks
vicentepinto98 opened this issue Oct 17, 2024 · 1 comment
Open
5 of 6 tasks

Comments

@vicentepinto98
Copy link

vicentepinto98 commented Oct 17, 2024

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

A component defined in the API specification which is defined as a allOf of a single $ref which is a simple data type model gets generated as an interface{} instead of the correct type.

The same happens if the model is nullable, in which case the field is defined as an unexistent NullableInterface type.

openapi-generator version
OpenAPI declaration file content or url

schema.components block

"AllOfComponent": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SimpleStringModel"
          }
        ],
        "description": "The gateway of a network. If not specified the first ip of the network will be assigned as the gateway. If 'null' is sent, then the network doesn't have a gateway."
      },
"SimpleStringModel": {
        "type": "string"
      },      
"Body": {
        "properties": {
          "someField": {
            "$ref": "#/components/schemas/AllOfComponent"
          },
        "type": "object"
      },
Generation Details

Generation call:
java -Dlog.level=${LOG_LEVEL} -jar ${PATH} generate \ --generator-name go \ --input-spec ${JSON_SPEC} \ --enable-post-process-file \ --global-property apis,models,modelTests=true,modelDocs=false,apiDocs=false,supportingFiles \ --additional-properties=isGoSubmodule=true,enumClassPrefix=true

Generated model:

type Body struct {
	AllOfComponent *interface{} `json:"allOfComponent,omitempty"`
}
Related issues/PRs

Might be related to #17534

Suggest a fix

The generated model should have the type of the simple data type model that is being referenced, in this case string

@wing328
Copy link
Member

wing328 commented Oct 28, 2024

thanks for reporting the issue.

i've filed #19986 to fix the issue with a test

would appreciate if you can pull the branch and do a test locally to confirm it fixes the issues for your use cases as well

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