OpenAPITools / OpenAPITools/openapi-generator
[BUG][TYPESCRIPT][TYPESCRIPT-AXIOS] Free-form model generation fails, which causes subsequent model that depends on this model to fail .
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We are currently using tsoa to generate our swagger docs and currently using openapitools/openapi-generator-cli to generate typescript axios clients, but when attempting generate the clients using these valid swagger jsons it fails with below error.
[main] INFO o.o.codegen.DefaultGenerator - Model ASchema not generated since it's a free-form object
Exception in thread "main" java.lang.RuntimeException: Could not process model 'BSchemaDefReferToA'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:524)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:926)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:487)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getAdditionalProperties()" because "schema" is null
at org.openapitools.codegen.utils.ModelUtils.isMapSchema(ModelUtils.java:528)
at org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.getTypeDeclaration(AbstractTypeScriptClientCodegen.java:606)
at org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen.addAdditionPropertiesToCodeGenModel(TypeScriptAxiosClientCodegen.java:194)
at org.openapitools.codegen.DefaultCodegen.updateModelForObject(DefaultCodegen.java:2836)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:3050)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1305)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:519)
openapi-generator-cli version : "@openapitools/openapi-generator-cli": "^2.5.2"
sample.json that produces the bug.
https://gist.github.com/v1shva/2f36bf5ccaaf6086e0ca09e5a5b2d70e
Using below config for openapitools
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.5.0"
}
}
Steps to reproduce
- Attempting to generate axios client using this command fails
npx openapi-generator-cli generate -i sample.json -g typescript-axios -o src/api-clients/test --skip-validate-spec
Related issues/PRs
Same issue affecting rust: https://github.com/OpenAPITools/openapi-generator/issues/14514
Suggest a fix
If you manually remove
"properties": {},
"type": "object"
from ASchema then it works without an issue. but since this json is a valid schema even if those are included, it's what get generated from tsoa.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the sample.json linked in the issue and the stack trace through ModelUtils.java, AbstractTypeScriptClientCodegen.java, and TypeScriptAxiosClientCodegen.java. Reproduce with the stated npx openapi-generator-cli command, then trace how the free-form ASchema is handled before BSchemaDefReferToA is processed. Done means the valid sample generates the TypeScript Axios client and its dependent model without the null-pointer failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100