mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Simlified if statements
This commit is contained in:
parent
0eb5e91ce4
commit
cb4732d14f
@ -13,18 +13,16 @@ function inverseDictionary(map: Dictionary<string>): Dictionary<string> {
|
||||
}
|
||||
|
||||
export function findOneOfParentDiscriminator(openApi: OpenApi, parent?: Model): OpenApiDiscriminator | undefined {
|
||||
if (openApi.components) {
|
||||
if (openApi.components && parent) {
|
||||
for (const definitionName in openApi.components.schemas) {
|
||||
if (openApi.components.schemas.hasOwnProperty(definitionName)) {
|
||||
const schema = openApi.components.schemas[definitionName];
|
||||
if (parent && schema.oneOf?.length && schema.discriminator) {
|
||||
const isPartOf =
|
||||
schema.oneOf
|
||||
.map(definition => definition.$ref && stripNamespace(definition.$ref) === parent.name)
|
||||
.filter(Boolean).length > 0;
|
||||
if (isPartOf) {
|
||||
return schema.discriminator;
|
||||
}
|
||||
if (
|
||||
schema.discriminator &&
|
||||
schema.oneOf?.length &&
|
||||
schema.oneOf.some(definition => definition.$ref && stripNamespace(definition.$ref) == parent.name)
|
||||
) {
|
||||
return schema.discriminator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user