Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13831
Closed
Open
Issue created Oct 26, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][GO] unused import "time"

Created by: NickUfer

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

The go generator generates unused import "time" statements which makes compilation impossible.

This happens when the model has anyOf, oneOf or allOf statements. import "time" is created when any of the vars of a model is of type time.Time. But this is wrong as model.vars includes all vars from anyOf, oneOf or allOf IF the model itself does not have any properties. This leads to imports which are actually required by referenced structs in other files

image

image

Here the nested Files struct causes the parent to add import "time"

openapi-generator version

6.2.0

OpenAPI declaration file content or url

This spec is generated by https://github.com/directus/directus

https://gist.github.com/NickUfer/3c004a00df5ca1420b9949613ddaeb61

Minimal spec:

https://gist.github.com/NickUfer/dcf51a1a86b06b5a9924753e12e6c437

Generation Details

config file:

disallowAdditionalPropertiesIfNotPresent: true
packageName: directusclient
generateInterfaces: true
structPrefix: true
enumClassPrefix: true

cmd:

generate -i /tmp/oas.yaml -g go -o "/tmp/directusclient" -c /tmp/go.yml
Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/13833

Suggest a fix
Assignee
Assign to
Time tracking