Skip to content
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

Invalid response for optional recursive allOf #2652

Open
dtmeadows opened this issue Jan 15, 2025 · 1 comment
Open

Invalid response for optional recursive allOf #2652

dtmeadows opened this issue Jan 15, 2025 · 1 comment

Comments

@dtmeadows
Copy link

openapi: 3.0.2
paths:
  /pet:
    get:
      responses:
        200:
          description: ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Person'
components:
  schemas:
    Person:
      type: object
      properties:
        name:
          type: string
        parent:
          type: object
          description: The person's parent
          allOf:
            - $ref: '#/components/schemas/Person'
      required:
        - name

Context

Right now we're unable to use mocking for certain endpoints that use this pattern and thus have to disable testing for this.

Current Behavior

Right now prisma will throw a validation error on its own when you make a request to /pet:

[5:14:38 PM] › [VALIDATOR] ✖ error Violation: response.body.parent.parent Response body property parent.parent must have required property 'name'

This is because it's returning the following object:

{ "name": "string", "parent": { "name": "string", "parent": {} } }

Expected Behavior

The problem, to my eyes, is that {} is the incorrect response type here. Since the property is optional, prisma should instead just omit the property in its return.

Possible Workaround/Solution

I'm not aware of any workarounds. I don't believe using the OpenAPI 3.1 flavor of sibling refs would work either: https://redocly.com/learn/openapi/all-of#siblings-to-ref-s

Steps to Reproduce

Easily reproduced using the example request and curl http://127.0.0.1:4010/pet

Environment

@dtmeadows
Copy link
Author

If you try the newer approach to sibling refs, you still get an unexpected response:

        parent:
          type: object
          description: The person's parent
          $ref: '#/components/schemas/Person'
{"name":"string","parent":{"$ref":null}}

It's only when you use the ref directly that it works:

        parent: '#/components/schemas/Person'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant