Closed bark-mshort closed 2 years ago
The OAS definition is generated. I ran it through a validator and found some smaller issues. I fixed it in a branch https://github.com/commercetools/commercetools-api-reference/compare/oas_fix
Can't merge it as before the code generator has to be adjusted
I fixed the issues in the generator and the OpenApi spec file is now valid
@jenschude I'm no longer getting the errors for certain schemas that are missing, but I'm still getting the below error - are there any additional updates I need to run and/or arguments that need passed for it to run successfully?
openapi-generator generate -i https://raw.githubusercontent.com/commercetools/commercetools-api-reference/main/oas/openapi.yaml \
--additional-properties=gemName=hackathon_ct_sdk,moduleName=HackathonCtSdk \
-g ruby
| Error count: 1, Warning count: 210
Errors:
-Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.LinkedHashMap["components"]->java.util.LinkedHashMap["schemas"]->java.util.LinkedHashMap["Message"]->java.util.LinkedHashMap["allOf"]->java.util.ArrayList[1]->java.util.LinkedHashMap["discriminator"]->java.util.LinkedHashMap["mapping"]->java.util.LinkedHashMap["null"])
Warnings:
-Null key for a Map not allowed in JSON (use a converting NullKeySerializer?) (through reference chain: java.util.LinkedHashMap["components"]->java.util.LinkedHashMap["schemas"]->java.util.LinkedHashMap["Message"]->java.util.LinkedHashMap["allOf"]->java.util.ArrayList[1]->java.util.LinkedHashMap["discriminator"]->java.util.LinkedHashMap["mapping"]->java.util.LinkedHashMap["null"])
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)
Ah there is a small mistake still inside.
Could you just remove line 76330
InventoryEntryQuantitySet: '#/components/schemas/InventoryEntryQuantitySetMessage'
null: '#/components/schemas/OrderMessage' # <---- this line here
OrderPaymentAdded: '#/components/schemas/OrderPaymentAddedMessage'
and line 79819
InventoryEntryQuantitySet: '#/components/schemas/InventoryEntryQuantitySetMessagePayload'
null: '#/components/schemas/OrderMessagePayload' # <---- this line here
OrderPaymentAdded: '#/components/schemas/OrderPaymentAddedMessagePayload'
Same error - looks like the last thing that runs before I do receive the error is for ZoneAddLocationAction_allOf
Correction - it is a different error but seems to still be caused by a null request body:
Exception: Request body cannot be null. Possible cause: missing schema in body parameter (OAS v2): class RequestBody {
description: null
content: class Content {
{*/*=class MediaType {
schema: null
examples: null
example: null
encoding: null
}}
}
required: null
}
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1186)
at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1080)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:571)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:914)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.RuntimeException: Request body cannot be null. Possible cause: missing schema in body parameter (OAS v2): class RequestBody {
description: null
content: class Content {
{*/*=class MediaType {
schema: null
examples: null
example: null
encoding: null
}}
}
required: null
It was the issue with the image upload endpoint, that the code generator expected some body definition whereas the spec says it's valid to have no body type at all. 🤷
Fixed it to be a string. Tried your command and it works now.
@jenschude thanks! It successfully runs now - but still getting this error when I go to require the gem from the irb console
2: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/hackathon_ct_sdk-1.0.0/lib/hackathon_ct_sdk/models/category_created_message.rb:16:in `<top (required)>'
1: from /Users/mirandashort/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/hackathon_ct_sdk-1.0.0/lib/hackathon_ct_sdk/models/category_created_message.rb:17:in `<module:HackathonCtSdk>'
NameError (uninitialized constant HackathonCtSdk::Message)
Did you mean? HackathonCtSdk::MessageAllOf
Don't know what the openapi generator is creating there and i don't know enough of ruby to be of help here.
Okay I can open an Issue with openapi and make sure it's not an issue with the ruby generator. Essentially it's not able to load the class Message
(but I can confirm the model is there). I'll see if they can confirm whether or not it's an issue on the commercetools side or their side.
@jenschude I think this is an issue with the openapi generator after all, so I'm going to go ahead and close this issue. Thanks for all your help!!
I'm trying to generate a ruby client via OpenAPI Generator. We've used both the npm installation approach as well as the homebrew installation. When trying to generate the client via CLI, we run into a number of warnings and some errors that end up blocking file generation.
Steps to reproduce
Install CLI
Generate ruby client
Errors
The primary error seems to be
But there are also a bunch of missing schema errors too (unsure if it's related to the above error):
-attribute components.schemas.ReplicaMyCartDraft.items is missing
-attribute paths.'/{projectKey}/product-projections/search'(post).requestBody.content.'application/x-www-form-urlencoded'.schema.#/components/schemas/string is missing
As is suggested by the generator, I appended to
--skip-validate-spec
to the generator command and all files successfully populate, but the classes in the newly created gem are failing to load:Could this be an issue with the spec?