OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

"Could not process model" with nested schema #583

Open JDziurlaj opened 6 years ago

JDziurlaj commented 6 years ago
Description

I'm running into an issue where openapi-generator fails to generate files for any generation target when referencing an external schema, with a variant of the following error

[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.VoterRecordsRequest
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.VoterRecordsRequest
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.VoterRecordsRequest
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationAcknowledgement
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationAcknowledgement
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationRejection
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationRejection
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationSuccess
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: VRI.RegistrationSuccess
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: addr.json#/definitions/addr.GeneralAddressClass_type
[main] WARN  o.o.codegen.utils.ModelUtils - addr.json#/definitions/addr.GeneralAddressClass_type is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: addr.json#/definitions/addr.GeneralAddressClass_type
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:addr.json#/definitions/addr.GeneralAddressClass_type. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: addr.json#/definitions/addr.NumberedThoroughfareAddress_type
[main] WARN  o.o.codegen.utils.ModelUtils - addr.json#/definitions/addr.NumberedThoroughfareAddress_type is not defined
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: addr.json#/definitions/addr.NumberedThoroughfareAddress_type
[main] WARN  o.o.codegen.DefaultCodegen - Error obtaining the datatype from ref:addr.json#/definitions/addr.NumberedThoroughfareAddress_type. Default to 'object'
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: addr.json#/definitions/addr.GeneralAddressClass_type
Exception in thread "main" java.lang.RuntimeException: Could not process model 'VRI.Address'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:400)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:790)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:315)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:58)
Caused by: java.lang.NullPointerException
        at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:1651)
        at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:1653)
        at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1564)
        at org.openapitools.codegen.languages.AbstractJavaCodegen.fromModel(AbstractJavaCodegen.java:877)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1023)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:395)
        ... 3 more

I have no concerns that my external schemas are valid, swagger-editor is able to parse and generate documentation for them, they pass JSON schema validation tools, etc.

This schema is quite complex, and I wish I had a simpler example to give you, but I do not. However, I've linked the schemas and OpenAPI file to this issue.

openapi-generator version

3.1.0

OpenAPI declaration file content or url

gist linked schema 1 linked schema 2

Command line used for generation

java -jar .\openapi-generator-cli-3.1.0.jar generate -i vriApi.yaml -g java -o ./

Steps to reproduce

Place addr.json/ NIST_VRI_voter_records_interchange.jsonaddr.json, NIST_VRI_voter_records_interchange.json up a level from vriApi.yaml and run the command above.

java version "10.0.1" 2018-04-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

Related issues/PRs

See swagger-api/swagger-codegen#8389

Suggest a fix/enhancement
macjohnny commented 6 years ago

maybe this can help you: https://github.com/OpenAPITools/openapi-generator/issues/304