nytimes / openapi2proto

A tool for generating Protobuf v3 schemas and gRPC service definitions from OpenAPI specifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adopt a more flexible way of resolving $ref references

jprobinson opened this issue · comments

We still have the kubernetes.json fixture commented out from tests due to a (valid) JSON Schema $ref to point to a string type:

     "$ref": {
      "type": "string"
     },

We should be able to detect this and simply resolve it as a type: string.

Hopefully this is the only thing preventing us from using the k8s spec as a fixture :)

IIRC this was not necessarily because of the "$ref" itself, but it was rather in the way that the openapi2proto code expects only objects. I think something can be worked out, but I think it's more of a matter of coming up with a minimal test case first.

I'm looking into this in the context of #128.

https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 states in section 3:

    A JSON Reference is a JSON object, which contains a member named
   "$ref", which has a JSON string value.  Example:

   { "$ref": "http://example.com/example.json#/foo/bar" }

   If a JSON value does not have these characteristics, then it SHOULD
   NOT be interpreted as a JSON Reference.

   The "$ref" string value contains a URI [RFC3986], which identifies
   the location of the JSON value being referenced.  It is an error
   condition if the string value does not conform to URI syntax rules.
   Any members other than "$ref" in a JSON Reference object SHALL be
   ignored.

That seems pretty clear - $ref should contain a URI. Under which circumstances would

     "$ref": {
      "type": "string"
     }

be valid according to the OpenAPI spec?