Skip to content

Commit 77cccbc

Browse files
committed
Simplify getOpenAPIComponents
1 parent da4ae61 commit 77cccbc

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/react-openapi/src/resolveOpenAPIOperation.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export async function resolveOpenAPIOperation(
5555
}
5656
}
5757

58-
const components = flattenComponents(schema);
58+
let components: OpenAPIOperationData['components'] = [];
59+
if (schema.components) {
60+
components = getOpenAPIComponents(schema);
61+
}
5962

6063
return {
6164
servers,
@@ -167,15 +170,10 @@ function flattenSecurities(security: OpenAPIV3.SecurityRequirementObject[]) {
167170
});
168171
}
169172

170-
function flattenComponents(
173+
function getOpenAPIComponents(
171174
schema: OpenAPIV3.Document | OpenAPIV3_1.Document
172175
): [string, OpenAPIV3.SchemaObject][] {
173-
const components = Object.keys(schema?.components?.schemas ?? {}).length
174-
? schema?.components?.schemas
175-
: {};
176-
177-
return Object.entries(components ?? {})
178-
.filter(([, schema]) => !shouldIgnoreEntity(schema))
179-
.sort((a, b) => a[0].localeCompare(b[0]))
180-
.map(([name, schema]) => [name, schema]);
176+
const schemas = schema.components?.schemas ?? {};
177+
178+
return Object.entries(schemas).filter(([, schema]) => !shouldIgnoreEntity(schema));
181179
}

0 commit comments

Comments
 (0)