prism icon indicating copy to clipboard operation
prism copied to clipboard

Invalid response for optional recursive allOf

Open dtmeadows opened this issue 11 months ago • 1 comments

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 avatar Jan 15 '25 22:01 dtmeadows

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'

dtmeadows avatar Jan 15 '25 22:01 dtmeadows