libopenapi icon indicating copy to clipboard operation
libopenapi copied to clipboard

OneOfs with Discriminator Mappings in External Files Will Break With Inline Bundling

Open califlower opened this issue 1 month ago • 3 comments

OneOf that with discriminators in external files break with inline bundling. Small Example

Parent File

  /shopping:
    get:
      responses:
        '200':
          description: Catalog page response
          content:
            application/json:
              schema:
                $ref: 'internal_schemas.yaml#/components/schemas/ResponseCatalogSection'

Child Files

    ResponseCatalogSection:
      oneOf:
        - $ref: '#/components/schemas/ResponseCatalogTileGroupSection'
        - $ref: '#/components/schemas/ResponseCatalogTableSection'
      discriminator:
        propertyName: type
        mapping:
          "TILE_GROUP_SECTION": '#/components/schemas/ResponseCatalogTileGroupSection'
          "TABLE_GROUP_SECTION": '#/components/schemas/ResponseCatalogTableSection'

Once the inline bundler runs, the bundler will move

    ResponseCatalogSection:
      oneOf:
        - $ref: '#/components/schemas/ResponseCatalogTileGroupSection'
        - $ref: '#/components/schemas/ResponseCatalogTableSection'
      discriminator:
        propertyName: type
        mapping:
          "TILE_GROUP_SECTION": '#/components/schemas/ResponseCatalogTileGroupSection'
          "TABLE_GROUP_SECTION": '#/components/schemas/ResponseCatalogTableSection'

to the main file, but the references will not come along with it nor will it inline. Not inlining is the CORRECT behavior, since I belive that's something I fixed in the past. But my fixed missed this case.

In this case, we either need to copy the references to the main file, or skip inlining this type of case at all. Since skipping has some prior precedence (when it comes to recursive refs), that's probably the solution to inline bundling.

califlower avatar Nov 03 '25 23:11 califlower

I think I might have a fix somewhere for this (since I wrote the code). These stupid discriminators are gonna be the death of me

califlower avatar Nov 04 '25 17:11 califlower

You can join me, sitting somewhere near the bottom (I think) of this endless pit we call OpenAPI. No matter what, it keeps getting deeper. You can't solve it. It's a puzzle that looks like it's solved, and then someone finds a way to use oneOf or anyOf in a new and terrifying way.

daveshanley avatar Nov 04 '25 17:11 daveshanley

I'm over it. It's cursed. If only you could see the work I've done trying to get discriminators and oneOfs to work in a Java client recently

califlower avatar Nov 07 '25 19:11 califlower