Bug Report Checklist
Description
The typescript-fetch generator generates code for models that drops values that should not be dropped when using oneOf with type: object, {type: array, items: {nullable: true}} or {type: array, items: {type: object}}. Take a look at the following OpenAPI declaration:
openapi: "3.0.2"
info:
title: Foo
version: 1.0.0
paths:
/foo:
post:
requestBody:
content:
application/json:
schema:
oneOf:
- type: object
- type: array
items:
nullable: true
responses:
204:
description: "Ok"
/bar:
post:
requestBody:
content:
application/json:
schema:
oneOf:
- type: object
- type: array
items:
type: object
responses:
204:
description: "Ok"
It generates
// models.FooPostRequest.ts
/* tslint:disable */
/* eslint-disable */
/**
* Foo
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* @type FooPostRequest
*
* @export
*/
export type FooPostRequest = Array<any | null> | object;
export function FooPostRequestFromJSON(json: any): FooPostRequest {
return FooPostRequestFromJSONTyped(json, false);
}
export function FooPostRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): FooPostRequest {
if (json == null) {
return json;
}
return {} as any;
}
export function FooPostRequestToJSON(json: any): any {
return FooPostRequestToJSONTyped(json, false);
}
export function FooPostRequestToJSONTyped(value?: FooPostRequest | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}
return {};
}
// BarPostRequest.ts
/* tslint:disable */
/* eslint-disable */
/**
* Foo
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* @type BarPostRequest
*
* @export
*/
export type BarPostRequest = Array<object> | object;
export function BarPostRequestFromJSON(json: any): BarPostRequest {
return BarPostRequestFromJSONTyped(json, false);
}
export function BarPostRequestFromJSONTyped(json: any, ignoreDiscriminator: boolean): BarPostRequest {
if (json == null) {
return json;
}
return {} as any;
}
export function BarPostRequestToJSON(json: any): any {
return BarPostRequestToJSONTyped(json, false);
}
export function BarPostRequestToJSONTyped(value?: BarPostRequest | null, ignoreDiscriminator: boolean = false): any {
if (value == null) {
return value;
}
return {};
}
The RequestFromJSONTyped and RequestToJSONTyped functions do not return the desired array or object values and instead replace them with an empty object.
openapi-generator version
7.15
Generation Details
typescript-fetch generator with default settings.
Steps to reproduce
Take the OpenAPI definition from above and run the OpenAPI generator with the typescript-fetch generator.
Related issues/PRs
Suggest a fix
I believe the modelOneOf.mustache template is missing some cases. I will try to open a pull request.
Bug Report Checklist
Description
The
typescript-fetchgenerator generates code for models that drops values that should not be dropped when usingoneOfwithtype: object,{type: array, items: {nullable: true}}or{type: array, items: {type: object}}. Take a look at the following OpenAPI declaration:It generates
The
RequestFromJSONTypedandRequestToJSONTypedfunctions do not return the desired array or object values and instead replace them with an empty object.openapi-generator version
7.15
Generation Details
typescript-fetch generator with default settings.
Steps to reproduce
Take the OpenAPI definition from above and run the OpenAPI generator with the typescript-fetch generator.
Related issues/PRs
Suggest a fix
I believe the
modelOneOf.mustachetemplate is missing some cases. I will try to open a pull request.