Skip to content

Unable to have $ref, allOf, etc under properties in a schema. #4168

@jlhawn

Description

@jlhawn

I ran into an issue where an API spec for Kubernetes has a definition for a type named JSONSchemaProps. This is used for the custom resources feature of k8s - you can define your own API resources and you supply a JSON schema. This means that a JSON schema actually needs to be defined as a JSON schema. This includes the properties $ref, allOf and others.

Unfortunately, a definition like this one results in errors:

{
  "definitions": {
    "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps": {
      "description": "JSONSchemaProps is a JSON-Schema following Specification Draft 4 (http://json-schema.org/).",
      "properties": {
        "$ref": {
          "type": "string"
        },
...

Saying that $ref is expected to be of type string. In this case though, I would expect that it's a perfectly legal value. $ref is actually the name of that property! It seems like swagger-ui is special-casing it when it shouldn't be.

A similar error occurs with the allOf or anyOf properties where it expects them to be an array.

If this is not considered a bug in swagger-ui, is there a way to escape $ref so that you can actually describe a property whose name is literally $ref?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions