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
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
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
}
Generate the code for failing_declaration.json with the settings mentioned above.
#2892 seems to be the same issue, only for Java
All happens for the various typescript generators. Can't use anyOf, oneOf, allOf with a collection of $ref in requestBody.
Most helpful comment
All happens for the various typescript generators. Can't use anyOf, oneOf, allOf with a collection of $ref in requestBody.