Schema modification

After you create a schema, you must add a category, a group, or an item type to design the schema. You can then use the types of the schema to design the structural view of the schema. To perform all these modifications on the schema, you must use the PATCH method.

Prerequisites

You must have the following information before you modify the schema:

The PATCH method

The operations of the PATCH method that you require to modify the schema are grouped into four phases:
  • Phase 1: Adding the types in a schema
  • Phase 2: Modifying the types in a schema
  • Phase 3: Defining the structural view of a schema
  • Phase 4: Managing the components in the structural view of a schema

The following table lists the operations that you require to modify the schema:

Phases Operations Purpose
Phase 1: Adding the types in a schema add_types You can add the types under Dictionary of a schema.
Phase 2: Modifying the types in a schema change_type You can convert types from one type to another in a schema. The types includes category, group, and item.
change_property You can change the properties of any type.
delete_type You can delete a type listed under Dictionary of a schema.
rename_type You can rename a type listed under Dictionary of a schema.
Phase 3: Defining the structural view of a schema add_component You can add the components to define the structural view of a schema.
Phase 4: Managing the components in the structural view of a schema change_component You can modify a property of a component in the structural view of a schema.
delete_component You can delete any component from the structural view of a schema.
You can modify the schema by using the following attributes:
Attributes Description
schema_id

The unique identification string that is assigned when you create a schema.

type_id

The identification number of the type that is assigned when you add a type under Dictionary.

This number must be an integer.

component_id

The identification number of the component that is assigned when you add a component corresponding to the type in the structural view of the schema.

This number must be an integer.

parent_type_id

The identification number of the type under which you can add the current type under Dictionary.

This number must be an integer.

value

The expression used to apply the rules on the item.

type_class

The type of the schema entities such as item, group, or category.

type_sequence_number

The sequence number in which the type is added in the schema structure. The sequence starts from zero.

This number must be an integer.

For example, in the schema, if there are three types in the structure, then type_sequence_number for the current type is two. Similarly, if you add the first type in the structure, then type_sequence_number for that type is zero.

type_path The type path is a path of any type in the schema.

For example, in the schema, if there is a Root category, with the Student group and the Name item type, then the type_path for the Student type is - Root:Student.

Response code

You can view the following response after you run the request:
HTTP response code Response example
200
{ 
 "_id":"5ef9967f0f11a4009dfdbe55", 
 "name":"otdschema2", 
 “message”:”Schema updated successfully”, 
  code:200 
}  

Error codes

The following table lists the error codes that can generate on the failure of the request:
HTTP error codes Response examples
401 (Invalid Token)
{ 
  "timestamp":"2020-07-01T05:22:29.233Z", 
  "code":401, 
  "messages":["Invalid token."] 
}  
401 (Session Expired)
{ 
  "timestamp":"2020-07-01T05:22:29.233Z", 
  "code":401, 
  "messages":["Session expired."] 
} 
404
{ 
  "_id":null, 
  "name":null, 
  "message":" A schema with id 5efc3b690f11a4009dfdbe8e does not exist in project 1150.", 
  "code":400 
} 
400
Adding a type with duplicate id 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":[ 
    " There is a duplicate id 1 in the schema's dictionary component." 
  ] 
} 

Type id of the type is out of range (It should be type id of last type added +1) 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":[" The id 5 is out of range "] 
} 
 
Missing class Name 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":[" Class attribute must be specified"] 
} 
 
Missing operation 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":[" Operation attribute must be specified."] 
} 
 
Invalid JSON 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":[“Missing property in path $['item_props']" 
  ] 
} 

Invalid data language 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":["Invalid data language."] 
} 
 
Invalid national language 
{ 
  "timestamp":"2020-07-19T13:03:44.757Z", 
  "code":400, 
  "messages":["Invalid national language."] 
} 

Adding invalid type class in dictionary 
{ 
  "timestamp":"2020-07-21T08:00:33.410Z", 
  "code":400, 
  "messages":["Invalid value for type class."] 
} 

Adding item, category under group type  
{ 
  "timestamp":"2020-07-21T08:00:33.410Z", 
  "code":400, 
  "messages":["Cannot add item or category under parent type group." 
  ] 
} 
 
Adding group, category under item type  
{ 
  "timestamp":"2020-07-21T08:00:33.410Z", 
  "code":400, 
  "messages":[ 
    "Cannot add group or category under parent type item." 
  ] 
} 
 
Adding type with duplicate name  
{ 
  "timestamp":"2020-07-21T08:00:33.410Z", 
  "code":400, 
  "messages":["Age Typename already present in the schema."] 
 
Renaming / Deleting non-existing type 
{ 
  "timestamp":"2020-07-30T07:23:35.609Z", 
  "code":400, 
  "messages":["No type was found with id 100."] 
} 
 
Renaming type to duplicate name  
{ 
  "timestamp":"2020-07-30T07:23:12.785Z", 
  "code":400, 
  "messages":["Name \"Name10\" is already present in a subtype of type \"Root\"."] 
}  
500
{ 
  "_id":null, 
  "name":null, 
  "message":"", 
  "code":500 
} 
 

Example of the cURL command

You can also use the following cURL command to modify the schema:

curl -X PATCH 'https://otd-fvt2.nonprod.hclpnp.com/onetest-data/rest/v1/otd/projects/9800/schemas/5f0eb76ea0dd6f009d2fb6a8' \ 
--header 'Authorization: Bearer xxxxxxxx' \ 
--header 'Content-Type: application/json;charset=utf-8' \ 
--header 'Accept: application/json;charset=utf-8' \ 
--data-raw '[ 
    { 
       "operation":"add_type", 
       "parent_type_id":0, 
       "component_id":null, 
       "value":{ 
            "name":"NewType1", 
            "class":"category", 
            "id":1, 
            "subtypes":[] 
       } 
    }