When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the same identifier myThing for both the request body and the schema):
paths:
/my/end/point:
put:
requestBody:
$ref: '#/components/requestBodies/myThing'
components:
requestBodies:
myThing:
content:
application/json:
schema:
$ref: '#/components/schemas/myThing'
required: true
schema:
myThing:
type: object
properties:
thing:
type: string
Then I used up with a typedef in the generated code like: type MyThing MyThing which is invalid.
I've currently worked around this by altering typedef.tmpl to do the following:
{{range .Types}}
{{if ne .TypeName .Schema.TypeDecl }}
{{ with .Schema.Description }}{{ . }}{{ else }}// {{.TypeName}} defines model for {{.JsonName}}.{{ end }}
type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}}
{{end}}
{{end}}
Which skips doing a typedef with a type name equal to it's schema declaration, but that is a bit of a hack and ideally the generator would create either unique names or be able to deduplicate identical types internally before iterating over them in the templates.
When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the same identifier
myThingfor both the request body and the schema):Then I used up with a typedef in the generated code like:
type MyThing MyThingwhich is invalid.I've currently worked around this by altering
typedef.tmplto do the following:Which skips doing a typedef with a type name equal to it's schema declaration, but that is a bit of a hack and ideally the generator would create either unique names or be able to deduplicate identical types internally before iterating over them in the templates.