How to Create New Schemas

Purpose

The purpose of this document is to demonstrate how to create new schemas.

Steps

  • For creating a new schema, the user needs to click on the “Manage Schema” button on the home page.

  • Next, click on “Create Schema” in the next page

  • If the user already has a schema in JSON format, he/she can click on “Upload JSON” (refer to section on "Steps to Create Schema Using JSON" for more details).

  • If the user wants to create a new schema manually click on ‘Add Manually’ (refer to the section on “Create Schema Manually” for more details).

Steps to Create Schema Using JSON

Step 1: Create the context using API call

  • Request method: POST

  • Request URL:{{baseUrl}}/vc-management/v1/context/

  • Request body

  • Key: Files

  • Value: ContextFile.json(should be in json format)

Content for the ContextFile.json

{
    "@context": {
        "@version": 1.1,
        "@protected": true,
        "id": "@id",
        "type": "@type",
        "schema": "https://schema.org/",
        "hp": "https://council.gov.in/credentials/healthProfessional/v1",
        "ProofOfHealthProfessionalCredential": {
            "@id": "schema:ProofOfHealthProfessionalCredential",
            "@context": {
                "@version": 1.1,
                "@protected": true,
                "nonTransferable": "vac:nonTransferable"
            }
        },
        "Person": {
            "@id": "schema:Person",
            "@context": {
                "@version": 1.1,
                "@protected": true,
                "registrationId": "schema:id",
                "name": "schema:name",
                "dob": "schema:date",
                "gender": "schema:gender"
            }
        },
        "HealthProfessional_1": {
            "@id": "hp:HealthProfessional",
            "@context": {
                "@version": 1.1,
                "@protected": true,
                "certificateId": "schema:id",
                "registrationCouncil": "schema:Text",
                "latestQualification": "schema:Text",
                "university": "schema:Text",
                "registrationDate": "schema:date",
                "systemOfMedicine": "schema:Text",
                "registrationExpiry": "schema:date",
                "degreeYear": "schema:Text"
            }
         }    } }

Response Json

  • The Id used here, that is, HealthProfessional_1, should be common in both context file creation, and its multiple occurrences in schema file.

{
    "message": {
        "id": "sunbird-rc.registry.create",
        "ver": "1.0",
        "ets": 1674742182025,
        "params": {
            "resmsgid": "",
            "msgid": "80813191-139c-40a8-918f-060273cbb747",
            "err": "",
            "status": "SUCCESSFUL",
            "errmsg": ""
        },
        "responseCode": "OK",
        "result": {
            "ContextURL": {
                "osid": "1-a6bd2f3b-43d4-406e-a265-917ff6d5199f"
            }
        }
    },
    "url": "http://vc-management-service:7655/vc-management/v1/context/a6bd2f3b-43d4-406e-a265-917ff6d5199f" }

Step 2: Upload Templates

  • Request method: POST

  • Request URL:{{baseUrl}}/vc-management/v1/templates/Tenant

  • Request body

  • Key: Files

  • Value: TempHealthcareUpdated.html (It is the name of html file template)

Refer Annexure A for Sample html File (TempHealthcareUpdated.html)

Response Json

{
    "uploadTemplateResponse": {
        "documentLocations": [
            "Tenant/f28d95e7-17ea-4f93-b457-195d133fbc27/templates/documents/d7390e5b-578a-4823-a7a1-7395d93361b3-vcTempHealthcareUpdated.html"
        ],
        "errors": []
    }
}

Step 3: Create and Upload Schema.json file

  • Create this file and save it in the local directory and upload in the application.

  • The ID used here, that is, HealthProfessional_1 will be used in context file creation.

  • The value of URL from the response of Step 1 will be used in below mentioned schema Json.

  • The value of document location from the response of Step 2 will be used in below mentioned SchemaJson.

SchemaJson Sample File

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "properties": {
    "HealthProfessional_1": {
      "$ref": "#/definitions/HealthProfessional_1"
    }
  },
  "required": [
    "HealthProfessional_1"
  ],
  "title": "HealthProfessional_1",
  "definitions": {
    "HealthProfessional_1": {
      "type": "object",
      "title": "HP Certificate",
      "required": [
        "name",
        "dob",
        "registrationId",
        "registrationCouncil",
        "registrationDate",
        "systemOfMedicine",
        "latestQualification",
        "degreeYear",
        "issuer",
        "issuanceDate",
        "certificateId"
      ],
      "properties": {
        "registrationId": {
          "type": "string"
        },
        "certificateId": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "dob": {
          "type": "string"
        },
        "gender": {
          "type": "string"
        },
        "registrationCouncil": {
          "type": "string"
        },
        "registrationDate": {
          "type": "string"
        },
        "registrationExpiry": {
          "type": "string"
        },
        "systemOfMedicine": {
          "type": "string"
        },
        "latestQualification": {
          "type": "string"
        },
        "university": {
          "type": "string"
        },
        "degreeYear": {
          "type": "string"
        },
        "issuer": {
          "type": "string"
        },
        "issuanceDate": {
          "type": "string"
        }
      }
    }
  },
  "_osConfig": {
    "uniqueIndexFields": [],
    "ownershipAttributes": [],
    "roles": [],
    "inviteRoles": [
      "anonymous"
    ],
    "enableLogin": false,
    "credentialTemplate": {
      "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "http://vc-management-service:7655/vc-management/v1/context/6d44d41e-93f8-4d81-8fb5-0679dcae50da"
      ],
      "type": [
        "VerifiableCredential",
        "ProofOfHealthProfessionalCredential"
      ],
      "credentialSubject": {
        "type": "Person",
        "registrationId": "{{registrationId}}",
        "name": "{{name}}",
        "dob": "{{dob}}",
        "gender": "{{gender}}"
      },
      "issuer": "{{{issuer}}}",
      "issuanceDate": "{{issuanceDate}}",
      "evidence": {
        "type": "HealthProfessional_1",
        "certificateId": "{{certificateId}}",
        "registrationCouncil": "{{registrationCouncil}}",
        "latestQualification": "{{latestQualification}}",
        "university": "{{university}}",
        "registrationDate": "{{registrationDate}}",
        "systemOfMedicine": "{{systemOfMedicine}}",
        "registrationExpiry": "{{registrationExpiry}}",
        "degreeYear": "{{degreeYear}}"
      },
      "nonTransferable": "true"
    },
    "certificateTemplates": {
      "html": "minio://Tenant/f28d95e7-17ea-4f93-b457-195d133fbc27/templates/documents/f72b3f6a-c4fe-447e-9684-692f56b81ca9-vcTempHealthcareUpdated.html ",
      "svg": "https://raw.githubusercontent.com/dileepbapat/ref-sunbirdrc-certificate/main/schemas/templates/TrainingCertificate.svg"
    }
  }
}

Steps to Create Schema Manually

The user can opt to create schema manually. The steps are as follows:

  • When a user clicks on “Create New Schema”, the page shown below will open, where the user has to fill the schema name in the “Name of the Schema” box.

  • If required, the user may fill in the description of the schema as well

  • Before moving to the next page, the user must click on ‘Save’ after entering all the information.

  • The user must drag and drop the desired field types to start creating a schema attribute.

  • The user can save an attribute after adding it in the schema by clicking on the ‘Save’ button.

  • After addition, all the attributes that are already present till that point, including the inbuilt attributes of schema, can be viewed.

  • The schema attributes that were added manually can be edited.

  • The user can add more fields in the schema by clicking on “Add Field”.

  • Once all the attributes are added, the schema can be saved as a draft by clicking on “Save as Draft”.

  • The schema draft is created with a default template which holds a QR code only.

  • More templates can be uploaded and managed using the “Upload Templates” & “Manage Templates” modal on the tenant-portal.

Last updated