Openapi-generator: [BUG] [csharp-netcore] UNKNOWN BASE TYPE when using allOf in request body schema declaration

Created on 3 Sep 2020  路  1Comment  路  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] Have you tested with the latest master to confirm the issuue still exists?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using an inline request body declaration containing "oneOf", the csharp-netcore code generator generates an UNKNOWN_BASE_TYPE as a parameter of that request method, e.g.

/// <summary>
/// 
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="UNKNOWN_BASE_TYPE">Problematic inline request body</param>
/// <returns>string</returns>
string ExamplePost(UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE);

This code does not compile. However, wrapping the request body declaration into a separate scheme and referencing it in the request body works. See the two linked gists for a working and failing example.

The output of the code generator includes the following warnings that seem related to the issue:

[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/?'
[main] WARN  o.o.codegen.DefaultCodegen - schema: class ComposedSchema {
    class Schema {
        type: null
        format: null
        $ref: null
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }
    allOf: null
    anyOf: null
    oneOf: [class Schema {
        type: null
        format: null
        $ref: #/components/schemas/ExtendedRequest1
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }, class Schema {
        type: null
        format: null
        $ref: #/components/schemas/ExtendedRequest2
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }]
}
[main] WARN  o.o.codegen.DefaultCodegen - codegenModel is null. Default to UNKNOWN_BASE_TYPE
openapi-generator version
  • openapi-generator-cli-5.0.0-beta.jar
  • openapi-generator-cli-5.0.0-20200903.070200-608.jar
OpenAPI declaration file content or url

The failing declaration can be found here: https://gist.github.com/mhanysz/9d08024b8c363db7e9530ea5114c219a
Introducing a wrapper scheme for the request body like shown here, fixes the issue: https://gist.github.com/mhanysz/a80ef762d37571b5fe8b03e45b09705c

Generation Details

Generator is called with java -jar .\openapi-generator-cli-5.0.0-20200903.070200-608.jar generate -i .\failing_declaration.json -g csharp-netcore -o .\FailingExampleClient\ -c .\generator-config.json --global-property modelDocs=false,modelTests=false,apiDocs=false,apiTests=false

The generator config looks like this:

{
  "optionalAssemblyInfo": false,
  "netCoreProjectFile": true,
  "targetFramework": "netstandard2.0",
  "validatable": false,
  "sortParamsByRequiredFlag": true,
  "optionalMethodArgument": false
}
Steps to reproduce

Generate the code for failing_declaration.json with the settings mentioned above.

Related issues/PRs

#2892 seems to be the same issue, only for Java

Suggest a fix
Bug

Most helpful comment

All happens for the various typescript generators. Can't use anyOf, oneOf, allOf with a collection of $ref in requestBody.

>All comments

All happens for the various typescript generators. Can't use anyOf, oneOf, allOf with a collection of $ref in requestBody.

Was this page helpful?
0 / 5 - 0 ratings