-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add PoC of handling discriminator for oneOf/anyOf cases in OpenAPI 3.1 #4952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
packages/apidom-ns-openapi-3-1/src/refractor/plugins/normalize-discriminator-mapping.ts
Outdated
Show resolved
Hide resolved
packages/apidom-ns-openapi-3-1/src/refractor/plugins/normalize-discriminator-mapping.ts
Outdated
Show resolved
Hide resolved
packages/apidom-ns-openapi-3-1/src/refractor/plugins/normalize-discriminator-mapping.ts
Show resolved
Hide resolved
packages/apidom-ns-openapi-3-1/src/refractor/plugins/normalize-discriminator-mapping.ts
Show resolved
Hide resolved
|
||
const schemaJSONPointer = ancestorLineageToJSONPointer([ | ||
...ancestors, | ||
parent!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't passing an undefined parent cause a type error?
const mapping = | ||
schemaElement.discriminator.get('mapping') ?? new DiscriminatorMappingElement(); | ||
const normalizedMapping: DiscriminatorMappingElement = cloneDeep(mapping); | ||
let normalizationResult = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let normalizationResult = true; | |
let hasNormalizationResult = true; |
]); | ||
|
||
// skip visiting this Schema Object if it's already normalized | ||
if (storage!.includes(schemaJSONPointer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should check before whether storage is not being empty?
const items = isArrayElement(schemaElement.oneOf) | ||
? schemaElement.oneOf | ||
: schemaElement.anyOf; | ||
|
||
items!.forEach((item) => { | ||
if (!isSchemaElement(item)) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const items = isArrayElement(schemaElement.oneOf) | |
? schemaElement.oneOf | |
: schemaElement.anyOf; | |
items!.forEach((item) => { | |
if (!isSchemaElement(item)) { | |
return; | |
} | |
const items = isArrayElement(schemaElement.oneOf) | |
? schemaElement.oneOf | |
: (schemaElement.anyOf as ArrayElement); | |
items.forEach((item) => { | |
if (!isSchemaElement(item)) { | |
return; | |
} |
Notes on the idea of handling discriminator:
Dereference: dereference value of
MemberElement
contained withinDiscriminator.mapping
and set the result as its metadata.Normalization: compare
oneOf/anyOf
items with the mapping values metadata and create normalized mapping based on the result:oneOf
andanyOf
are present, do not normalizecomponents/schema/<schemaName>
:baseURI
or by not havingschemaName
metadata.$refBaseURI
metadata.components/schema/<schemaName>
:schemaName
metadata.schemaName
and$refBaseURI
metadata.<schemaName>: <schema>
.x-normalized-mapping
)Additionally, we should have a new strategy option to check if we should dereference Discriminator.mapping values.