openapi-generators / openapi-python-client

Generate modern Python clients from OpenAPI
MIT License
1.19k stars 189 forks source link

Can't generate client for spec with refs in allOf #1060

Closed coandco closed 1 month ago

coandco commented 1 month ago

Describe the bug I'm attempting to use openapi-python-client to generate a client for the new XPipe API, but it's failing with "Cannot take allOf a non-object". I've boiled it down to the following minimal reproducer. I think what the original spec is trying to describe is an auth type that always has the key "type", and then either has one key or the other based on what type it is.

OpenAPI Spec File

openapi: 3.0.1
info:
  title: Example
  version: "1.0"
paths:
  /ping:
    get:
      responses:
        '200':
          description: OK
components:
  schemas:
    AuthMethod:
      type: object
      discriminator:
        propertyName: type
      properties:
        type:
          type: string
      required:
        - type
      oneOf:
        - $ref: '#/components/schemas/FirstType'
        - $ref: '#/components/schemas/SecondType'
    FirstType:
      type: object
      allOf:
        - $ref: '#/components/schemas/AuthMethod'
        - type: object
          properties:
            key_one:
              type: string
              description: KeyOne
          required:
            - key_one
    SecondType:
      type: object
      allOf:
        - $ref: '#/components/schemas/AuthMethod'
        - type: object
          properties:
            key_two:
              type: string
              description: KeyTwo
          required:
            - key_two

Desktop (please complete the following information):

Additional context I'm fairly new to openapi specs, so it's entirely possible I'm misreading the file or that the original spec is doing something hinky that I don't understand. What am I missing here?

dbanty commented 1 month ago

There are a few peculiar things about this document, none of which we’re likely to have an easy solution to:

  1. using both top-level schema and oneOf. I’d need to read some of the jsonschema spec to see if that’s even allowed, and if so how to resolve it.
  2. Reference cycles between all of the types. AuthMethod might be a FirstType which includes all of AuthMethod which might be a SecondType which…
  3. Using a discriminator and not defining the values to discriminate on. We don’t actually support discriminators yet, but if we did that’d be an error.

So no obvious way to support this schema in this project. Maybe take a look at the openapitools generator and see what they do with it?

Gonna close this since I don’t think it’s a bug.