Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [HTML2] No models for alias types generated, html docs broken #13312

Closed
5 of 6 tasks
pbarnes-tibco opened this issue Aug 30, 2022 · 0 comments · Fixed by #18579
Closed
5 of 6 tasks

[BUG] [HTML2] No models for alias types generated, html docs broken #13312

pbarnes-tibco opened this issue Aug 30, 2022 · 0 comments · Fixed by #18579

Comments

@pbarnes-tibco
Copy link

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

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: object
      properties:
        name:
          type: string
        identifier:
          $ref: "#/components/schemas/Identifier"

    ThingList:
      description: |
        A list of things
      type: array
      items:
        $ref: "#/components/schemas/Thing"

    Identifier:
      description: An identifier
      type: string
      minLength: 1
      pattern: '^[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"

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant