redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Decorator or feature flag to bundle merge "allOf" schemas

Open adamaltman opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Let's say I have these schemas:

schemas:
  Car:
    allOf: 
      - $ref: #/components/schemas/Make
      - $ref: #/components/schemas/Model
      - type: object
        properties:
          manufacturedAt:
             type: string
             format: date
          color:
             type: string
  Make:
    type: object
    properties:
       make:
           type: string
           enum: 
              - Batmobile
              - DeLorean
  Model:
    type: object
    properties:
       model:
           type: string

And now, I have an application (not Redocly), that needs to consume this schema and operate on it. The application struggles with the allOf. I wish to have a resulting merged schema like the following to make it easier for third party programs to use:

Car:
  type: object
  properties:
     make: ...
     model: ...
     manufacturedAt: ...
     color: ...

Describe the solution you'd like

  1. A flag on the bundle command like --merge-all-of.
  2. A decorator that can be included in a redocly.yaml file like merge-all-of.

Describe alternatives you've considered

Requesting third party libs have better allOf support. 🤣

Additional context

None

adamaltman avatar Aug 17 '23 18:08 adamaltman

this is related to bundling or flattening and is a hot topic in the JSON Schema community. It was undefined behavior for quite a few years and only recently have they officially documented the bundling process for 2020-12.

I believe there are some major behavior differences depending on the draft used in the schema. for example, use of additionalProperties has long been a hang up with earlier drafts and allOf schemas

here's a fairly popular package: https://github.com/mokkabonna/json-schema-merge-allof

@relequestual @jdesrosiers @MikeRalphson

jeremyfiel avatar Aug 21 '23 16:08 jeremyfiel