redux-toolkit
redux-toolkit copied to clipboard
Rtk-query/codegen-openapi generating incorrect types with "oneOf" operator in json schema.
Expected result:
type PostApiClientAuthLoginApiArg = ({ phone: string } | { email: string }) & { password: string }
Body types in generated file are looks like:

export type PostApiClientAuthLoginApiArg = {
body:
| {
phone: string;
}
| {
email: string;
};
};
runing by npm script command: npx @rtk-query/codegen-openapi openapi-config.json
openapi-config.json
{
"apiFile": "./src/store/baseApi.ts",
"apiImport": "baseApi",
"exportName": "coreApi",
"hooks": true,
"outputFile": "./src/store/coreApi.ts",
"schemaFile": "./common-scheme.json"
}
schema.json
{
"info": {
"title": "title",
"version": "0.1"
},
"openapi": "3.0.0",
"paths": {
"/api/client/auth/login": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"properties": {
"phone": {
"type": "string"
}
},
"required": [
"phone"
]
},
{
"properties": {
"email": {
"type": "string",
"format": "email"
}
},
"required": [
"email"
]
}
],
"properties": {
"password": {
"format": "password",
"maxLength": 50,
"minLength": 5,
"type": "string"
}
},
"required": [
"password"
],
"type": "object"
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
}
},
"description": "stub"
}
}
}
}
}
}