Skip to content

feat: add PoC of handling discriminator for allOf case in OpenAPI 3.1 #4959

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

Merged
merged 3 commits into from
Jul 4, 2025

Conversation

glowcloud
Copy link
Contributor

@glowcloud glowcloud commented Jun 18, 2025

Notes on the idea of handling allOf discriminator:

Dereference: dereferenced value of SchemaElement should be stored within allOfDiscriminatorMapping if

  1. SchemaElement is an item of AllOfElement
  2. SchemaElement has a schemaName metadata
  3. parent SchemaElement has a schemaName metadata
# schemas
components:
  schemas:
    Pet:
      properties:
        petType:
          type: string
     discriminator:
       propertyName: petType
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet' # => SchemaElement Cat should be mapped to Pet

# allOfDiscriminatorMapping
Pet: [ 
  # dereferenced SchemaElement Cat
  allOf:
    - properties:
         petType:
           type: string
       discriminator:
         propertyName: petType
 ]

Normalization: should be similar to oneOf/anyOf discriminator normalization but this time we will be creating the normalized mapping based on the items of allOfDiscriminatorMapping instead of items of oneOf/anyOf fields. External references and references not pointing to internal components/schemas/<schemaName> are also not being handled here.

@glowcloud glowcloud self-assigned this Jun 18, 2025
@glowcloud glowcloud added enhancement New feature or request OpenAPI 3.1 labels Jun 18, 2025
@glowcloud glowcloud force-pushed the feat/handling-discriminator-allOf branch from 0c77fa4 to f9d460b Compare June 23, 2025 13:37
@glowcloud glowcloud force-pushed the feat/handling-discriminator-allOf branch from f9d460b to de17035 Compare July 2, 2025 07:52
@glowcloud glowcloud marked this pull request as ready for review July 2, 2025 07:59
@@ -531,6 +532,11 @@ export const visit = (

// cycle detected; skipping over a sub-tree to avoid recursion
if (detectCycles && ancestors.includes(node)) {
if (typeof detectCyclesCallback === 'function') {
// @ts-ignore
detectCyclesCallback(node, key, parent, path, ancestors);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding types for visit options argument would fix that error

@robert-hebel-sb
Copy link

It seems there are many issues within typings. If resolving all TS errors exceeds the scope of the task, we can handle it in a separate ticket

Base automatically changed from feat/handling-discriminator-oneOf-anyOf to main July 4, 2025 06:52
@glowcloud glowcloud force-pushed the feat/handling-discriminator-allOf branch from 1d5517d to 4ad3864 Compare July 4, 2025 07:00
@glowcloud glowcloud force-pushed the feat/handling-discriminator-allOf branch from 4ad3864 to c1c8b7d Compare July 4, 2025 07:05
@glowcloud
Copy link
Contributor Author

It seems there are many issues within typings. If resolving all TS errors exceeds the scope of the task, we can handle it in a separate ticket

Let's handle it separately - we have many similar cases with the typings, we could try addressing them as well.

@glowcloud glowcloud merged commit 4eee665 into main Jul 4, 2025
8 checks passed
@glowcloud glowcloud deleted the feat/handling-discriminator-allOf branch July 4, 2025 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OpenAPI 3.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants