CVEProject / cve-services

This repo contains the source for the CVE Services API.
Creative Commons Zero v1.0 Universal
151 stars 70 forks source link

openapi.json doesn't work with openapi-generate #681

Open gwd opened 2 years ago

gwd commented 2 years ago

Prerequisites

Description

One of the gigantic strengths of OpenApi is the ability to auto-generate bindings for your preferred language. Unfortunately the openapi.json included in the tree doesn't seem to be suitable for this purpose.

Steps to Reproduce

openapi-generator generate -g go -i https://github.com/CVEProject/cve-services/raw/dev/api-docs/openapi.json

It would seem the references to "/schema//.json" are confusing it; even if you run it from within the tree itself; e.g.:

$ git clone https://github.com/CVEProject/cve-services
$ cd cve-services
$ openapi-generator generate -g go -i api-docs/openapi.json

...also fails.

Expected behavior:

Golang bindings are generated

Actual behavior:

I get a bunch of errors like the following:

[main] ERROR io.swagger.v3.parser.util.RemoteUrl - unable to read
java.io.FileNotFoundException: https://github.com/schemas/cve-id/list-cve-ids-response.json

Reproduces how often:

100%

Versions

staging, production

Additional Information

It would be nice if everything required to generate bindings were hosted on https://cveawg.mitre.org. Particularly if https://cveawg.mitre.org/api-docs/openapi.json was actually the openapi.json source, rather than a web page; and if the documentation page pointed you to the openapi schema that could be used to generate bindings.

Alternately, a few lines of documentation on how to generate bindings in the README here would be helpful.

Thanks.

wizedkyle commented 2 years ago

@gwd We released a new version of the swagger docs that is currently located here for testing:

I don't believe this has made its way to production yet as it is going to be bundled with the next release. Let me know if you run into any issues with those swagger docs.

gwd commented 2 years ago

@wizedkyle Thanks for the quick response!

Now I get this error with openapi-generator:

$ openapi-generator generate -g go -i https://cveawg-test.mitre.org/api-docs/openapi.json
[main] WARN  io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because "items" is null
    at io.swagger.v3.parser.processors.SchemaProcessor.processArraySchema(SchemaProcessor.java:196)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:47)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:39)
    at io.swagger.v3.parser.processors.ComponentsProcessor.processSchemas(ComponentsProcessor.java:226)
    at io.swagger.v3.parser.processors.ComponentsProcessor.processComponents(ComponentsProcessor.java:140)
    at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:50)
    at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:175)
    at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:154)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:89)
    at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
    at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:525)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:583)
    at org.openapitools.codegen.cmd.Generate.execute(Generate.java:433)
    at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 1, Warning count: 0
Errors: 
    -Cannot invoke "io.swagger.v3.oas.models.media.Schema.get$ref()" because "items" is null

    at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:556)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:583)
    at org.openapitools.codegen.cmd.Generate.execute(Generate.java:433)
    at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

swagger-codegen also has some sort of error, but seems to actually generate something (haven't yet had a chance to look at it to see if it's sane):

$ swagger-codegen generate -l go -i https://cveawg-test.mitre.org/api-docs/openapi.json
12:38:48.611 [Thread-0] WARN  io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.NullPointerException: null
    at io.swagger.v3.parser.processors.SchemaProcessor.processArraySchema(SchemaProcessor.java:196)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:47)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processPropertySchema(SchemaProcessor.java:117)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:54)
    at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:39)
    at io.swagger.v3.parser.processors.ComponentsProcessor.processSchemas(ComponentsProcessor.java:226)
    at io.swagger.v3.parser.processors.ComponentsProcessor.processComponents(ComponentsProcessor.java:140)
    at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:50)
    at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:183)
    at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:162)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:89)
    at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
    at io.swagger.codegen.v3.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:606)
    at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:386)
    at java.base/java.lang.Thread.run(Thread.java:829)
wizedkyle commented 2 years ago

I just re-ran swagger-codegen and everything looks intact except for the localVarReturnValue Object.

image

I'll have to take a look at openapi-generator as I don't have it installed currently to see if I can figure out why its not working.

Also if you are looking for a Go SDK I have a stable SDK that relates to CVE Services 1.1 here: https://github.com/wizedkyle/cveservices-go-sdk which was generated from swagger-codegen.

gwd commented 2 years ago

@wizedkyle That looks like it already has the JSON schema 5.0 support? How long will CVE Services 1.1 continue to work? And will you eventually be creating a golang API for the 2.x services as well? :-)

Thanks again for your help!

wizedkyle commented 2 years ago

@gwd The JSON schema 5.0 support in the cveservices-go-sdk isn't 100% but it will be correctly match the 2.x services when I update the API. CVE Services 1.1 functionality will continue to work as that is the ID reservation functionality.

I am planning on updating cveservices-go-sdk in the next couple of weeks to support 2.x however, there will most likely be breaking changes from a function naming perspective as I am moving to use swagger-codegen to automate the releases.

MaceWindu commented 2 years ago

Another issue: reference to non-existing examples component

"errorGeneric": {
"$ref": "#/components/examples/errorGeneric"
}