speccy icon indicating copy to clipboard operation
speccy copied to clipboard

Resolve allows non-existent references

Open dlouzan opened this issue 6 years ago • 1 comments

When using external references I'm observing the following behavior:

  • referencing a nonexistent element defined in the same file will fail on resolve (expected)
  • referencing a nonexistent external file will trigger an error on resolve (expected)
  • referencing an nonexistent element inside an existing external file will be ok (!!!) for resolve and generate a spec with empty content for that reference {}

Example:

  /:
...
      responses:
        '200':
          description: OK
          content:
            application/vnd.api+json:
              schema:
                # This will fail on *lint*, ref can't be resolved
                $ref: '#/components/schemas/idontexist'
            application/xml:
              schema:
                # This will fail on *resolve*, file can't be found
                $ref: 'idontexist.yaml#/components/schemas/iexist'
            application/json:
              schema:
                # Resolve will set `schema: {}` and lint will pass
                $ref: 'iexist.yaml#/components/schemas/idontexist'
...

Most of the time this will fail at the lint phase, because the generated content will not be OAS spec-compliant, but this will bite specifically with schemas, since apparently an empty schema is fine (at least for speccy, not sure if OAS compliant).

I'm not sure if this is intended behavior, but it's leading to some weird errors at least on my side, because the resolve command will output some schemas as empty if they are incorrectly referenced (e.g. typo), and lint will happily accept the output. Then later users realize that some schemas are empty.

--rules=strict is not helping either. I guess this could be solved by adding a new lint rule that checks for empty schemas, but I'm not seeing the point of allowing these empty references in the first place when resolving.

dlouzan avatar Jan 29 '19 12:01 dlouzan

This behavior is definitely surprising, what is the process to change it?

kanekv avatar Dec 07 '19 07:12 kanekv