Openapi-generator: [BUG][JAVA] Bug generating spring server: codegenModel is null. Default to UNKNOWN_BASE_TYPE

Created on 25 Feb 2019  路  15Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] 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

requestBody: 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
Related issues/PRs
Suggest a fix
Bug Spring

All 15 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

I believe that this is all related to the discussion in: https://github.com/OpenAPITools/openapi-generator/issues/15
@jmini , can you confirm?

Hi,
I'm facing this issue as well. Still, I'd like to know whether it exists a workaround or not for it, even though it is by manually setting any configuration parameter on the pom.xml which generates the API.
Thanks in advance.

Facing the same issue. Can confirm that the issues does occur once you use oneOf like so:

  /demonstrations:
    post:
      summary: Create Demonstration
      tags: 
        - Demonstrations
      operationId: createDemonstration
      requestBody:
        description: Demonstration details.
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/demonstrationPayload2'
                - $ref: '#/components/schemas/demonstrationPayload1'
      responses:
        '201':
          description:  created

When we comment oneOf and only mention one entry of $ref, then it works.

As a workaround, what about defining the schema separately (instead of inline)? e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/allOf.yaml#L43-L52

@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 oneOf declaration. What I'd like to have instead is a Java class that is a super-type of the two mentioned schemas.

I remember the oneOf implementation in Java is still being discussed/worked on.

What I'd like to have instead is a Java class that is a super-type of the two mentioned schemas.

If it's a super-type, what about using allOf instead?

Same issue here and I don't wat to use the allOf instead.

Hey everyone. Was there ever a solution found for this? Facing the same issue with oneOf currently.

Facing the same issue with oneOf. Any solution for this issue?

I still have this issue with Spring generator. Anything new?

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.

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..

Does "openapi-generator validate -i filename.yml" give you any tips?

Have you tried using Version 3.0?

Was this page helpful?
0 / 5 - 0 ratings