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

Question: OneOf #85

Open
lbispham opened this issue Mar 14, 2018 · 0 comments
Open

Question: OneOf #85

lbispham opened this issue Mar 14, 2018 · 0 comments

Comments

@lbispham
Copy link

lbispham commented Mar 14, 2018

After the objects are serialized to JsonSchema, I need to add another field.

BEFORE:

{
  "schema": {
    "type": "object",
     "id": "urn:jsonschema:io:asfjava:ui:core:schema:Conditional",
    "properties": {
      "needColor": {
        "type": "boolean"
      },
      "color": {
        "type": "string",
        "title": "Color"
      },
      "length": {
        "type": "string",
        "title": "Length"
      }
    }
  },
  "form": [
    {
      "key": "length"
    },
    {
      "key": "color",
      "type": "select",
      "autofocus": false,
      "disabled": false,
      "multiple": false,
      "required": false,
      "size": 1,
      "titleMap": [
        {
          "name": "Red",
          "value": "red"
        },
        {
          "name": "Blue",
          "value": "blue"
        }
      ]
    }
  ]
}

AFTER

{
  "schema": {
    "type": "object",
    "id": "urn:jsonschema:io:asfjava:ui:core:schema:Conditional",
    "properties": {
      "needColor": {
        "type": "boolean"
      },
      "color": {
        "type": "string",
        "title": "Color"
      },
      "length": {
        "type": "string",
        "title": "Length"
      }
    },
    "oneOf": 
        [
            {
                "properties": {
                    "needColor": { "enum": [true] }
                },
                "required": ["color"]
            },
            {
                "properties": {
                    "needColor": { "enum": [false] }
                },
                "required": ["length"]
            }
        ]
  },
  "form": [
    {
      "key": "length"
    },
    {
      "key": "color",
      "type": "select",
      "autofocus": false,
      "disabled": false,
      "multiple": false,
      "required": false,
      "size": 1,
      "titleMap": [
        {
          "name": "Red",
          "value": "red"
        },
        {
          "name": "Blue",
          "value": "blue"
        }
       ]
    }
  ]
}

I found the following example (https://github.com/FasterXML/jackson-module-jsonSchema/blob/master/src/main/java/com/fasterxml/jackson/module/jsonSchema/customProperties/TitleSchemaFactoryWrapper.java) of injecting a new property into a JsonSchema but it uses the schema.asSimpleTypeSchema().setTitle() method which is not the same thing as injecting a brand new property.

The oneOf field would allow me to do some conditional validation on the front end. Do you know of a way to do this? I understand it's a little outside the scope of the current project. Side note: I am generating this schema for https://angular2-json-schema-form.firebaseapp.com (as opposed to Angular Schema Form). Angular2 supports the same schema format which is why I can use sf-java-ui, but also has a limited implementation of oneOf.

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

No branches or pull requests

1 participant