mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2026-01-25 16:02:59 +00:00
Merge pull request #916 from sjoerdmulder/feature/discriminator-cleanup
Small cleanup
This commit is contained in:
commit
708677684d
@ -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