openai-openapi
openai-openapi copied to clipboard
Error in generating openapi client with openapi-generator to typescript-fetch
openapi-generator-cli generate -i src/openapi.yaml -g typescript-fetch -o src/openai-client
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: 5, 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.CreateChatCompletionRequest.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:684)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:711)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Same Problem can replicate
My errror log is like this:
# 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: 2, Warning count: 10
# Errors:
# -attribute components.schemas.CreateCompletionRequest.default is not of type `object`
# -attribute components.schemas.CreateChatCompletionRequest.default is not of type `object`
# Warnings:
# -attribute components.schemas.CreateCompletionRequest.default is not of type `object`
# -attribute components.schemas.CreateChatCompletionRequest.default is not of type `object`
# at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:701)
# at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:728)
# at org.openapitools.codegen.cmd.Generate.execute(Generate.java:519)
# at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
# at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
But I am confused, it seems in the yaml components.schemas.CreateCompletionRequest we didn't define the default value for this schema I am not familar with OpenAPI format, is the default automatically built upon its sub properties' default value? If yes, then why isn't it an object? Is it a bug to OpenAPI generator?
I seee this https://stackoverflow.com/questions/58991883/jsonschema-xxx-is-not-of-type-object it seems the error indicated it actually not the problem. It is not because the type is not object, but because the object don't have required field
After some exploration,I figure out the root cause of this error.
It is on "model" definition, the OpenAPI generator doesn't support something like this:
This definition is bad. It wants it to be an enum to restrict typo error, but it also want to support arbitary model name. That's contradiction. I don't know how js define enum, but afterall it seems the two types are conflicting and not recognized by openapi generator
Two kinds of solution here,
- type:string and examples are the enum
- is there a "enum" type for json schema? I am not familar with js
- Is anyof generally not supported? Or just breaks for “str or str”
Two kinds of solution here,
- type:string and examples are the enum
- is there a "enum" type for json schema? I am not familar with js
- Is anyof generally not supported? Or just breaks for “str or str”
For 1., it seems there is only a "default" and "example", no "examples" in OpenAPI Spec or Json Schema, right? I cannot figure out when to use "default" and when to use "example", they are so alike.
But is should have "examples", how can example be single? enum is restrictions, not extensible? or many "enum" is what I think to be examples and extensible?
enum
I believe this is the cause because the generated python\java\rust code cannot well define the class "CreateChatCompletionRequestModel" they treat is as an attribute of class "CreateChatCompletionRequest" and it is an empty class with nothing.
and the json deserializer doesn't work for "CreateChatCompletionRequestModel" since it is not well defined as string, but an empty struct.
I am confused with the document of OpenAPI 3.0 https://swagger.io/specification/
It seems neither "example" nor "default" are valid keyword of the OpenAPI 3.0 schema dialect
The errors
-attribute components.schemas.CreateCompletionRequest.default is not of type object
-attribute components.schemas.CreateChatCompletionRequest.default is not of type object
disappear for me, if I comment the default in logit_bias for both objects
logit_bias: type: object x-oaiTypeLabel: map #default: null
The errors -attribute components.schemas.CreateCompletionRequest.default is not of type
object-attribute components.schemas.CreateChatCompletionRequest.default is not of typeobjectdisappear for me, if I comment the default in logit_bias for both objects
logit_bias: type: object x-oaiTypeLabel: map #default: null
Had the same issue, can confirm that this solution works. Thanks for the workaround!
x-oaiTypeLabel
So when the type is object and the default is null, it would break?
Btw, can anyone explain what is x-oaiTypeLabel to me, it seems there is many x-oai, I searched it but found nothing meaningful.