opsgenie / opsgenie-oas

Apache License 2.0
11 stars 24 forks source link

Generator fails with NPE #48

Open aSapien opened 5 years ago

aSapien commented 5 years ago

Steps to reproduce:

Run
swagger-codegen generate -i https://raw.githubusercontent.com/opsgenie/opsgenie-oas/master/swagger.json -l scala -o ./ogswagger/

Result:

Outputs the content of swagger.json to stdout and appends the following at the end:

Exception in thread "Thread-1" java.lang.NullPointerException
    at io.swagger.v3.parser.converter.SwaggerConverter.lambda$convert$0(SwaggerConverter.java:199)
    at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at io.swagger.v3.parser.converter.SwaggerConverter.convert(SwaggerConverter.java:198)
    at io.swagger.v3.parser.converter.SwaggerConverter.readLocation(SwaggerConverter.java:95)
    at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
    at io.swagger.codegen.v3.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:495)
    at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:340)
    at java.lang.Thread.run(Thread.java:748)

I've tried using the same config as in the pom.xml with the following command, but got the same result:

swagger-codegen generate -c ./config.json --invoker-package com.opsgenie.oas.sdk --api-package com.opsgenie.oas.sdk.api --model-package com.opsgenie.oas.sdk.model -i ./swagger.json -l scala --output ./

config.json:

{
    "groupId": "com.opsgenie.oas",
    "artifactId": "opsgenie-sdk-swagger",
    "artifactVersion": "1.0.9",
    "developerName": "Alp, Baris, Mustafa, Halil, Alperen, Zafer",
    "developerEmail": "support@opsgenie.com",
    "developerOrganization": "OpsGenie",
    "developerOrganizationUrl": "https://www.opsgenie.com/",
    "hideGenerationTimestamp": "true",
    "dateLibrary": "joda",
    "library": "jersey2",
    "sortParamsByRequiredFlag": "false",
    "useBeanValidation": "true",
    "performBeanValidation": "true",
    "supportJava6": "false",
    "useRuntimeException": "true",
    "licenseName": "Apache License 2.0 (Apache-2.0)",
    "licenseUrl": "https://www.apache.org/licenses/LICENSE-2.0"
 }

Please assist 🙏

wing328 commented 5 years ago

@aSapien Seems like the spec contains validation errors:

$ swagger-cli validate https://raw.githubusercontent.com/opsgenie/opsgenie-oas/master/swagger.json
Swagger schema validation failed.
  Additional properties not allowed: nullable at #/definitions/EscalationRepeat/properties/closeAlertAfterAll

JSON_OBJECT_VALIDATION_FAILED

After the spec has been updated to address the validation issue, you may also want to try OpenAPI Generator to generate the clients, e.g.

npm install @openapitools/openapi-generator-cli -g
openapi-generator generate -i https://raw.githubusercontent.com/opsgenie/opsgenie-oas/master/swagger.json -g scala-httpclient-deprecated -o /tmp/scala
bougar commented 4 years ago

Try with swagger-codegen v2.4.14. The cause of the most part of the problems is that the swagger specification is not correctly adapted to swagger: 2.0. It is mixed with the openapi:3.0.x specification :(

bougar commented 4 years ago

It should be fixed on https://github.com/opsgenie/opsgenie-oas/pull/53 :P