Skip to content

Question: OneOf #85

Open
Open
@lbispham

Description

@lbispham

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions