We possess an OpenAPI schema that looks like this:
{
"openapi": "3.0.1",
"paths": {
"/v1/tool/breadcrumbs/{hierarchyId}/{categoryId}": {
"get": {
"tags": [
"V1-tool"
],
"summary": "Get Breadcrumbs details",
"operationId": "getBreadcrumbs",
"parameters": [
{
"name": "hierarchyId",
"in": "path",
"required": true,
"schema": {
"minimum": 1,
"type": "integer",
"format": "int32"
}
},
{
"name": "categoryId",
"in": "path",
"required": true,
"schema": {
"minimum": 1,
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "default response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Kitten"
}
}
}
}
}
},
"security": [
{
"Auth": []
}
]
}
},
...
We execute the following command to produce Flow types from the above schema file:
npx swagger-to-flowtype path/to/schema/file -d generated_types.js
The outcome of this process is seen below:
// @flow strict
export type Kitten = { type: "Kitten", id: number, name: string, uri: string };
export type HierarchyResponse = { type: "Hierarchy", id: number, name: string };
...
One issue arises with the Item
type, which is currently defined as:
export type Item = { type: string };
Instead, we desire it to be defined like so:
export type Item = ChildCategoryResponse | AliasCategoryResponse | SubheaderResponse;
Upon examining our OpenAPI schema, we found the relevant section:
"Item": {
// properties and oneOf definitions
},
Even though we expected a different output for the Item
type during generation using swagger-to-flowtype
, similar issues were observed when generating TypeScript types.
A concrete example showcasing items array is given below:
const items: Array<Item> = [
{
type: "Alias",
level: "3",
name: "name",
id: 42,
uri: "uri"
},
...
]
It's evident why the current definition
export type Item = { type: string };
is incorrect and should instead reflect export type Item = ChildCategoryResponse | AliasCategoryResponse | SubheaderResponse
.
Question:
Is there a way to adjust the schema to generate the desired
export type Item = ChildCategoryResponse | AliasCategoryResponse | SubheaderResponse
representation?