openai-openapi icon indicating copy to clipboard operation
openai-openapi copied to clipboard

Java code generation fails with org.openapitools.codegen.SpecValidationException

Open relango opened this issue 2 years ago • 2 comments

I am trying to build a Java SDK by autogenerating code using open API code generator, but running into problems.

When I ran the command openapi-generator generate -i openapi.yaml -g java

I am getting this exception:

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: 4, Warning count: 0
Errors:
	-attribute components.schemas.CreateFineTuneRequest.default is not of type `array`
	-attribute components.schemas.CreateAnswerRequest.default is not of type `object`
	-attribute components.schemas.CreateCompletionRequest.default is not of type `object`
	-attribute components.schemas.CreateClassificationRequest.default is not of type `object`

	at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:604)
	at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:631)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:457)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

When Run with --skip-validate-spec flag, the code generation works, but generated code fails to compile. Looks like there are some issues with schema. Can we get this fixed?

relango avatar Jan 31 '23 00:01 relango

I made a few corrections to the openai yaml and was able to create an angular typescript library. I got the same errors (Theres 5 if you use the latest openai spec. I pasted it as a gist here. https://gist.github.com/Netizine/48809371b37669800affda391192c214. Should work for you as it uses the same engine

Netizine avatar Mar 12 '23 05:03 Netizine

A couple of the examples need to be cleaned up. Some of the schemas need to have types added. Heavily typed languages like Java need more information included such as descriptions, schema types.

I need a Java SDK so I am putting in the PR's for the needed changes

https://github.com/openai/openai-openapi/pull/33

Jmfwolf avatar Mar 21 '23 18:03 Jmfwolf

We have made a ton of API changes recently but please open a new issue if you are still having issues.

logankilpatrick avatar Sep 06 '23 02:09 logankilpatrick

How did you fix that? What is the root of the issue? Can you give me some hint?

2catycm avatar Jan 26 '24 03:01 2catycm