Skip to content

Using allOf: to define composite schemas #1467

@stevendearborn

Description

@stevendearborn

I would like to understand the extent of using the allOf: construct in OpenAPI; it may be different than what it is defined in JSON schema.

I would like to define a composite schema by re-using two or more independent schema definitions. It seems that once I add more than one definition to the allOf: array, then 1) the resulting object is not rendered in either Swagger Editor or Swagger UI the way I expect it to be, and 2) there are cascading syntax errors in the editor when defining additional OpenAPI objects.

I think the answer is this [for OpenAPI]:

  1. the allOf: construct is limited to take only one schema reference; the "polymorphism examples" supply its best use.
  2. the allOf: construct should not be used to define the schema of a response: use the oneOf: construct to select one schema from several alternatives.

It is #2 that is what I would like to do: to avoid defining intermediate schemas and just "compose" a response given re-useable schema definitions.

Here is an example:
openapi-13.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions