openapi-generator: [BUG][JAVA] Bug generating spring server: codegenModel is null. Default to UNKNOWN_BASE_TYPE
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What’s the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I am trying to generate a java spring server using 4.0.0-beta2, however generation fails with:
[main] WARN o.o.codegen.DefaultCodegen - codegenModel is null. Default to UNKNOWN_BASE_TYPE
[main] WARN o.o.codegen.DefaultCodegen - The following schema has undefined (null) baseType. It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. A correct 'consumes' for form parameters should be 'application/x-www-form-urlencoded' or 'multipart/form-data'
[main] WARN o.o.codegen.DefaultCodegen - schema: class ComposedSchema {
class Schema {
title: null
multipleOf: null
The .java with the generated APIs has the following:
import org.openapitools.model.UNKNOWN_BASE_TYPE;
The default ResponseEntity has:
ApiParam(value = "Click on the **Model** below to view the available parameters for this endpoint." ,required=true ) @Valid @RequestBody UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE) {
openapi-generator version
4.0.0-beta2 and previous versions.
OpenAPI declaration file content or url
description: >-
Click on the **Model** below to view the available parameters for this
endpoint.
required: true
content:
application/json:
schema:
allOf:
- type: object
properties:
key:
type: string
example: S1111...111111
alg:
type: string
example: abc
params:
type: object
oneOf:
- $ref: '#/components/schemas/abc_params'
- $ref: '#/components/schemas/abb_params'
- $ref: '#/components/schemas/aaa_params'
example:
num: '5521204534320004'
expiryDate: 0519
sCode: '123'
discriminator:
propertyName: alg
mapping:
abc: '#/components/schemas/abc_params'
abb: '#/components/schemas/abb_params'
aaa: '#/components/schemas/aaa_params'```
##### Command line used for generation
java -jar openapi-generator-cli.jar generate -i myAPI.yaml -g spring -o spring_server -c config.json
##### Steps to reproduce
<!-- unambiguous set of steps to reproduce the bug.-->
##### Related issues/PRs
<!-- has a similar issue/PR been reported/opened before? Please do a search in https://github.com/openapitools/openapi-generator/issues?utf8=%E2%9C%93&q=is%3Aissue%20 -->
##### Suggest a fix
<!-- if you can't fix the bug yourself, perhaps you can point to what might be
causing the problem (line of code or commit), or simply make a suggestion -->
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 22 (3 by maintainers)
I remember the oneOf implementation in Java is still being discussed/worked on.
If it’s a super-type, what about using
allOfinstead?@wing328 Hi, same as @frochi42 I’m getting UNKNOWN_BASE_TYPE with version 5.1.1 with openapi-generator-cli for angular-typescript. Using https://editor.swagger.io/ I’m getting the correct client code.
Below is example yaml code: `openapi: 3.0.1 info: title: ‘Test Client’ version: ‘v1’ description: | This component store resources and authorizations to MongoDB
paths: /api/v1/resources/apply-configuration: post: operationId: apply-resource tags: - ‘resources’ summary: apply resource parameters: - in: header name: X-Security schema: $ref: ‘#/components/schemas/header.x-security’ required: true requestBody: content: application/json: schema: required: [configuration] properties: configuration: required: [name, type] properties: name: $ref: ‘#/components/schemas/value.string’ type: allOf: - $ref: ‘#/components/schemas/value.string’ - enum: [security.template/account.v1, security.template/company.v1] example: security.template/account.v1 description: | Field | Description -|-
name| string - the unique name of the configurationtype| string - the configuration type description: | Field | Description -|-configuration| object - contain configuration propeties responses: 202: $ref: ‘#/components/responses/200-empty’ 4XX: $ref: ‘#/components/responses/4XX’ 5XX: $ref: ‘#/components/responses/5XX’ 503: $ref: ‘#/components/responses/503’components: responses: 200-empty: description: ‘Empty success answer’ 4XX: content: application/json: schema: type: object properties: code: type: string example: ‘VAIDATION_ERROR’ correlation: type: string example: ‘146a99c0b0aced9a’ errors: type: array items: type: object properties: field: type: string example: ‘field1’ message: type: string example: ‘can not be null’ description: ‘Client error’ 5XX: content: application/json: schema: $ref: ‘#/components/schemas/value.error’ description: ‘Server error’ 503: content: application/json: schema: $ref: ‘#/components/schemas/value.error’ description: ‘Service unavailable’
schemas: value.string: type: string example: ‘any’ description: String value value.error: properties: error: properties: code: type: string example: ‘ERROR’ correlation: type: string example: ‘any’ description: Error header.x-security: type: string example: ‘%7B%20%22user%22%3A%20%7B%20%22name%22%3A%20%22cf678c35-806a-47da-b92d-0144e23eb3be%22%2C%20%22alias%22%3A%20%22Lorenzo%20Dodi%22%20%7D%20%7D’ description: ‘JSON URL encoded which contain user informatinos as “name” and “alias”’
`
did anyone ever get to the bottom if it? I still see that even latest maven plugin 5.0.0-beta2 fails to generate inheritance code, whereas online generator processes exactly the same yaml correctly. Tried all workarounds found, no luck…
Facing the same issue with oneOf. Any solution for this issue?
fyi. this also happens for python-fastapi server generation
Hi, any progress or workaround here? We are stuck at the same problem, even with version 5.1.1 of theopenapi-generator-maven-plugin. Thanks a lot!
Generating code that implements oneOf and allOf requires the use of inheritance in the model. From what I see, the generated code does not use inheritance. However, if I use SwaggerHub site to generate code, inheritance is used to implement oneOf and allOf.
I still have this issue with Spring generator. Anything new?
@wing328: I tried that, then it parses the yaml correctly and the source code compiles. However, when you look at the generated code, it does not do what the semantics would imply.
In my experiments, the code generator generates a Java class that looks exactly (of course, except its name) like the Java class that corresponds to the schema mentioned at last under the
oneOfdeclaration. What I’d like to have instead is a Java class that is a super-type of the two mentioned schemas.