Importing a data model definition file

You can automatically populate a data model with composite types and enumeration types that are imported from a JSON schema file.

About this task

The following JSON schema formats are supported:
  • Swagger 2.0
  • OpenAPI 2.0
  • OpenAPI 3.0
  • OpenAPI 3.1
  • JSON schema draft 04
  • JSON schema draft 06
  • JSON schema draft 07
  • JSON schema draft 2019-09
  • JSON schema draft 2020-12
The following example shows a Swagger 2.0 definition file that contains a definitions element. Inside the definitions element, two data types are described:
  • A composite type person with multiple attributes.
  • An enumeration type status with three values, Married, Single, and Divorced.
{
  "swagger": "2.0",
  "info": {
    "title": "Swagger definition file",
    "description": "Simple definition file"
  },
  "definitions": {
    "Person": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "dateOfBirth": {
          "type": "string",
          "format": "date-time"
        },
        "dateOfLoanStart": {
          "type": "string",
          "format": "date"
        },
        "numberOfChildren": {
          "type": "integer"
        },
        "income": {
          "type": "number"
        },
        "noBankrupcy": {
          "type": "boolean"
        },
        "lastName": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "Married",
            "Single",
            "Divorced"
          ]
        },
        "descendants": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Person"
          }
        }
      }
    }
  }
}

Customizing names of data types and attributes that are imported

You can annotate schemas to preserve the data types and attributes that you want to import. The following tags are available:
  • x-ibm-decision-adapt-type-name: when set to false, the name of the data type is preserved.
  • x-ibm-decision-adapt-property-name: when set to false, the name of the attribute is preserved.

Take the following example:

"RadioNetworkControllerRole": {
    "x-ibm-decision-adapt-type-name" : false,
    "x-ibm-decision-adapt-property-name" : false,
    "enum": [
      "D_NRC",
      "S_NRC"
    ],
    "type": "string"
  }

Without the x-ibm-decision-adapt-type-name tag set to false, the data type name might appear as radio network controller role when it is imported into Decision Designer.

Without the x-ibm-decision-adapt-property-name tag set to false, the two attributes might appear as D NRC and S NRC when it is imported into Decision Designer.

From 24.0.0-IF001Importing types that can be shared between schemas

If you import a schema that contains the type Person in data model 1, and another schema that contains the same type Person in data model 2, you cannot use both the data models at the same time.

For example:
  • To have the data model 2 that depends on the data model 1
  • To have a decision model that depends on both the data models

These two types are considered different in these cases as they are created in different packages, while they have the same verbalizations.

Use the annotation x-ibm-pattern-to-package in the imported schemas to select in which package the shared types are placed so that they are considered the same type.

See the following annotation example in an OpenAPI schema:
{
  "openapi": "3.0.3",
  "x-ibm-pattern-to-package" : {
     "^Shared.*$" : "com.shared"
},

The x-ibm-pattern-to-package annotation must be put at the top level. It can contain several regular expressions and relate them to a package name. Here, all types that begin with Shared in the schema is put in the com.shared package.

Apply the same x-ibm-pattern-to-package annotation to all the schemas that contain the types to be shared. Each time a schema is imported, the shared types are created in the shared packages.

Procedure

  1. Open the Data tab in your decision service and click Create.
  2. Enter a name for the data model.
  3. Drag your definition file into the drop target area.
    Alternatively, you can click the drop target area and navigate to the definition file on your local system.
  4. Click Create.

Results

Your data model opens. You can now start to use the data types that it contains in your decision service. For more information, see Using data models in other decision artifacts.