Repository navigation
Closed
Labels
Description
Description
I'm attempting to generate a client for a spec which includes complex references https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
My first thought was this was a bug because it includes a circular reference but it seems to be due to the $ref references. I've linked to PRs discussing similar issues.
openapi-generator version
v4.0.0
(I also tried todays latest sha256:f6107b18532b334798cfafc7cafdb82b479b6955a2417d61f12b66eda98289f4)
OpenAPI declaration file content or url
openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/resource/{resourceId}:
get:
parameters:
- name: resourceId
in: path
required: true
description: The id of the resource to retrieve
schema:
allOf:
- $ref: '#/components/schemas/ResourceID'
operationId: list
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Resource'
components:
schemas:
Resource:
type: object
properties:
id:
allOf:
- $ref: '#/components/schemas/ResourceID'
children:
allOf:
- $ref: "#/components/schemas/ResourceChildren"
ResourceChildren:
description: A map of alias to child object.
type: object
additionalProperties:
$ref: '#/components/schemas/ResourceChild'
ResourceChild:
description: A specification of a resource's child.
required:
- id
properties:
id:
description: The ID of the child resource.
allOf:
- $ref: '#/components/schemas/ResourceID'
resource:
description: The child resource.
nullable: true
allOf:
- $ref: '#/components/schemas/Resource'
ResourceID:
type: string
example: 1234myname
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.0.0 generate \
-i /local/spec.yaml \
-g go \
-o /local/clientSteps to reproduce
The command above generates
type Resource struct {
Id string `json:"id,omitempty"`
Children ModelMap `json:"children,omitempty"`
}
type ResourceChild struct {
// The ID of the child resource.
Id string `json:"id"`
// The child resource.
Resource *Resource `json:"resource,omitempty"`
}where ModelMap is undefined.
or optionally with the flag
--generate-alias-as-modeltype Resource struct {
Id string `json:"id,omitempty"`
Children ResourceChildren `json:"children,omitempty"`
}
// A map of alias to child object.
type ResourceChildren struct {
}Suggest a fix
Shouldn't it generate ResourceChildren as
type ResourceChildren *map[ResourceID]ResourceChild
and (this may be a different issue alltogether or maybe I'm misunderstanding something) provide a definition like below and use it in place for id everywhere
type ResourceID string
Related PR
Reacted by lacksfish
Activity
auto-labeler commentedon May 23, 2019
👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
iafilius commentedon Mar 26, 2021
Hi, ran in same issue with openapi-generator-cli 4.2.2 and 5.1.0
specfile used:
https://code.vmware.com/apis/1115/velocloud-sdwan-vco-api
is generator but ModelMap is not defined
source:
and
using the suggested --generate-alias-as-model results in an empty type (but go code at least compiles)
JigarJoshi04 commentedon Feb 13, 2024
I am still facing the same issue, any possible solution?
wing328 commentedon Feb 13, 2024
did a test with the latest master and the output works (no compilation error)
please give it a try with the latest master or stable version (v7.3.0)
closing this one for the time being