Skip to content

Commit

Permalink
provide 'required' as an argument while creating schema structure
Browse files Browse the repository at this point in the history
'required' is very crucial field to be added into the schema to support multiple usecases.

Fixes: #120

Signed-off-by: Amar Tumballi <[email protected]>
  • Loading branch information
amarts committed Sep 13, 2023
1 parent 85af4d3 commit 829049f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions demo/src/utils/createDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
},
Expand Down
1 change: 1 addition & 0 deletions demo/src/utils/generateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function ensureStoredSchema(
type: 'object',
},
},
[ 'name', 'id', 'age' ],
creator
)

Expand Down
2 changes: 2 additions & 0 deletions packages/modules/src/schema/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISchema, '$id'> = {
properties,
required,
title,
$schema: SchemaModelV1.$id,
type: 'object',
Expand Down
1 change: 1 addition & 0 deletions packages/modules/src/schema/Schema.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ export interface ISchema {
| RefPattern
}
type: 'object'
required: string[]
additionalProperties?: false
}

0 comments on commit 829049f

Please sign in to comment.