From 829049f196b7818fb815b1382cf186a29d38456b Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Wed, 13 Sep 2023 12:17:16 +0530 Subject: [PATCH] provide 'required' as an argument while creating schema structure 'required' is very crucial field to be added into the schema to support multiple usecases. Fixes: #120 Signed-off-by: Amar Tumballi --- demo/src/utils/createDocument.ts | 2 -- demo/src/utils/generateSchema.ts | 1 + packages/modules/src/schema/Schema.ts | 2 ++ packages/modules/src/schema/Schema.types.ts | 1 + packages/types/src/Schema.ts | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/demo/src/utils/createDocument.ts b/demo/src/utils/createDocument.ts index 79a8e2f4..f507817e 100644 --- a/demo/src/utils/createDocument.ts +++ b/demo/src/utils/createDocument.ts @@ -23,14 +23,12 @@ export async function createDocument( name: 'Alice', age: 29, id: '123456789987654321', - gender: 'Female', country: 'India', address: { street: 'a', pin: 54032, location: { state: 'karnataka', - country: 'india' } } }, diff --git a/demo/src/utils/generateSchema.ts b/demo/src/utils/generateSchema.ts index 0930436f..8f6b7b12 100644 --- a/demo/src/utils/generateSchema.ts +++ b/demo/src/utils/generateSchema.ts @@ -37,6 +37,7 @@ export async function ensureStoredSchema( type: 'object', }, }, + [ 'name', 'id', 'age' ], creator ) diff --git a/packages/modules/src/schema/Schema.ts b/packages/modules/src/schema/Schema.ts index 5a8713b2..7b8eaaa3 100644 --- a/packages/modules/src/schema/Schema.ts +++ b/packages/modules/src/schema/Schema.ts @@ -211,10 +211,12 @@ export function verifySchemaMetadata(metadata: ISchemaMetadata): void { export function fromProperties( title: ISchema['title'], properties: ISchema['properties'], + required: ISchema['required'], creator: DidUri ): ISchema { const schema: Omit = { properties, + required, title, $schema: SchemaModelV1.$id, type: 'object', diff --git a/packages/modules/src/schema/Schema.types.ts b/packages/modules/src/schema/Schema.types.ts index d048f365..5a7c23d4 100644 --- a/packages/modules/src/schema/Schema.types.ts +++ b/packages/modules/src/schema/Schema.types.ts @@ -32,6 +32,7 @@ export const SchemaModelV1: JsonSchema.Schema & { $id: string } = { type: 'object', }, additionalProperties: { const: false, type: 'boolean' }, + required: { type: 'array', items: { type: 'string' } }, }, additionalProperties: false, required: [ diff --git a/packages/types/src/Schema.ts b/packages/types/src/Schema.ts index f3c15138..010c8586 100644 --- a/packages/types/src/Schema.ts +++ b/packages/types/src/Schema.ts @@ -54,5 +54,6 @@ export interface ISchema { | RefPattern } type: 'object' + required: string[] additionalProperties?: false }