NPE in ModelUtils.isFreeFormObject
Created by: padamstx
Description
The attached apispec causes an NPE in ModelUtils.isFreeFormObject(). Within the apispec, the "Context" schema is defined like this:
"Context":{
"type":"object",
"description":"A collection of arbitrary properties that form the context information for a message.",
"additionalProperties":{
"type":"object"
}
}
The fact that additionalProperties is set to an ObjectSchema that contains no properties seems to be the crux of the problem. Which is odd because that's a fairly common construct.
openapi-generator version
master (latest)
OpenAPI declaration file content or url
I'm attaching the full apispec which can serve as a testcase: testcase.zip
Steps to reproduce
Process the attached apispec with the "java" generator, with a command similar to this:
java -jar <location-of-jar>/openapi-generator-cli.jar generate -i testcase.json -g java -o ./java
Here is an example:
$ java -jar /work/openapitools/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i testcase.json -g java -o ./java/testcase
[main] WARN o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO o.o.c.languages.AbstractJavaCodegen - Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE="/usr/local/bin/clang-format -i"' (Linux/Mac)
[main] INFO o.o.c.languages.AbstractJavaCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] WARN o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Message'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:457)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:888)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:355)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:62)
Caused by: java.lang.NullPointerException
at org.openapitools.codegen.utils.ModelUtils.isFreeFormObject(ModelUtils.java:560)
at org.openapitools.codegen.utils.ModelUtils.unaliasSchema(ModelUtils.java:772)
at org.openapitools.codegen.DefaultCodegen.unaliasPropertySchema(DefaultCodegen.java:3403)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1708)
at org.openapitools.codegen.languages.AbstractJavaCodegen.fromModel(AbstractJavaCodegen.java:942)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1126)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:452)
... 3 more
Related issues/PRs
Suggest a fix/enhancement
I'll submit a PR that fixes the issue.