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] Imports for field types are not included when using inheritance/polymorphism #19959

Open
5 of 6 tasks
perhallgren opened this issue Oct 23, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@perhallgren
Copy link

perhallgren commented Oct 23, 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?
    In the generated model_foo.go, we have
      import (
      	"encoding/json"
      )
    
    But should have
    import (
    	"encoding/json"
    	"time"
    )
    
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I found a case where the generated Go code doesn't compile, it is missing an import of the time package. I think it's due to an incorrect implementation of polymorphism.

openapi-generator version
$ docker run --rm openapitools/openapi-generator-cli:latest version
7.10.0-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: '1.0.0'
  title: 'FooBar Service'
paths: {}
components:
  schemas:
    Foo:
      type: object
      anyOf: [] # doesn't need to contain anything, the object's properties are dropped due to the presence of anyOf
      properties:
        bar:
          format: date-time
          type: string
Generation Details

I'm using

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate \
        --input-spec /local/go-time-import.yaml \
        --generator-name go \
        --additional-properties "withGoMod=false" \
        --package-name gen \
        --output /local/gen
Steps to reproduce

If you run https://gist.github.com/perhallgren/d2af2441d7c265a06407313b064f68d6, you get:

[...]
gen/model_foo.go:22:7: undefined: time
gen/model_foo.go:43:24: undefined: time
gen/model_foo.go:45:11: undefined: time
gen/model_foo.go:53:28: undefined: time
gen/model_foo.go:70:24: undefined: time
Related issues/PRs
Suggest a fix

I'm working on #19958, with a fix that seems to solve the problem I am having.

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

1 participant