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][JAVA] html2-generator produces empty schemas in JavaScript-part of the HTML-Webpage #14642

Closed
DataWork1 opened this issue Feb 8, 2023 · 1 comment · Fixed by #18356
Closed

Comments

@DataWork1
Copy link

Description

We are using the openapi-generator Java Maven plugin to produce an html-doc from an openapi.yml with the html2-generator.
The resulting html (more precisely JavaScript) has invalid empty schemas.
The browser reports "Uncaught SyntaxError: Unexpected token ';'" and the schema fields are shown empty.
In our case this problem occurs since version 6.2.0. The official releases from 5.4.0 to 6.1.0 produce correct html.

The resulting javascript code in the generated html of version 6.2.0 and 6.3.0:
Take a look at "var schemaWrapper = ;"

<script>
  $(document).ready(function() {
    // this should contain a schema in json format (and it does for us in versions 5.4.0 - 6.1.0)
    var schemaWrapper = ;
    // --------------------------------
    var schema = findNode('schema',schemaWrapper).schema;
    if (!schema) {
      schema = schemaWrapper.schema;
    }
    ...
</script>

The plugin configuration of our pom.xml:

...
<plugin>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <apiDocsUrl>http://localhost:8080/api/api-docs.yaml</apiDocsUrl>
    <outputFileName>openapi.yml</outputFileName>
    <outputDir>${project.build.directory}/docs/openapi</outputDir>
  </configuration>
</plugin>
<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>6.3.0</version>
  <executions>
    <execution>
      <id>openapi-html</id>
      <phase>verify</phase>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <inputSpec>${project.build.directory}/docs/openapi/openapi.yml</inputSpec>
        <output>${project.build.directory}/docs/openapi/html</output>
        <generatorName>html2</generatorName>
        <configOptions>
          <sourceFolder>${project.build.directory}/docs/openapi</sourceFolder>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>
...

There are no error logs hinting at a configuration error. The openapi.yml used for conversion was identical between versions 5.4.0 to 6.1.0 and 6.2.0 to 6.3.0, except for the order of http 200 and http 4xx responses.

openapi-generator version

Tested on official maven releases from 5.4.0 up to 6.3.0.
5.4.0 to 6.1.0 produces correct results.
6.2.0 and 6.3.0 produce the empty schemas.

Steps to reproduce

Generate an html documentation page with swagger schemas using html2-generator in Version 6.2.0 or 6.3.0.
The YAML we are using contains $ref to schemas:

content:
  application/json:
    schema:
      $ref: '#/components/schemas/EndpointV3'
Related issues/PRs

I found the exact same issue on the swagger-codegen project which seems to have been fixed. For openapi-generator I could not find a report with this exact problem:
swagger-api/swagger-codegen#11911
swagger-api/swagger-codegen#11953
swagger-api/swagger-codegen-generators#1072

Suggest a fix

I found this file looking very similar to the one fixed in swagger-codegen project. So maybe it needs the same fix:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/htmlDocs2/paramB.mustache

@Backfighter
Copy link
Contributor

apiInfo.apis.operation.responses.schema seems to be the result of toString insteadof the actual hierarchy. This is what got inserted in the template in my testing:

class ArraySchema {
    class Schema {
        type: array
        format: null
        $ref: null
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }
}

Maybe jmustache doesn't search the parent context if the current one is a simple value?
Because {{{jsonSchema}}} is empty when nesting it in {#schema}. Using {#content} insteadof {#schema} in order to check whether there is a response body worked in my case.

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.

2 participants