Skip to content

how to combine $ref and default? #469

@maxlapshin

Description

@maxlapshin

Field in API can refer to some component and have default value. Speccy doesn't allow combining allOf $ref and default

Detailed description

For example:

components:
    frame_video_pix_fmt:
      enum:
        - yuv420p
        - yuvj420p
        - yuv422p
        - yuv444p
...

        pix_fmt:
          allOf:
            - $ref: "#/components/schemas/frame_video_pix_fmt"
          default: yuv420p

It is illegal to specify

        pix_fmt:
          $ref: "#/components/schemas/frame_video_pix_fmt"
          default: yuv420p

because $ref must rewrite completely current object and does not allow any siblings.
Using allOf is a working hack to allow having siblings for $ref, but speccy doesn't allow default with $ref

I suppose that speccy should either validate default against referenced component, either do not complain about having default without type:

$ speccy lint   http://localhost:8080/flussonic/api/v3/schema
Specification schema is invalid.

#/components/schemas/track_info/properties/pix_fmt
expected Object {
  allOf: Array [ Object { $ref: '#/components/schemas/frame_video_pix_fmt' } ],
  default: 'yuv420p',
  deprecated: true
} to have property type

Your environment

$ speccy --version
0.11.0
$ node --version
v14.7.0
$ uname -a
Darwin maxbook-m1.e 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions