Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields with oneOf tag are not displayed #112

Open
kventos opened this issue Oct 10, 2017 · 1 comment
Open

Fields with oneOf tag are not displayed #112

kventos opened this issue Oct 10, 2017 · 1 comment

Comments

@kventos
Copy link

kventos commented Oct 10, 2017

Hi!

I have a problem with form generating with properties containing oneOf tag. I tried to convert JSON with this peace on the demo converter site here and got only field name with empty text field which cannot be submitted.

What should I do for correct work?

"SomeProperty" : {
        "type" : "object",
        "description" : "Some property description",
        "oneOf" : [ {
            "properties" : {
                "PropertyType" : {
                    "type" : "string",
                    "description" : "Property type description",
                    "enum" : [ "firstValue", "secondValue" ]
                },
                "PropertyValue" : {
                    "type" : "string",
                    "minLength" : 1,
                    "description" : "Property value description"
                }
            },
            "required" : [ "PropertyType", "PropertyValue" ],
            "additionalProperties" : false
        }, {
            "properties" : {
                "PropertyType" : {
                    "type" : "string",
                    "description" : "Property type description",
                    "enum" : [ "thirdValue", "forthValue" ]
                },
                "PropertyValue" : {
                    "type" : "string",
                    "minLength" : 1,
                    "description" : "Property value description",
                    "pattern" : "^[A-Z]{2}[A-Z0-9]{9}[0-9]$"
                }
            },
            "required" : [ "PropertyType", "PropertyValue" ],
            "additionalProperties" : false
        } ]
      }

Whole JSON

{
  "schema": {
    "type": "object",
    "properties": {
      "first_name": { "type": "string" },
      "last_name": { "type": "string" },
      "address": {
        "type": "object",
        "properties": {
          "street_1": { "type": "string" },
          "street_2": { "type": "string" },
          "city": { "type": "string" },
          "state": {
            "type": "string",
            "enum": [ "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE",
                "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA",
                "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS",
                "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND",
                "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD",
                "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY" ]
          },
          "zip_code": { "type": "string" }
        }
      },
      "birthday": { "type": "string" },
      "notes": { "type": "string" },
      "phone_numbers": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "number": { "type": "string" },
            "type": {
              "type": "string",
              "enum": [ "cell", "home", "work" ]
            }
          },
          "required": [ "number", "type" ]
        }
      },
      "SomeProperty" : {
        "type" : "object",
        "description" : "Some property description",
        "oneOf" : [ {
            "properties" : {
                "PropertyType" : {
                    "type" : "string",
                    "description" : "Property type description",
                    "enum" : [ "firstValue", "secondValue" ]
                },
                "PropertyValue" : {
                    "type" : "string",
                    "minLength" : 1,
                    "description" : "Property value description"
                }
            },
            "required" : [ "PropertyType", "PropertyValue" ],
            "additionalProperties" : false
        }, {
            "properties" : {
                "PropertyType" : {
                    "type" : "string",
                    "description" : "Property type description",
                    "enum" : [ "thirdValue", "forthValue" ]
                },
                "PropertyValue" : {
                    "type" : "string",
                    "minLength" : 1,
                    "description" : "Property value description",
                    "pattern" : "^[A-Z]{2}[A-Z0-9]{9}[0-9]$"
                }
            },
            "required" : [ "PropertyType", "PropertyValue" ],
            "additionalProperties" : false
        } ]
      }
    }
  }
}

screen

@dschnelldavis
Copy link
Owner

Yes, for the moment, this is a known limitation of this library. In most cases 'oneOf' and 'anyOf' schemas will not display.

One exception that you can use a 'oneOf' schema to create a select control if you format it like this:

"oneOf":  [
  { "title": "James T. Kirk",    "enum": [ "William Shatner" ] },
  { "title": "Jean-Luc Picard",  "enum": [ "Patrick Stewart" ] },
  { "title": "Jack Harkness",    "enum": [ "John Barrowman"  ] },
  { "title": "Malcolm Reynolds", "enum": [ "Nathan Fillion"  ] }
]

or this

"oneOf":  [
  { "title": "James T. Kirk",    "const": "William Shatner" },
  { "title": "Jean-Luc Picard",  "const": "Patrick Stewart" },
  { "title": "Jack Harkness",    "const": "John Barrowman"  },
  { "title": "Malcolm Reynolds", "const": "Nathan Fillion"  }
]

But other than that, 'oneOf' and 'anyOf' schemas don't currently display at all.

I've created empty stubs for a new anyOf widget, as well as a Material Design version, which will fix this problem when they're finished. However, I don't have time to build the widget right now. So if someone else wants to take it on, that would be great. Otherwise, it will have to go on the to-do list for the time being, and I'll get to it when I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants