Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1623
Closed
Open
Issue created Dec 05, 2018 by Administrator@rootContributor

NullPointerException in StaticHtmlGenerator when components: doesn't have schema:

Created by: jmalin-splunk

Description

I found a possible bug the 3.0.3 generator for html. If a file has a components object that doesn't contain a schemas object, I get a NullPointerException in the StaticHtmlGenerator.

I've tested this against 17 different .yaml files. The only ones that fail have a components object that contains a securitySchemes object but not a schemas object.

The full error is:

Exception in thread "main" java.lang.NullPointerException
	at org.openapitools.codegen.languages.StaticHtmlGenerator.preprocessOpenAPI(StaticHtmlGenerator.java:197)
	at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:183)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:854)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:349)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:62)
openapi-generator version

v3.0.3. Don't know if it's a regression, because I haven't used an earlier version.

OpenAPI declaration file content or url

The entire contents of the components object is:

components:
  securitySchemes:
    SignalFxAuthenticationScheme:
      type: http
      description: >-
        Authentication with the SignalFx API using an **org** token (referred to
        as an **access** token in the web UI).
      scheme: bearer
      bearerFormat: SignalFx

Sample YAML file available as a Gist:

https://gist.github.com/jmalin-signalfx/0d18add1615f3fe19de5da716ad9b9ed

Command line used for generation
#!/usr/local/bin/bash
#
# OAS v3 yaml to HTML generator
#
# set -x
apidir="/Users/joemalin/src/api-reference"
outputdir="${apidir}/output/oas-html-v4"
generatedir="/Users/joemalin/src/openapi-generator-4/modules/openapi-generator-cli/target"
if [ -f "${outputdir}/${1}_api.html" ]; then 
    rm ${outputdir}/${1}_api.html
fi
java -jar ${generatedir}/openapi-generator-cli.jar generate \
--generator-name 'html' \
--input-spec ${apidir}/${1} \
--template-dir ${apidir}/templates/html-v4-new \
--verbose \
--output ${outputdir} > ${apidir}/logs/oas4-runlog-$(date --iso-8601='seconds').log
mv ${outputdir}/index.html ${outputdir}/${1}_api.html
Steps to reproduce

Attempt to generate HTML from the YAML.

Note: I don't think this is related to templates. I've customized the templates, but 15 YAML files work, and 2 dont', all using the same templates.

Related issues/PRs

Haven't found any.

Suggest a fix/enhancement

I looked at StaticHtmlGenerator.preprocessOpenAPI(StaticHtmlGenerator.java line 197. It's in the following method:

    public void preprocessOpenAPI(OpenAPI openAPI) {
        Info info = openAPI.getInfo();
        info.setDescription(toHtml(info.getDescription()));
        info.setTitle(toHtml(info.getTitle()));
        Map<String, Schema> models = openAPI.getComponents().getSchemas();
        for (Schema model : models.values()) {
            model.setDescription(toHtml(model.getDescription()));
            model.setTitle(toHtml(model.getTitle()));
        }
    }

I notice that the method seems to be getting Schemas objects from the Components objects, but it's not checking to see if a Schemas object actually exists. According to the OAS3 3.0.2 specification, none of the fields within the Components object is required, so a Components object that only contains a securitySchemes object is valid.

Assignee
Assign to
Time tracking