[BUG] typescript generator throws when `additionalProperties` is set to `true`
Created by: arnemolland
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
When using the typescript generator, anywhere additionalProperties is explicitly set to true, the generator throws. It should be expected with array types, but this happens on object types. This is not the case with the typescript-axios or typescript-fetch generators. It does not throw when additionalProperties is set to false or if it's omitted (in which case I've interpreted the spec as to it's true by default).
openapi-generator version
6.0.1
OpenAPI declaration file content or url
Repro JSON schema
{
"openapi": "3.0.3",
"components": {
"schemas": {
"foo": {
"properties": {
"bar": {
"additionalProperties": true,
"description": "baz",
"type": "object"
}
},
"type": "object"
}
}
},
"info": {
"title": "Repro",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"description": "Foo",
"operationId": "getFoo",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"foo": {
"description": "Foo.",
"type": "string"
}
},
"required": [
"foo"
],
"type": "object"
}
}
},
"description": "Foo"
}
},
"summary": "Foo",
"tags": [
"metadata"
]
}
}
}
}
Generation Details
openapi-generator-cli generate -i spec.json -g typescript -o /dev/null
Steps to reproduce
Use the typescript generator to generate code from any schema where any components.schemas.properties object has additionalProperties set to true.
Logs
Exception in thread "main" java.lang.RuntimeException: Could not process model 'errorAuthenticatorAssuranceLevelNotSatisfied'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:509)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:911)
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.ClassCastException: class java.lang.Boolean cannot be cast to class io.swagger.v3.oas.models.media.Schema (java.lang.Boolean is in module java.base of loader 'bootstrap'; io.swagger.v3.oas.models.media.Schema is in unnamed module of loader 'app')
at org.openapitools.codegen.languages.TypeScriptClientCodegen.getTypeDeclaration(TypeScriptClientCodegen.java:890)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:3650)
at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:5402)
at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:5344)
at org.openapitools.codegen.DefaultCodegen.updateModelForObject(DefaultCodegen.java:2672)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:2873)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1288)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:504)
... 4 more