# How to Create New Schemas

## Purpose

The purpose of this document is to demonstrate how to create new schemas.&#x20;

## Steps

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

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FNsxfojub18LvxUPBNsn9%2FScreenshot%202023-04-05%20at%204.11.35%20PM.png?alt=media&#x26;token=3a1fc410-8ceb-4205-8d8f-60c586ddc610" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FpN0tw47yjhb2RKMqfR6B%2FScreenshot%202023-04-05%20at%204.12.27%20PM.png?alt=media&#x26;token=304f3048-bedc-4f42-af36-55a8b9eebe24" alt=""><figcaption></figcaption></figure>

* 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).

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FCLQe9IifrdGhcRHtWKjI%2FScreenshot%202023-04-05%20at%204.14.14%20PM.png?alt=media&#x26;token=1693fad6-460d-4c03-847a-6d2622aa5d39" alt=""><figcaption></figcaption></figure>

## 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&#x20;

```
{
    "@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.

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2Fw38OJRCFkxpJ39jJ4Wkb%2FScreenshot%202023-04-05%20at%204.19.26%20PM.png?alt=media&#x26;token=26baa0ae-7f05-440e-9a14-0017f56df78b" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FXmWlU2rUAYSQCIAcFw6l%2FScreenshot%202023-04-05%20at%204.20.12%20PM.png?alt=media&#x26;token=66773aaa-a45c-4b10-aff2-65a472e3387a" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FzJ6viyrVTuvrBBjkHMEG%2FScreenshot%202023-04-05%20at%204.21.49%20PM.png?alt=media&#x26;token=2df33273-0066-41e2-8d62-056d2744d2ac" alt=""><figcaption></figcaption></figure>

* 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”.

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2FWITUE5r1NyNIu3v7Ph3V%2FScreenshot%202023-04-05%20at%204.22.46%20PM.png?alt=media&#x26;token=844a8672-98fb-407e-9cca-472b2743976e" alt=""><figcaption></figcaption></figure>

* 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.

<figure><img src="https://3849653046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frmjx4OUiHEx18PH4nMzn%2Fuploads%2F5trb2wjmbcE96X6FHLe2%2FScreenshot%202023-04-05%20at%204.23.25%20PM.png?alt=media&#x26;token=ed5c0c2e-5c2a-4d1b-add4-9f3f140d54ff" alt=""><figcaption></figcaption></figure>

[![Creative Commons License](https://i.creativecommons.org/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)*All content on this page by* [*eGov Foundation*](https://egov.org.in/) *is licensed under a* [*Creative Commons Attribution 4.0 International License*](http://creativecommons.org/licenses/by/4.0/)*.*
