OpenAPI Spec + hey-api/openapi-ts
-
I am trying to codegen from the openapi spec, using openapi-generator-cli and @hey-api/openapi-ts, they both fail, one with:
java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml
the other one with circular dependencyIt would seem somethings wrong with the spec, I download the full spec straight from here https://github.com/NodeBB/NodeBB/tree/master/public/openapi julian
-
I am trying to codegen from the openapi spec, using openapi-generator-cli and @hey-api/openapi-ts, they both fail, one with:
java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml
the other one with circular dependencyIt would seem somethings wrong with the spec, I download the full spec straight from here https://github.com/NodeBB/NodeBB/tree/master/public/openapi julian
Hi Konrad-Moskal, this is the docs entry for that route: https://docs.nodebb.org/api/read/#tag/topics/paths/~1api~1topic~1{topic_id}~1{slug}~1{post_index}/get
It seems to resolve ok here.
In that file (
topic_id.yaml) there is- $ref: ../../components/schemas/TopicObject.yaml#/TopicObjectSlimwhich seems to be where your parser is tripping up.I am not certain what the issue is, because from that working directory, that relative path does resolve to the file in question.
Actually, I am not sure why it is looking for
components/schemas/TopicObjectSlim, because the path iscomponents/schemas/TopicObject.yaml#/TopicObjectSlim -
julian full error included, I am trying to fix it but no luck so far, I already tried two code gen tools, none worked, have you got it working with any tools maybe?
[main] INFO o.o.c.l.PythonFastAPIServerCodegen - Skipping sorting of path operations, order matters, let the developer decide via their specification file. [main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving: java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:203) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:95) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchema(ExternalRefProcessor.java:1047) at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:238) at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:283) at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:264) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchemaObject(ExternalRefProcessor.java:1009) at io.swagger.v3.parser.processors.ExternalRefProcessor.processPathItem(ExternalRefProcessor.java:350) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem(ExternalRefProcessor.java:325) at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath(PathsProcessor.java:346) at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:68) at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:72) at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:59) at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:240) at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:183) at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97) at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16) at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:687) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:745) at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527) at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66) [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./components/schemas/UserObject.yaml#/UserObjectSlim [main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./components/schemas/UserObject.yaml#/UserObjectSlim [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. 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: -Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:718) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:745) at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527) at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66) ELIFECYCLE Command failed with exit code 1.You may ignore the error
java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml, I think I pasted the wrong thing -
julian full error included, I am trying to fix it but no luck so far, I already tried two code gen tools, none worked, have you got it working with any tools maybe?
[main] INFO o.o.c.l.PythonFastAPIServerCodegen - Skipping sorting of path operations, order matters, let the developer decide via their specification file. [main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving: java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:203) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:95) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchema(ExternalRefProcessor.java:1047) at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:238) at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:283) at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:264) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchemaObject(ExternalRefProcessor.java:1009) at io.swagger.v3.parser.processors.ExternalRefProcessor.processPathItem(ExternalRefProcessor.java:350) at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem(ExternalRefProcessor.java:325) at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath(PathsProcessor.java:346) at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:68) at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:72) at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:59) at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:240) at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:183) at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97) at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16) at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:687) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:745) at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527) at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66) [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./components/schemas/UserObject.yaml#/UserObjectSlim [main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: ./components/schemas/UserObject.yaml#/UserObjectSlim [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. [main] ERROR o.o.codegen.utils.ModelUtils - Undefined array inner type for `null`. Default to String. 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: -Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:718) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:745) at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527) at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66) ELIFECYCLE Command failed with exit code 1.You may ignore the error
java.lang.RuntimeException: Could not find components/schemas/TopicObjectSlim in contents of ./read/topic/topic_id.yaml, I think I pasted the wrong thingI asked ChatGPT for thoughts (because I literally have no idea what to say), and it theorized that openapi-generator-cli was pointed to the file
topic_id.yamldirectly.That would indeed cause issues because the file
topic_id.yamlisn't meant to be loaded in isolation.You need to point your tool at either
read.yamlorwrite.yaml, which are the OpenAPI schema entry points for the two APIs NodeBB exposes. -
I am pointing to the input correcty. My LLM wanted me to extract TopicObjectSlim into its own file, it didn't help, I tried to inline TopicObjectSlim and that worked, but there was another error of the same kind just with a different object.
I was able to fix it, it seems at least, I'll need to test it. Adding a flag to skip validation allowed it to compete sucessfully:
openapi-generator-cli generate -i src/specs/read.yaml -g typescript-fetch -o src/sdks/read --skip-validate-spec -
I am pointing to the input correcty. My LLM wanted me to extract TopicObjectSlim into its own file, it didn't help, I tried to inline TopicObjectSlim and that worked, but there was another error of the same kind just with a different object.
I was able to fix it, it seems at least, I'll need to test it. Adding a flag to skip validation allowed it to compete sucessfully:
openapi-generator-cli generate -i src/specs/read.yaml -g typescript-fetch -o src/sdks/read --skip-validate-specKonrad-Moskal okay, best of luck getting the schema to load :)
-
julian I was able to make a request to write api: POST to create a user, using a master token :grin:
There are w few issues though, when using a token
_uid, must be specified, shame it's not in the OA spec. Error handling is also tricky, since OA spec does not have all responses types, like 400 (https://docs.nodebb.org/api/write/#tag/users/paths/~1users~1/post).I made good progress though so I am happy, it's a side project :) Thank you for your help. Will you guys look into improving these types or are open for contributions?
EDIT: actually _uid is not an issue, I created myself a token for admin user and it does what I want without needing to pass _uid
-
julian I was able to make a request to write api: POST to create a user, using a master token :grin:
There are w few issues though, when using a token
_uid, must be specified, shame it's not in the OA spec. Error handling is also tricky, since OA spec does not have all responses types, like 400 (https://docs.nodebb.org/api/write/#tag/users/paths/~1users~1/post).I made good progress though so I am happy, it's a side project :) Thank you for your help. Will you guys look into improving these types or are open for contributions?
EDIT: actually _uid is not an issue, I created myself a token for admin user and it does what I want without needing to pass _uid
Konrad-Moskal yes, we're open to those updates to the OpenAPI spec.
If you use LLMs to write your commits we kindly ask you utilise the
Assisted-Byline in your commit messages.