From 70df5d5f69356701712a541476e6e4a7327106c0 Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Fri, 10 May 2024 20:16:30 +0400 Subject: [PATCH 1/4] JSON schemas for client and administrator entities with inheritance from the user table. --- resources/schema/Administrator.json | 22 ++++++++++++++++++ resources/schema/Client.json | 27 ++++++++++++++++++++++ resources/schema/User.json | 35 +++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 resources/schema/Administrator.json create mode 100644 resources/schema/Client.json create mode 100644 resources/schema/User.json diff --git a/resources/schema/Administrator.json b/resources/schema/Administrator.json new file mode 100644 index 00000000..548d9c2a --- /dev/null +++ b/resources/schema/Administrator.json @@ -0,0 +1,22 @@ +{ + "administrator": { + "allOf": [ + { + "$ref": "#/definitions/user" + }, + { + "type": "object", + "properties": { + "job_title": { + "type": "string", + "minLength": 4 + }, + "is_super_admin": { + "type": "boolean" + } + }, + "required": ["job_title"] + } + ] + } +} diff --git a/resources/schema/Client.json b/resources/schema/Client.json new file mode 100644 index 00000000..f8c855dd --- /dev/null +++ b/resources/schema/Client.json @@ -0,0 +1,27 @@ +{ + "client": { + "allOf": [ + { + "$ref": "#/definitions/user" + }, + { + "type": "object", + "properties": { + "street": { + "type": "string", + "minLength": 4 + }, + "city": { + "type": "string", + "minLength": 3 + }, + "district_id": { + "type": "integer", + "minimum": 1 + } + }, + "required": ["street", "city", "district_id"] + } + ] + } +} diff --git a/resources/schema/User.json b/resources/schema/User.json new file mode 100644 index 00000000..5eef3d3a --- /dev/null +++ b/resources/schema/User.json @@ -0,0 +1,35 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "user": { + "type": "object", + "properties": { + "user_id": { + "type": "integer", + "minimum": 1 + }, + "email": { + "type": "string", + "format": "email" + }, + "first_name": { + "type": "string", + "minLength": 3 + }, + "password": { + "type": "string", + "minLength": 8 + }, + "phone_no": { + "type": "string", + "minLength": 7 + }, + "last_name": { + "type": "string", + "minLength": 3 + } + }, + "required": ["user_id", "email", "first_name", "password", "phone_no"] + } + } +} \ No newline at end of file From c4514c973a81fbe493573c582144af3e17ec3bca Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Wed, 15 May 2024 18:03:43 +0400 Subject: [PATCH 2/4] update schema files to reference User.json --- resources/schema/Administrator.json | 2 +- resources/schema/Client.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/schema/Administrator.json b/resources/schema/Administrator.json index 548d9c2a..3cf54e96 100644 --- a/resources/schema/Administrator.json +++ b/resources/schema/Administrator.json @@ -2,7 +2,7 @@ "administrator": { "allOf": [ { - "$ref": "#/definitions/user" + "$ref": "User.json#/definitions/user" }, { "type": "object", diff --git a/resources/schema/Client.json b/resources/schema/Client.json index f8c855dd..9532fe0d 100644 --- a/resources/schema/Client.json +++ b/resources/schema/Client.json @@ -2,7 +2,7 @@ "client": { "allOf": [ { - "$ref": "#/definitions/user" + "$ref": "User.json#/definitions/user" }, { "type": "object", From b14f26f641f260d16541fef4df6c110bd5a62c34 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Sat, 18 May 2024 13:39:00 +0400 Subject: [PATCH 3/4] format files --- resources/schema/Administrator.json | 4 ++- resources/schema/Client.json | 6 ++++- resources/schema/Comment.json | 34 ++++++++++++++++++++------ resources/schema/Product.json | 11 ++++++++- resources/schema/Review.json | 38 +++++++++++++++++++++++------ resources/schema/User.json | 8 +++++- 6 files changed, 83 insertions(+), 18 deletions(-) diff --git a/resources/schema/Administrator.json b/resources/schema/Administrator.json index 3cf54e96..c91b4d93 100644 --- a/resources/schema/Administrator.json +++ b/resources/schema/Administrator.json @@ -15,7 +15,9 @@ "type": "boolean" } }, - "required": ["job_title"] + "required": [ + "job_title" + ] } ] } diff --git a/resources/schema/Client.json b/resources/schema/Client.json index 9532fe0d..8b23aae5 100644 --- a/resources/schema/Client.json +++ b/resources/schema/Client.json @@ -20,7 +20,11 @@ "minimum": 1 } }, - "required": ["street", "city", "district_id"] + "required": [ + "street", + "city", + "district_id" + ] } ] } diff --git a/resources/schema/Comment.json b/resources/schema/Comment.json index 155d450f..a6ed716d 100644 --- a/resources/schema/Comment.json +++ b/resources/schema/Comment.json @@ -3,12 +3,32 @@ "title": "Comment", "type": "object", "properties": { - "comment_id": { "type": "integer" }, - "text": { "type": "string", "minLength": 1, "maxLength": 2000 }, - "created_date": { "type": "string", "format": "date-time" }, - "parent_comment_id": { "type": "integer" }, - "user_id": { "type": "integer" }, - "review_id": { "type": "integer" } + "comment_id": { + "type": "integer" + }, + "text": { + "type": "string", + "minLength": 1, + "maxLength": 2000 + }, + "created_date": { + "type": "string", + "format": "date-time" + }, + "parent_comment_id": { + "type": "integer" + }, + "user_id": { + "type": "integer" + }, + "review_id": { + "type": "integer" + } }, - "required": ["comment_id", "text", "created_date", "user_id"] + "required": [ + "comment_id", + "text", + "created_date", + "user_id" + ] } diff --git a/resources/schema/Product.json b/resources/schema/Product.json index d1b0bfde..3c6f3dff 100644 --- a/resources/schema/Product.json +++ b/resources/schema/Product.json @@ -48,7 +48,16 @@ "description": "The date and time when the product was created" } }, - "required": ["name", "calories", "img_url", "img_alt_text", "category", "price", "description", "created_date"], + "required": [ + "name", + "calories", + "img_url", + "img_alt_text", + "category", + "price", + "description", + "created_date" + ], "additionalProperties": false, "patternProperties": { "img_url": { diff --git a/resources/schema/Review.json b/resources/schema/Review.json index c5e2863a..04657aa2 100644 --- a/resources/schema/Review.json +++ b/resources/schema/Review.json @@ -3,12 +3,36 @@ "title": "Review", "type": "object", "properties": { - "review_id": { "type": "integer" }, - "rating": { "type": "integer", "minimum": 1, "maximum": 5 }, - "created_date": { "type": "string", "format": "date-time" }, - "text": { "type": "string", "minLength": 2, "maxLength": 2000 }, - "client_id": { "type": "integer" }, - "product_id": { "type": "integer" } + "review_id": { + "type": "integer" + }, + "rating": { + "type": "integer", + "minimum": 1, + "maximum": 5 + }, + "created_date": { + "type": "string", + "format": "date-time" + }, + "text": { + "type": "string", + "minLength": 2, + "maxLength": 2000 + }, + "client_id": { + "type": "integer" + }, + "product_id": { + "type": "integer" + } }, - "required": ["review_id", "rating", "created_date", "text", "client_id", "product_id"] + "required": [ + "review_id", + "rating", + "created_date", + "text", + "client_id", + "product_id" + ] } diff --git a/resources/schema/User.json b/resources/schema/User.json index 5eef3d3a..b1c3ac74 100644 --- a/resources/schema/User.json +++ b/resources/schema/User.json @@ -29,7 +29,13 @@ "minLength": 3 } }, - "required": ["user_id", "email", "first_name", "password", "phone_no"] + "required": [ + "user_id", + "email", + "first_name", + "password", + "phone_no" + ] } } } \ No newline at end of file From a0de75862b8cc5400c2ce7f24d4aed523b529a20 Mon Sep 17 00:00:00 2001 From: creme332 <65414576+creme332@users.noreply.github.com> Date: Sat, 18 May 2024 13:45:15 +0400 Subject: [PATCH 4/4] define $schema, define schema at root level instead of nested --- resources/schema/Administrator.json | 41 +++++++++++---------- resources/schema/Client.json | 55 ++++++++++++++--------------- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/resources/schema/Administrator.json b/resources/schema/Administrator.json index c91b4d93..e95359e8 100644 --- a/resources/schema/Administrator.json +++ b/resources/schema/Administrator.json @@ -1,24 +1,23 @@ { - "administrator": { - "allOf": [ - { - "$ref": "User.json#/definitions/user" - }, - { - "type": "object", - "properties": { - "job_title": { - "type": "string", - "minLength": 4 - }, - "is_super_admin": { - "type": "boolean" - } + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ + { + "$ref": "User.json#/definitions/user" + }, + { + "type": "object", + "properties": { + "job_title": { + "type": "string", + "minLength": 4 }, - "required": [ - "job_title" - ] - } - ] - } + "is_super_admin": { + "type": "boolean" + } + }, + "required": [ + "job_title" + ] + } + ] } diff --git a/resources/schema/Client.json b/resources/schema/Client.json index 8b23aae5..842b1652 100644 --- a/resources/schema/Client.json +++ b/resources/schema/Client.json @@ -1,31 +1,30 @@ { - "client": { - "allOf": [ - { - "$ref": "User.json#/definitions/user" - }, - { - "type": "object", - "properties": { - "street": { - "type": "string", - "minLength": 4 - }, - "city": { - "type": "string", - "minLength": 3 - }, - "district_id": { - "type": "integer", - "minimum": 1 - } + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ + { + "$ref": "User.json#/definitions/user" + }, + { + "type": "object", + "properties": { + "street": { + "type": "string", + "minLength": 4 + }, + "city": { + "type": "string", + "minLength": 3 }, - "required": [ - "street", - "city", - "district_id" - ] - } - ] - } + "district_id": { + "type": "integer", + "minimum": 1 + } + }, + "required": [ + "street", + "city", + "district_id" + ] + } + ] }