You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When an alias type is used in the spec for responses and request body, no model is generated and the generated html is broken. --generate-alias-as-model argument will work around some, but not all issues. That command line option will handle things like an array or map alias, but not, e.g., an alias for a string (or presumably other basic types.) We make heavy use of such aliases so that restrictions (pattern, min/max, minLength/maxLength, etc) do not need to be duplicated all over the spec.
openapi-generator version
Using 5.4.0; also occurs in 6.0.1 and master
OpenAPI declaration file content or url
Here the Identifier model is an example of an alias which does not work. ThingList is an alias for an array of Thing, and the --generate-alias-as-model option will work around that one.
components:
schemas:
Thing:
type: objectproperties:
name:
type: stringidentifier:
$ref: "#/components/schemas/Identifier"ThingList:
description: | A list of thingstype: arrayitems:
$ref: "#/components/schemas/Thing"Identifier:
description: An identifiertype: stringminLength: 1pattern: '^[A-Za-z]\S*'
Problem can be seen if a response (or a request body) refers to a ThingList:
responses:
'200':
description: The things
content:
application/json:
schema:
$ref: "#/components/schemas/ThingList"
Run the above command on the linked openapi.yaml. Open the resulting index.html in e.g. chrome. Notice that the Responses section is either empty (no --generate-alias-as-model) or partial, with "undefined" (with --generate-alias-as-model). In developer tools console, you'll see errors like
SyntaxError: Error resolving $ref pointer "file:///C:/openapi-template/bug-repos/undefined-alias-model-bug-repo/generated/index.html#/components/schemas/Identifier". (at index.html:2890:318)
Token "Identifier" does not exist.
SyntaxError: Error resolving $ref pointer "file:///C:/openapi-template/bug-repos/undefined-alias-model-bug-repo/generated/index.html#/components/schemas/ThingList". (at index.html:2890:318)
Token "ThingList" does not exist.
Looking in the generated index.html, it can be seen in the "Script section to load models into a JS Var" section, these models are missing (depending on the --generate-alias-as-model; Identifier model is always missing.)
defs["ThingList"] = ...
defs["Identifier"] = ...
Related issues/PRs
Suggest a fix
All models, alias or not, should be included for working documentation (or interpolated before handing off to the template engine.) The --generate-alias-as-model option should not be required for the more complex aliases. And aliases to simple types like Identifier should definitely be included, as this defect makes such aliases impossible to use. The only workarounds I was able to find were to repeat the alias definition everywhere, or make Identifier an object with a string property.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
When an alias type is used in the spec for responses and request body, no model is generated and the generated html is broken.
--generate-alias-as-model
argument will work around some, but not all issues. That command line option will handle things like an array or map alias, but not, e.g., an alias for a string (or presumably other basic types.) We make heavy use of such aliases so that restrictions (pattern, min/max, minLength/maxLength, etc) do not need to be duplicated all over the spec.openapi-generator version
Using 5.4.0; also occurs in 6.0.1 and master
OpenAPI declaration file content or url
Here the Identifier model is an example of an alias which does not work. ThingList is an alias for an array of Thing, and the
--generate-alias-as-model
option will work around that one.Problem can be seen if a response (or a request body) refers to a ThingList:
A complete, minimal spec to repro is here
Generation Details
openapi-generator-cli generate -g html2 -i openapi.yaml -o generated [--generate-alias-as-model]
Steps to reproduce
Run the above command on the linked openapi.yaml. Open the resulting index.html in e.g. chrome. Notice that the Responses section is either empty (no
--generate-alias-as-model
) or partial, with "undefined" (with--generate-alias-as-model
). In developer tools console, you'll see errors likeLooking in the generated index.html, it can be seen in the "Script section to load models into a JS Var" section, these models are missing (depending on the --generate-alias-as-model; Identifier model is always missing.)
Related issues/PRs
Suggest a fix
All models, alias or not, should be included for working documentation (or interpolated before handing off to the template engine.) The
--generate-alias-as-model
option should not be required for the more complex aliases. And aliases to simple types like Identifier should definitely be included, as this defect makes such aliases impossible to use. The only workarounds I was able to find were to repeat the alias definition everywhere, or make Identifier an object with a string property.The text was updated successfully, but these errors were encountered: