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
  • #5737
Closed
Open
Issue created Mar 28, 2020 by Administrator@rootContributor

[REQ][Go Client] Support circular schema definitions

Created by: grokify

Is your feature request related to a problem? Please describe.

Valid OpenAPI specs can have circular definitions, however, this is not currently supported in generated Go client SDKs.

Validity of OpenAPI circular definitions is discussed here:

  • https://github.com/OAI/OpenAPI-Specification/issues/822
  • https://github.com/kubernetes/kubernetes/issues/52163

Such definitions will also validate on the OAS3 validators by Mermade and APIDevTools.

Currently, when such a spec is used, the invalid recursive type compile error occurs.

# github.com/grokify/go-ringcentral/codegen/engagevoice
../../../../codegen/engagevoice/model_agent_account_access.go:12:6: invalid recursive type AgentAccountAccess
../../../../codegen/engagevoice/model_campaign.go:12:6: invalid recursive type Campaign
../../../../codegen/engagevoice/model_custom_dial_zone_groups.go:12:6: invalid recursive type CustomDialZoneGroups
../../../../codegen/engagevoice/model_quota_target.go:12:6: invalid recursive type QuotaTarget

Describe the solution you'd like

The problem with circular definitions occurs in Go because the compiler cannot determine the size of such a struct. The solution is to replace the nested struct with a pointer, who's size is known, as described here:

A pointer's size is known, but how big is something that contains itself? (And the inner struct contains itself as well, as does the inner inner struct, and so on.)

https://stackoverflow.com/a/8261789/1908967

This has been confirmed to compile by manually updating the generated model files.

Describe alternatives you've considered

None yet.

Additional context

  1. The use of pointers for nested structs is also being discussed in various JSON null value threads.
    1. https://github.com/OpenAPITools/openapi-generator/issues/522
    2. https://github.com/OpenAPITools/openapi-generator/issues/5278
  2. Google's auto-generated Go client SDKs appear to always use pointers for nested structs - https://github.com/googleapis/google-api-go-client

Given how pointers are part of a long-running nullable discussion, one thought is to use a CLI parameter that will make all nested structs pointers as to make it an optional feature.

Assignee
Assign to
Time tracking