Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG][CLI][GENERATOR] NullPointer when not setting outputDir #3439

Closed
5 of 6 tasks
Fjolnir-Dvorak opened this issue Jul 24, 2019 · 5 comments
Closed
5 of 6 tasks

[BUG][CLI][GENERATOR] NullPointer when not setting outputDir #3439

Fjolnir-Dvorak opened this issue Jul 24, 2019 · 5 comments

Comments

@Fjolnir-Dvorak
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The openapi-generator-cli will throw a NullPointerException when the flag o is omitted.

openapi-generator version

master commit no. 2c4fdd0

OpenAPI declaration file content or url

Example Petstore is sufficient

Command line used for generation
openapi-generator generate \
    -g spring \
    --library spring-cloud \
    --additional-properties "java8=true" \
    --additional-properties "dateLibrary=java8" \
    --additional-properties "hideGenerationTimestamp=true" \
    --additional-properties "fullJavaUtil=true" \
    -i petstore-swagger-or-anything-else.json \
    --artifact-id demo \
    --api-package de.mo.demo.api \
    --model-package de.mo.demo.model
Steps to reproduce

The above statement will throw following NullPointer:

Exception in thread "main" java.lang.NullPointerException
        at java.io.File.<init>(File.java:277)
        at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.<init>(CodegenIgnoreProcessor.java:63)
        at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.<init>(CodegenIgnoreProcessor.java:52)
        at org.openapitools.codegen.DefaultGenerator.opts(DefaultGenerator.java:96)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:399)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Exception in thread "main" java.lang.NullPointerException

This Nullpointer will vanish if you add the flag o to the command :

openapi-generator generate \
    -g spring \
    --library spring-cloud \
    --additional-properties "java8=true" \
    --additional-properties "dateLibrary=java8" \
    --additional-properties "hideGenerationTimestamp=true" \
    --additional-properties "fullJavaUtil=true" \
    -i petstore-swagger-or-anything-else.json \
    --artifact-id demo \
    --api-package de.mo.demo.api \
    --model-package de.mo.demo.model \
    -o ./
Related issues/PRs

Found nothing

Suggest a fix

I am looking into it and will hopefully provide a pull request shortly.

@auto-labeler
Copy link

auto-labeler bot commented Jul 24, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Fjolnir-Dvorak added a commit to Fjolnir-Dvorak/openapi-generator that referenced this issue Jul 24, 2019
…builder. There are a few issues here:

- outputDir's default was set to "." but was overwritten by the builder.
- validateSpec was defaulted to true but was overwritten to false by the builder.
- strictSpecBehavior was defaulted to true but was overwritten to false by the builder.

A builder should not have primitive not nullable fields if there are fields containing default which are not nullable.
The main issue I migrated the default value setter to the builder is that fields can be nullable but have set a notnull default. If null is an indicator whether to set the value or not those values could never be set to null.
@Fjolnir-Dvorak Fjolnir-Dvorak changed the title [BUG][CLI][GENERATOR] Description [BUG][CLI][GENERATOR] NullPointer when not setting outputDir Jul 24, 2019
@jmini
Copy link
Member

jmini commented Aug 1, 2019

Isn't -o (or --output) a mandatory parameter on the CLI ?

What should be the default if omitted ? (I think a proper error indicating that the option is missing could also be ok)

@Fjolnir-Dvorak
Copy link
Contributor Author

na, it is not required. The default is the current directory

@Locour
Copy link

Locour commented Aug 20, 2019

I just downloaded version 4.1.0 as a npm package and i got the same error.

Using the cli command without -o parameter

openapi-generator generate -g typescript-angular -i swagger.json

results in the following error

Exception in thread "main" java.lang.NullPointerException
        at java.io.File.<init>(File.java:277)
        at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.<init>(CodegenIgnoreProcessor.java:63)
        at org.openapitools.codegen.ignore.CodegenIgnoreProcessor.<init>(CodegenIgnoreProcessor.java:52)
        at org.openapitools.codegen.DefaultGenerator.opts(DefaultGenerator.java:96)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:399)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)

Whereas when specifying the output parameter directly it works without any error:

 openapi-generator generate -g typescript-angular -i swagger.json -o .

Setup: Windows 10, Powershell, CMD, git bash

@Fjolnir-Dvorak
Copy link
Contributor Author

merged and working

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

Successfully merging a pull request may close this issue.

3 participants