kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Support to skip resolving external references

Open Hunga1 opened this issue 2 years ago • 3 comments

Hello! I was wondering if it's possible to add support for allowing external references in OpenAPI v3 specification files, but skipping the resolution of those external references, such as when a $ref object is used for a schema.

Hunga1 avatar Aug 01 '22 05:08 Hunga1

When creating a loader, you can define:

  1. IsExternalRefsAllowed boolean to allow/prevent external references from being used
  2. a ReadFromURIFunc (defaults to DefaultReadFromURI) which will allow to fine tune operations. Default implementation uses a cache and http.DefaultClient.

Hope it helps

cboitel avatar Aug 02 '22 06:08 cboitel

Thanks for the info. I have a couple more questions.

From my understanding, if IsExternalRefsAllowed is set to false and an external reference exists in the spec, the parser will return an error. Is this correct?

If I have a spec that contains external references, but one or more of those external references are missing or do not exist, is it possible for the parser to continue parsing the remaining document and return the unmarshaled object?

The reason I ask is I've run into several OpenAPI v3 documents where external references exist, but those references simply do not exist. I would still like to use the parser and try to get the remaining data in the spec.

Hunga1 avatar Aug 02 '22 16:08 Hunga1

You are right if you disable external reference usage, you will get an error in such case.

As for missing external references, your source document is somewhat invalid since it references something that does not exist. You could still provide a ReadFromURIFUnc that snoozes 404 errors.

cboitel avatar Aug 21 '22 16:08 cboitel