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

Schema processing fails when "allOf" references to nullable object #1066

Open
sebastianheinig opened this issue Jun 28, 2024 · 1 comment
Open

Comments

@sebastianheinig
Copy link

Describe the bug
When using a schema that contains an "allOf" reference to a nullable object, the generation fails with the message "Cannot take allOf a non-object".

OpenAPI Spec File
Document to recreate:

openapi: 3.0.1
info:
  title: Title
  description: Description
  version: 1.0.0
servers:
  - url: /api
paths:
  /item:
    get:
      operationId: item
      responses:
        "200":
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Item'
components:
  schemas:
    RelatedItemSuper:
      type: object
      nullable: true
      properties:
        propertyA:
          type: string
    RelatedItem:
      type: object
      allOf:
        - $ref: '#/components/schemas/RelatedItemSuper'
        - type: object
          properties:
            propertyB:
              type: string
    Item:
      type: object
      nullable: false
      properties:
        key:
          type: string
        relatedItem:
          $ref: '#/components/schemas/RelatedItem'

A real world example can be found here.

Desktop (please complete the following information):

  • OS: Linux
  • Python Version: 3.11.2
  • openapi-python-client version: 0.21.1

Additional context
Changing "nullable" to "false" on "RelatedItem" in the above example works but does not seem to be a suitable solution as the construct used is legitimate, or is it not?

@eli-bl
Copy link
Collaborator

eli-bl commented Sep 16, 2024

I think I see how this is happening. There are two related issues here:

  1. The current allOf logic only works for object schemas, not for unions of "could be an object, could be something else" (in this case the something else is null). That's just a limitation of how it's implemented. I can sort of imagine a fix but not a very straightforward one.
  2. This spec is in kind of a gray area where it's technically valid but doesn't exactly match what you intended. I think that if you do an allOf with two schemas but only one of them is nullable, a strict OpenAPI validator would say that the result is not nullable. That is, a null value would not be a valid RelatedItem, because it would satisfy RelatedItemSuper but would not satisfy the non-nullable inline schema with propertyB. The fix for that would just be to make the inline schema nullable too; unfortunately it still wouldn't work with the current generator, due to the implementation issue I mentioned.

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

2 participants