optic icon indicating copy to clipboard operation
optic copied to clipboard

warning: invalid allOf variant warning if allOf includes oneOf

Open corneliu-petrescu opened this issue 1 year ago • 6 comments

Hi,

We're seeing a parse warning when trying to lint the following API spec:

Example: -- invalid allOf variant

---
openapi: 3.0.3
info:
title: Test
version: 3.0.0
servers:
- url: /test
  description: Test
tags:
- name: Test
  description: test
paths:
/test:
  post:
    description: test
    operationId: test
    tags:
      - Test
    requestBody:
      content:
        application/vnd.api+json:
          schema:
            allOf:
              - type: object
                properties:
                  prop1:
                     type: string
                required: [prop1]
              - oneOf:
                  - type: object
                    properties:
                      prop2:
                        type: string
                  - type: object
                    properties:
                      prop3:
                        type: string
    responses:
      '201':
        description: success
        content:
          application/vnd.api+json:
            schema:
              type: object
          location:
            schema:
              type: string

corneliu-petrescu avatar Apr 10 '24 09:04 corneliu-petrescu

Ah interesting, it looks like our mergeAllOf handler doesn't handle this case.

This might be a little trickier to implement, given each oneOf child would result in a top level polymorphic item, and you could have multiple oneOf children which would result in all combinations of polymorphic options.

niclim avatar Apr 11 '24 19:04 niclim

We have 2 or 3 APIs that use the above approach. What would be the impact of it at this moment? Is it just a warning?

corneliu-petrescu avatar Apr 12 '24 04:04 corneliu-petrescu

I think right now it'll exclude values in oneOf blocks that are nested inside of an allOf block. This would affect the diff that's generated and rules run against it.

niclim avatar Apr 16 '24 13:04 niclim

For now I'm investigating rewriting some of the schemas using

oneOf
 - allOf
     prop1
     prop2
 - allOf
     prop1
     prop3
     ```
 This does not give any warnings
     

corneliu-petrescu avatar Apr 16 '24 13:04 corneliu-petrescu

I think I just came across the same ...

optic diff reference\Configuration.yaml --last-change 
  1. invalid allOf variant at reference\Configuration.yaml:103:3535 this is a model with a allOf of two models, where the second model has a oneOf (many)
  2. Operations: No operations changed where I have remove the required attribute of a property in a Model listed in the oneOf

checkin247 avatar May 23 '24 12:05 checkin247

Hit this issue today when using the Train Travel OADs. https://github.com/bump-sh-examples/train-travel-api

These are a good baseline for testing support. I downgraded them to OAS 3.0 for testing diff tooling.

I get the same error https://github.com/bump-sh-examples/train-travel-api/blob/87d810c1371409178380032cf48ab0eb26fa9b78/openapi.yaml#L124-L135

Relequestual avatar Feb 07 '25 10:02 Relequestual