From 9a8ec0456937f7d1fd5114245072f08dea38c553 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Sat, 20 Apr 2024 23:39:51 +0530 Subject: [PATCH 01/26] adding componet --- components/StyledValidator.tsx | 73 +++++++++++++++++++++ data/getting-started-examples.json | 0 pages/learn/[slug].page.tsx | 2 + pages/learn/getting-started-step-by-step.md | 8 +-- public/icons/green-tick.svg | 1 + public/icons/red-cross.svg | 17 +++++ 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 components/StyledValidator.tsx create mode 100644 data/getting-started-examples.json create mode 100644 public/icons/green-tick.svg create mode 100644 public/icons/red-cross.svg diff --git a/components/StyledValidator.tsx b/components/StyledValidator.tsx new file mode 100644 index 000000000..8dda1f46e --- /dev/null +++ b/components/StyledValidator.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import JsonEditor from './JsonEditor'; + +const StyledValidator = () => { + return ( + <> +
+
+

+ Select a JSON Schema Validator +

+ +
+ +

+ Lorem ipsum, dolor sit amet consectetur adipisicing elit. Laboriosam + tinctio sint voluptate. +

+ +

JSON Schema

+ +
+ +
+
+

+ Select a JSON Schema Instance +

+ +
+ +

Instance

+ +
+ +

Result

+
+

This is a valid JSON instance for the provided JSON Schema

+ + +
+
+ +
+ + ); +}; + +export default StyledValidator; diff --git a/data/getting-started-examples.json b/data/getting-started-examples.json new file mode 100644 index 000000000..e69de29bb diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index f110ff75d..cfbaac59d 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -7,6 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import StyledValidator from '~/components/StyledValidator'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/learn'); @@ -31,6 +32,7 @@ export default function StaticMarkdownPage({ {frontmatter.title} + ); diff --git a/pages/learn/getting-started-step-by-step.md b/pages/learn/getting-started-step-by-step.md index f9e287bb5..b9c47551b 100644 --- a/pages/learn/getting-started-step-by-step.md +++ b/pages/learn/getting-started-step-by-step.md @@ -576,7 +576,7 @@ With the external schema reference, the overall schema looks like this: This section describes how to validate JSON data against the product catalog schema. This example JSON data matches the product catalog schema: - + -To validate this JSON data against the product catalog JSON Schema, you can use any validator of your choice. In addition to command-line and browser tools, validation tools are available in a wide range of languages, including Java, Python, .NET, and many others. To find a validator that’s right for your project, see [Tools](https://json-schema.org/implementations). + diff --git a/public/icons/green-tick.svg b/public/icons/green-tick.svg new file mode 100644 index 000000000..0301794bb --- /dev/null +++ b/public/icons/green-tick.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/icons/red-cross.svg b/public/icons/red-cross.svg new file mode 100644 index 000000000..758f9b0c0 --- /dev/null +++ b/public/icons/red-cross.svg @@ -0,0 +1,17 @@ + + + + + + + + From fbfe7cb9b15c60b0392c272b3b39c1187f80fad1 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Sun, 21 Apr 2024 01:07:52 +0530 Subject: [PATCH 02/26] adding data --- data/getting-started-examples.json | 14 ++++++++++++++ .../instances/default.json | 0 data/getting-started-examples/schemas/default.json | 0 3 files changed, 14 insertions(+) create mode 100644 data/getting-started-examples/instances/default.json create mode 100644 data/getting-started-examples/schemas/default.json diff --git a/data/getting-started-examples.json b/data/getting-started-examples.json index e69de29bb..7d51bf646 100644 --- a/data/getting-started-examples.json +++ b/data/getting-started-examples.json @@ -0,0 +1,14 @@ +[ + { + "name": "Getting Started Guide", + "default": true, + "file": "/data/getting-started-examples/schemas/default.json", + "instances": [ + { + "name": "Basic valid instance", + "default": true, + "file": "/data/getting-started-examples/instances/default.json" + } + ] + } +] diff --git a/data/getting-started-examples/instances/default.json b/data/getting-started-examples/instances/default.json new file mode 100644 index 000000000..e69de29bb diff --git a/data/getting-started-examples/schemas/default.json b/data/getting-started-examples/schemas/default.json new file mode 100644 index 000000000..e69de29bb From 4a1930d253726f9eef3ac8bce500b98bc6ae3cff Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Sun, 21 Apr 2024 01:18:52 +0530 Subject: [PATCH 03/26] connecting with data --- components/StyledValidator.tsx | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/components/StyledValidator.tsx b/components/StyledValidator.tsx index 8dda1f46e..6e47741c8 100644 --- a/components/StyledValidator.tsx +++ b/components/StyledValidator.tsx @@ -1,5 +1,6 @@ import React from 'react'; import JsonEditor from './JsonEditor'; +import data from '../data/getting-started-examples.json'; const StyledValidator = () => { return ( @@ -14,12 +15,17 @@ const StyledValidator = () => { className='p-2 dark:bg-slate-900 rounded-md max-sm:text-[12px]' id='Examples' > - + {data.map((data, id) => { + return ( + + ); + })} @@ -42,12 +48,17 @@ const StyledValidator = () => { className='p-2 dark:bg-slate-900 rounded-md max-sm:text-[12px] ' id='Examples' > - + {data.map((data, id) => { + return ( + + ); + })} From 440e8ddc89392462fe1d5cd80178ac8de1d8f986 Mon Sep 17 00:00:00 2001 From: Benjamin Granados Date: Thu, 16 May 2024 15:24:06 +0200 Subject: [PATCH 04/26] Pushed data changes --- data/getting-started-examples.json | 6 ++- .../instances/default.json | 16 ++++++ .../schemas/default.json | 52 +++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/data/getting-started-examples.json b/data/getting-started-examples.json index 7d51bf646..26e134ac9 100644 --- a/data/getting-started-examples.json +++ b/data/getting-started-examples.json @@ -1,13 +1,15 @@ [ { - "name": "Getting Started Guide", + "name": "Getting Started example", "default": true, "file": "/data/getting-started-examples/schemas/default.json", "instances": [ { "name": "Basic valid instance", "default": true, - "file": "/data/getting-started-examples/instances/default.json" + "valid": true, + "file": "/data/getting-started-examples/instances/default.json", + "details": "This is a valid JSON instance for the provided JSON Schema" } ] } diff --git a/data/getting-started-examples/instances/default.json b/data/getting-started-examples/instances/default.json index e69de29bb..d09d10536 100644 --- a/data/getting-started-examples/instances/default.json +++ b/data/getting-started-examples/instances/default.json @@ -0,0 +1,16 @@ +{ + "productId": 1, + "productName": "An ice sculpture", + "price": 12.50, + "tags": [ "cold", "ice" ], + "dimensions": { + "length": 7.0, + "width": 12.0, + "height": 9.5 + }, + "warehouseLocation": { + "latitude": -78.75, + "longitude": 20.4 + } + } + \ No newline at end of file diff --git a/data/getting-started-examples/schemas/default.json b/data/getting-started-examples/schemas/default.json index e69de29bb..31764cc97 100644 --- a/data/getting-started-examples/schemas/default.json +++ b/data/getting-started-examples/schemas/default.json @@ -0,0 +1,52 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/product.schema.json", + "title": "Product", + "description": "A product from Acme's catalog", + "type": "object", + "properties": { + "productId": { + "description": "The unique identifier for a product", + "type": "integer" + }, + "productName": { + "description": "Name of the product", + "type": "string" + }, + "price": { + "description": "The price of the product", + "type": "number", + "exclusiveMinimum": 0 + }, + "tags": { + "description": "Tags for the product", + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + }, + "dimensions": { + "type": "object", + "properties": { + "length": { + "type": "number" + }, + "width": { + "type": "number" + }, + "height": { + "type": "number" + } + }, + "required": [ "length", "width", "height" ] + }, + "warehouseLocation": { + "description": "Coordinates of the warehouse where the product is located.", + "$ref": "https://example.com/geographical-location.schema.json" + } + }, + "required": [ "productId", "productName", "price" ] + } + \ No newline at end of file From 35d83fa114f0046c1fa42432969c10b19f4ba02b Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Wed, 29 May 2024 13:14:49 +0530 Subject: [PATCH 05/26] Fix:getting started data fetching problem --- data/getting-started-examples.json | 6 ++-- pages/learn/[slug].page.tsx | 2 -- .../learn/validator/index.page.tsx | 33 ++++++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) rename components/StyledValidator.tsx => pages/learn/validator/index.page.tsx (76%) diff --git a/data/getting-started-examples.json b/data/getting-started-examples.json index 26e134ac9..f56c01cc8 100644 --- a/data/getting-started-examples.json +++ b/data/getting-started-examples.json @@ -2,13 +2,13 @@ { "name": "Getting Started example", "default": true, - "file": "/data/getting-started-examples/schemas/default.json", + "file": "./data/getting-started-examples/schemas/default.json", "instances": [ { "name": "Basic valid instance", "default": true, - "valid": true, - "file": "/data/getting-started-examples/instances/default.json", + "valid": true, + "file": "./data/getting-started-examples/instances/default.json", "details": "This is a valid JSON instance for the provided JSON Schema" } ] diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index cfbaac59d..f110ff75d 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -7,7 +7,6 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; -import StyledValidator from '~/components/StyledValidator'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/learn'); @@ -32,7 +31,6 @@ export default function StaticMarkdownPage({ {frontmatter.title} - ); diff --git a/components/StyledValidator.tsx b/pages/learn/validator/index.page.tsx similarity index 76% rename from components/StyledValidator.tsx rename to pages/learn/validator/index.page.tsx index 6e47741c8..4777255c0 100644 --- a/components/StyledValidator.tsx +++ b/pages/learn/validator/index.page.tsx @@ -1,8 +1,30 @@ import React from 'react'; -import JsonEditor from './JsonEditor'; -import data from '../data/getting-started-examples.json'; +import JsonEditor from '~/components/JsonEditor'; +import data from '~/data/getting-started-examples.json'; +import fs from 'fs'; -const StyledValidator = () => { +export async function getStaticProps() { + const schemaFilepath = data.map((data) => data.file).join(''); + const instanceFilepath = data.map((data) => data.instances[0].file).join(''); + + const schemaData = fs.readFileSync(schemaFilepath, 'utf-8'); + const instanceData = fs.readFileSync(instanceFilepath, 'utf-8'); + + return { + props: { + schemaData, + instanceData, + }, + }; +} + +const StyledValidator = ({ + schemaData, + instanceData, +}: { + schemaData: string; + instanceData: string; +}) => { return ( <>
@@ -35,7 +57,8 @@ const StyledValidator = () => {

JSON Schema

- + +
@@ -63,7 +86,7 @@ const StyledValidator = () => {

Instance

- +

Result

From b20f37dec980fbc9c6b876047fea04ae5435f3bf Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Wed, 29 May 2024 20:10:09 +0530 Subject: [PATCH 06/26] updating component rendering --- .../getting-started-step-by-step.md | 0 .../index.page.tsx | 38 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) rename pages/learn/{ => getting-started-step-by-step}/getting-started-step-by-step.md (100%) rename pages/learn/{validator => getting-started-step-by-step}/index.page.tsx (76%) diff --git a/pages/learn/getting-started-step-by-step.md b/pages/learn/getting-started-step-by-step/getting-started-step-by-step.md similarity index 100% rename from pages/learn/getting-started-step-by-step.md rename to pages/learn/getting-started-step-by-step/getting-started-step-by-step.md diff --git a/pages/learn/validator/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx similarity index 76% rename from pages/learn/validator/index.page.tsx rename to pages/learn/getting-started-step-by-step/index.page.tsx index 4777255c0..7e41a500b 100644 --- a/pages/learn/validator/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -3,6 +3,14 @@ import JsonEditor from '~/components/JsonEditor'; import data from '~/data/getting-started-examples.json'; import fs from 'fs'; +import { getLayout } from '~/components/Sidebar'; +import Head from 'next/head'; +import { Headline1 } from '~/components/Headlines'; +import matter from 'gray-matter'; +import StyledMarkdown from '~/components/StyledMarkdown'; +import { SectionContext } from '~/context'; +import { DocsHelp } from '~/components/DocsHelp'; + export async function getStaticProps() { const schemaFilepath = data.map((data) => data.file).join(''); const instanceFilepath = data.map((data) => data.instances[0].file).join(''); @@ -10,23 +18,39 @@ export async function getStaticProps() { const schemaData = fs.readFileSync(schemaFilepath, 'utf-8'); const instanceData = fs.readFileSync(instanceFilepath, 'utf-8'); + const block1 = fs.readFileSync( + 'pages/learn/getting-started-step-by-step/getting-started-step-by-step.md', + 'utf-8', + ); + const { content: block1Content } = matter(block1); return { props: { schemaData, instanceData, + blocks: [block1Content], }, }; } -const StyledValidator = ({ +export default function StyledValidator({ schemaData, instanceData, + blocks, }: { schemaData: string; instanceData: string; -}) => { + blocks: any[]; +}) { + const newTitle = 'Creating your first schema'; // replace this + return ( - <> + + + {newTitle} + + {newTitle} + +

@@ -100,8 +124,8 @@ const StyledValidator = ({ Download Example

- + + ); -}; - -export default StyledValidator; +} +StyledValidator.getLayout = getLayout; From 4d79def9cdd1f48edd62ac85901efb08c5d22a1d Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Thu, 30 May 2024 23:40:35 +0530 Subject: [PATCH 07/26] adjusting layout --- data/getting-started-examples.json | 2 +- .../index.page.tsx | 44 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/data/getting-started-examples.json b/data/getting-started-examples.json index f56c01cc8..ca52dda0e 100644 --- a/data/getting-started-examples.json +++ b/data/getting-started-examples.json @@ -1,6 +1,6 @@ [ { - "name": "Getting Started example", + "name": "Getting started example", "default": true, "file": "./data/getting-started-examples/schemas/default.json", "instances": [ diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index 7e41a500b..f85989840 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -52,13 +52,11 @@ export default function StyledValidator({
-
-

- Select a JSON Schema Validator -

+
+

JSON Schema

-

- Lorem ipsum, dolor sit amet consectetur adipisicing elit. Laboriosam - tinctio sint voluptate. -

- -

JSON Schema

-
-
-

- Select a JSON Schema Instance -

+
+

Instance

-

Instance

-

Result

+

Result

-

This is a valid JSON instance for the provided JSON Schema

+ {data.map((data, id) => { + return ( + <> +

{data.instances[0].details}

- + {data.instances[0].valid ? ( + green tick + ) : ( + red cross + )} + + ); + })}
- - +
{selectedSchema}
+
@@ -83,27 +85,15 @@ export default function StyledValidator({ name='Select a JSON Schema Instance' className='p-2 border dark:border-slate-300 border-slate-800 dark:bg-slate-900 rounded-md max-sm:text-[12px] ' id='Examples' - > - {data.map((data, id) => { - return ( - - ); - })} - + >
- +

Result

- {data.map((data, id) => { + {/* {data.map((data, id) => { return ( <>

{data.instances[0].details}

@@ -115,7 +105,7 @@ export default function StyledValidator({ )} ); - })} + })} */}
-
*/} ); diff --git a/public/getting-started-examples/schemas/default copy.json b/public/getting-started-examples/schemas/default copy.json deleted file mode 100644 index c783e1b70..000000000 --- a/public/getting-started-examples/schemas/default copy.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/product.schema.json", - "title": "Product", - "description": "A product from Acme's catalog", - "type": "object", - "properties": { - "productId": { - "description": "The unique identifier for a product", - "type": "integer" - }, - "productName": { - "description": "Name of the product", - "type": "string" - }, - "price": { - "description": "The price of the product", - "type": "number", - "exclusiveMinimum": 0 - }, - "tags": { - "description": "Tags for the product", - "type": "array", - "items": { - "type": "string" - }, - "minItems": 1, - "uniqueItems": true - } - }, - "required": ["productId", "productName", "price"] -} diff --git a/public/getting-started-examples/schemas/default-extended.json b/public/getting-started-examples/schemas/default-extended.json index 769c181b6..c783e1b70 100644 --- a/public/getting-started-examples/schemas/default-extended.json +++ b/public/getting-started-examples/schemas/default-extended.json @@ -26,25 +26,6 @@ }, "minItems": 1, "uniqueItems": true - }, - "dimensions": { - "type": "object", - "properties": { - "length": { - "type": "number" - }, - "width": { - "type": "number" - }, - "height": { - "type": "number" - } - }, - "required": ["length", "width", "height"] - }, - "warehouseLocation": { - "description": "Coordinates of the warehouse where the product is located.", - "$ref": "https://example.com/geographical-location.schema.json" } }, "required": ["productId", "productName", "price"] diff --git a/public/getting-started-examples/schemas/default.json b/public/getting-started-examples/schemas/default.json index 31764cc97..769c181b6 100644 --- a/public/getting-started-examples/schemas/default.json +++ b/public/getting-started-examples/schemas/default.json @@ -1,52 +1,51 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/product.schema.json", - "title": "Product", - "description": "A product from Acme's catalog", - "type": "object", - "properties": { - "productId": { - "description": "The unique identifier for a product", - "type": "integer" - }, - "productName": { - "description": "Name of the product", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/product.schema.json", + "title": "Product", + "description": "A product from Acme's catalog", + "type": "object", + "properties": { + "productId": { + "description": "The unique identifier for a product", + "type": "integer" + }, + "productName": { + "description": "Name of the product", + "type": "string" + }, + "price": { + "description": "The price of the product", + "type": "number", + "exclusiveMinimum": 0 + }, + "tags": { + "description": "Tags for the product", + "type": "array", + "items": { "type": "string" }, - "price": { - "description": "The price of the product", - "type": "number", - "exclusiveMinimum": 0 - }, - "tags": { - "description": "Tags for the product", - "type": "array", - "items": { - "type": "string" + "minItems": 1, + "uniqueItems": true + }, + "dimensions": { + "type": "object", + "properties": { + "length": { + "type": "number" }, - "minItems": 1, - "uniqueItems": true - }, - "dimensions": { - "type": "object", - "properties": { - "length": { - "type": "number" - }, - "width": { - "type": "number" - }, - "height": { - "type": "number" - } + "width": { + "type": "number" }, - "required": [ "length", "width", "height" ] + "height": { + "type": "number" + } }, - "warehouseLocation": { - "description": "Coordinates of the warehouse where the product is located.", - "$ref": "https://example.com/geographical-location.schema.json" - } + "required": ["length", "width", "height"] }, - "required": [ "productId", "productName", "price" ] - } - \ No newline at end of file + "warehouseLocation": { + "description": "Coordinates of the warehouse where the product is located.", + "$ref": "https://example.com/geographical-location.schema.json" + } + }, + "required": ["productId", "productName", "price"] +} From cd0f5273d9716233f8d146a6262937bd3ddc9718 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Thu, 6 Jun 2024 20:39:36 +0530 Subject: [PATCH 12/26] fixing workflow --- pages/learn/getting-started-step-by-step/index.page.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index f33d67e03..6b069a43c 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -107,7 +107,6 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) { }, ]); - /* eslint-disable */ useEffect(() => { fetchData().then((data) => setOptions(data)); }, []); @@ -115,20 +114,21 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) { const handleChange = async (e: any) => { setSelectedSchema(e.target.value); const selectedSchemaObj = options.find( + // @ts-ignore (schema) => schema.file === e.target.value, ); if (selectedSchemaObj) { + // @ts-ignore setInstances(selectedSchemaObj.instances); const schemaResponse = await fetch(selectedSchema); const schemaData = await schemaResponse.json(); setFetchedSchema(schemaData); } else { setInstances([]); - setFetchedSchema(null); + setFetchedSchema(null!); } }; - /* eslint-enable */ return ( From 6cca80dfabc805d5c41f7376b16f7e69c15f8679 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Thu, 6 Jun 2024 21:32:05 +0530 Subject: [PATCH 13/26] adding fetch testing --- pages/learn/getting-started-step-by-step/index.page.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index 6b069a43c..db18cb213 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -155,6 +155,7 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) {
{selectedSchema}
+
{JSON.stringify(fetchedSchema, null, 2)}
From 946f7b08c66fecd0345d2d8deaba656fea1caffd Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Fri, 7 Jun 2024 12:48:26 +0530 Subject: [PATCH 14/26] replacing code editor --- .../index.page.tsx | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index db18cb213..7b26f42fd 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; -import JsonEditor from '~/components/JsonEditor'; import fs from 'fs'; +import { atomOneDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; import { getLayout } from '~/components/Sidebar'; import Head from 'next/head'; @@ -9,6 +9,7 @@ import matter from 'gray-matter'; import StyledMarkdown from '~/components/StyledMarkdown'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; +import Highlight from 'react-syntax-highlighter'; export async function getStaticProps() { const block1 = fs.readFileSync( @@ -154,11 +155,38 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) { ))} -
{selectedSchema}
-
{JSON.stringify(fetchedSchema, null, 2)}
- + +
+ { + const isHighlighted = false; + return { + className: `${isHighlighted ? 'bg-code-editor-dark-highlight block ml-10 w-full' : ''} pr-8`, + }; + }} + codeTagProps={{ + className: 'mr-8', + }} + > + {JSON.stringify(fetchedSchema, null, 2)} + +
From bde43c5cded45356228344e4eedc46b9dca899c7 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Fri, 7 Jun 2024 19:25:19 +0530 Subject: [PATCH 15/26] feat: enabling instnaces and moving to new component --- components/GettingStarted.tsx | 227 ++++++++++++++++++ .../index.page.tsx | 177 +------------- 2 files changed, 230 insertions(+), 174 deletions(-) create mode 100644 components/GettingStarted.tsx diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx new file mode 100644 index 000000000..42c47074b --- /dev/null +++ b/components/GettingStarted.tsx @@ -0,0 +1,227 @@ +import React, { useState, useEffect } from 'react'; +import { atomOneDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; +import Highlight from 'react-syntax-highlighter'; + +async function fetchData() { + const response = await fetch('/getting-started-examples.json'); + const data = await response.json(); + return data; +} + +const GettingStarted = () => { + const intitalSchemaData = { + $schema: 'https://json-schema.org/draft/2020-12/schema', + $id: 'https://example.com/product.schema.json', + title: 'Product', + description: 'A product from Acmes catalog', + type: 'object', + properties: { + productId: { + description: 'The unique identifier for a product', + type: 'integer', + }, + productName: { + description: 'Name of the product', + type: 'string', + }, + price: { + description: 'The price of the product', + type: 'number', + exclusiveMinimum: 0, + }, + tags: { + description: 'Tags for the product', + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, + dimensions: { + type: 'object', + properties: { + length: { + type: 'number', + }, + width: { + type: 'number', + }, + height: { + type: 'number', + }, + }, + required: ['length', 'width', 'height'], + }, + warehouseLocation: { + description: + 'Coordinates of the warehouse where the product is located.', + $ref: 'https://example.com/geographical-location.schema.json', + }, + }, + required: ['productId', 'productName', 'price'], + }; + + const [options, setOptions] = useState([]); + const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); + const [selectedSchema, setSelectedSchema] = useState( + '/getting-started-examples/schemas/default.json', + ); + const [instances, setInstances] = useState([ + { + name: 'Valid instance', + default: true, + valid: true, + file: '/getting-started-examples/instances/default-ok.json', + details: 'This is a valid JSON instance for the provided JSON Schema', + }, + { + name: 'Invalid instance', + default: false, + valid: false, + file: '/getting-started-examples/instances/default-ko.json', + details: 'This is an invalid JSON instance for the provided JSON Schema', + }, + ]); + + const [selectedInstance, setSelectedInstance] = useState( + '/getting-started-examples/instances/default-ok.json', + ); + const [fetchedInstance, setFetchedInstance] = useState({}); + + useEffect(() => { + fetchData().then((data) => setOptions(data)); + }, []); + + const handleChange = async (e: any) => { + setSelectedSchema(e.target.value); + const selectedSchemaObj = options.find( + // @ts-ignore + (schema) => schema.file === e.target.value, + ); + + if (selectedSchemaObj) { + // @ts-ignore + setInstances(selectedSchemaObj.instances); + const schemaResponse = await fetch(selectedSchema); + const schemaData = await schemaResponse.json(); + setFetchedSchema(schemaData); + } else { + setInstances([]); + setFetchedSchema(null!); + } + }; + + const handleInstanceChange = async (e: any) => { + setSelectedInstance(e.target.value); + + const instanceResponse = await fetch(selectedInstance); + const instanceData = await instanceResponse.json(); + setFetchedInstance(instanceData); + }; + + return ( + <> +
+
+

JSON Schema

+ +
+ +
+ { + const isHighlighted = false; + return { + className: `${isHighlighted ? 'bg-code-editor-dark-highlight block ml-10 w-full' : ''} pr-8`, + }; + }} + codeTagProps={{ + className: 'mr-8', + }} + > + {JSON.stringify(fetchedSchema, null, 2)} + +
+
+ +
+
+

JSON Instance

+ +
+
+ { + const isHighlighted = false; + return { + className: `${isHighlighted ? 'bg-code-editor-dark-highlight block ml-10 w-full' : ''} pr-8`, + }; + }} + codeTagProps={{ + className: 'mr-8', + }} + > + {JSON.stringify(fetchedInstance, null, 2)}{' '} + +
+
+ + ); +}; + +export default GettingStarted; diff --git a/pages/learn/getting-started-step-by-step/index.page.tsx b/pages/learn/getting-started-step-by-step/index.page.tsx index 7b26f42fd..7ea5face8 100644 --- a/pages/learn/getting-started-step-by-step/index.page.tsx +++ b/pages/learn/getting-started-step-by-step/index.page.tsx @@ -1,6 +1,5 @@ -import React, { useState, useEffect } from 'react'; +import React from 'react'; import fs from 'fs'; -import { atomOneDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; import { getLayout } from '~/components/Sidebar'; import Head from 'next/head'; @@ -9,7 +8,7 @@ import matter from 'gray-matter'; import StyledMarkdown from '~/components/StyledMarkdown'; import { SectionContext } from '~/context'; import { DocsHelp } from '~/components/DocsHelp'; -import Highlight from 'react-syntax-highlighter'; +import GettingStarted from '~/components/GettingStarted'; export async function getStaticProps() { const block1 = fs.readFileSync( @@ -24,113 +23,9 @@ export async function getStaticProps() { }; } -async function fetchData() { - const response = await fetch('/getting-started-examples.json'); - const data = await response.json(); - return data; -} - export default function StyledValidator({ blocks }: { blocks: any[] }) { const newTitle = 'Creating your first schema'; - const intitalSchemaData = { - $schema: 'https://json-schema.org/draft/2020-12/schema', - $id: 'https://example.com/product.schema.json', - title: 'Product', - description: 'A product from Acmes catalog', - type: 'object', - properties: { - productId: { - description: 'The unique identifier for a product', - type: 'integer', - }, - productName: { - description: 'Name of the product', - type: 'string', - }, - price: { - description: 'The price of the product', - type: 'number', - exclusiveMinimum: 0, - }, - tags: { - description: 'Tags for the product', - type: 'array', - items: { - type: 'string', - }, - minItems: 1, - uniqueItems: true, - }, - dimensions: { - type: 'object', - properties: { - length: { - type: 'number', - }, - width: { - type: 'number', - }, - height: { - type: 'number', - }, - }, - required: ['length', 'width', 'height'], - }, - warehouseLocation: { - description: - 'Coordinates of the warehouse where the product is located.', - $ref: 'https://example.com/geographical-location.schema.json', - }, - }, - required: ['productId', 'productName', 'price'], - }; - - const [options, setOptions] = useState([]); - const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); - const [selectedSchema, setSelectedSchema] = useState( - '/getting-started-examples/schemas/default.json', - ); - const [instances, setInstances] = useState([ - { - name: 'Valid instance', - default: true, - valid: true, - file: '/getting-started-examples/instances/default-ok.json', - details: 'This is a valid JSON instance for the provided JSON Schema', - }, - { - name: 'Invalid instance', - default: false, - valid: false, - file: '/getting-started-examples/instances/default-ko.json', - details: 'This is an invalid JSON instance for the provided JSON Schema', - }, - ]); - - useEffect(() => { - fetchData().then((data) => setOptions(data)); - }, []); - - const handleChange = async (e: any) => { - setSelectedSchema(e.target.value); - const selectedSchemaObj = options.find( - // @ts-ignore - (schema) => schema.file === e.target.value, - ); - - if (selectedSchemaObj) { - // @ts-ignore - setInstances(selectedSchemaObj.instances); - const schemaResponse = await fetch(selectedSchema); - const schemaData = await schemaResponse.json(); - setFetchedSchema(schemaData); - } else { - setInstances([]); - setFetchedSchema(null!); - } - }; - return ( @@ -138,73 +33,7 @@ export default function StyledValidator({ blocks }: { blocks: any[] }) { {newTitle} - -
-
-

JSON Schema

- -
- -
- { - const isHighlighted = false; - return { - className: `${isHighlighted ? 'bg-code-editor-dark-highlight block ml-10 w-full' : ''} pr-8`, - }; - }} - codeTagProps={{ - className: 'mr-8', - }} - > - {JSON.stringify(fetchedSchema, null, 2)} - -
-
- -
-
-

JSON Instance

- -
-
-
- +
); From 8b01252b63fb2498ad659a2c76b82e4e14018a2b Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Fri, 7 Jun 2024 21:31:31 +0530 Subject: [PATCH 16/26] fix: state rendering problem solved --- components/GettingStarted.tsx | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index 42c47074b..fc835b4d9 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -63,10 +63,6 @@ const GettingStarted = () => { }; const [options, setOptions] = useState([]); - const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); - const [selectedSchema, setSelectedSchema] = useState( - '/getting-started-examples/schemas/default.json', - ); const [instances, setInstances] = useState([ { name: 'Valid instance', @@ -84,17 +80,14 @@ const GettingStarted = () => { }, ]); - const [selectedInstance, setSelectedInstance] = useState( - '/getting-started-examples/instances/default-ok.json', - ); + const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); const [fetchedInstance, setFetchedInstance] = useState({}); useEffect(() => { fetchData().then((data) => setOptions(data)); }, []); - const handleChange = async (e: any) => { - setSelectedSchema(e.target.value); + const handleSchemaChange = async (e: any) => { const selectedSchemaObj = options.find( // @ts-ignore (schema) => schema.file === e.target.value, @@ -103,7 +96,7 @@ const GettingStarted = () => { if (selectedSchemaObj) { // @ts-ignore setInstances(selectedSchemaObj.instances); - const schemaResponse = await fetch(selectedSchema); + const schemaResponse = await fetch(e.target.value); const schemaData = await schemaResponse.json(); setFetchedSchema(schemaData); } else { @@ -113,9 +106,7 @@ const GettingStarted = () => { }; const handleInstanceChange = async (e: any) => { - setSelectedInstance(e.target.value); - - const instanceResponse = await fetch(selectedInstance); + const instanceResponse = await fetch(e.target.value); const instanceData = await instanceResponse.json(); setFetchedInstance(instanceData); }; @@ -129,7 +120,7 @@ const GettingStarted = () => { name='Select a JSON Schema Validator' className='p-2 border dark:border-slate-300 border-slate-800 dark:bg-slate-900 rounded-md max-sm:text-[12px]' id='Examples' - onChange={handleChange} + onChange={handleSchemaChange} > {options.map((option: any, id: number) => (
From 24293fe5c9fab506ccbd82321769ed0dcd146766 Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Fri, 7 Jun 2024 23:37:09 +0530 Subject: [PATCH 17/26] feat:adding text and icons --- components/GettingStarted.tsx | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index fc835b4d9..36819ea6d 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -79,7 +79,10 @@ const GettingStarted = () => { details: 'This is an invalid JSON instance for the provided JSON Schema', }, ]); - + const [details, setDetails] = useState([ + 'This is a valid JSON instance for the provided JSON Schema', + true, + ]); const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); const [fetchedInstance, setFetchedInstance] = useState({}); @@ -88,14 +91,14 @@ const GettingStarted = () => { }, []); const handleSchemaChange = async (e: any) => { - const selectedSchemaObj = options.find( + const selectedSchema = options.find( // @ts-ignore (schema) => schema.file === e.target.value, ); - if (selectedSchemaObj) { + if (selectedSchema) { // @ts-ignore - setInstances(selectedSchemaObj.instances); + setInstances(selectedSchema.instances); const schemaResponse = await fetch(e.target.value); const schemaData = await schemaResponse.json(); setFetchedSchema(schemaData); @@ -106,9 +109,16 @@ const GettingStarted = () => { }; const handleInstanceChange = async (e: any) => { - const instanceResponse = await fetch(e.target.value); - const instanceData = await instanceResponse.json(); - setFetchedInstance(instanceData); + const selectedInstance = instances.find( + (instance) => instance.file === e.target.value, + ); + + if (selectedInstance) { + setDetails([selectedInstance.details, selectedInstance.valid]); + const instanceResponse = await fetch(e.target.value); + const instanceData = await instanceResponse.json(); + setFetchedInstance(instanceData); + } }; return ( @@ -210,6 +220,16 @@ const GettingStarted = () => { {JSON.stringify(fetchedInstance, null, 2)} +

Instance Result

+
+

{details[0]}

+ + {details[1] ? ( + green tick + ) : ( + red cross + )} +
); From a60d761b5b88e099a98cba41edb4b67a3f35ed8d Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Tue, 18 Jun 2024 23:31:21 +0530 Subject: [PATCH 18/26] fix: instances fix --- components/GettingStarted.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index 36819ea6d..892a83a49 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -84,7 +84,7 @@ const GettingStarted = () => { true, ]); const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); - const [fetchedInstance, setFetchedInstance] = useState({}); + const [fetchedInstance, setFetchedInstance] = useState(instances[0]); useEffect(() => { fetchData().then((data) => setOptions(data)); @@ -118,6 +118,8 @@ const GettingStarted = () => { const instanceResponse = await fetch(e.target.value); const instanceData = await instanceResponse.json(); setFetchedInstance(instanceData); + } else { + setFetchedInstance(null!); } }; From 1f6040111afb86775064613766dae0ecf2ac4d6f Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Tue, 18 Jun 2024 23:53:53 +0530 Subject: [PATCH 19/26] fixing text alignment --- components/GettingStarted.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index 892a83a49..f648ecefc 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -126,7 +126,7 @@ const GettingStarted = () => { return ( <>
-
+

JSON Schema

Date: Thu, 20 Jun 2024 15:00:27 +0530 Subject: [PATCH 20/26] fix: instances fix --- components/GettingStarted.tsx | 79 ++++++++-------------------- public/getting-started-examples.json | 2 +- 2 files changed, 24 insertions(+), 57 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index f648ecefc..be04d759c 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -8,60 +8,23 @@ async function fetchData() { return data; } -const GettingStarted = () => { - const intitalSchemaData = { - $schema: 'https://json-schema.org/draft/2020-12/schema', - $id: 'https://example.com/product.schema.json', - title: 'Product', - description: 'A product from Acmes catalog', - type: 'object', - properties: { - productId: { - description: 'The unique identifier for a product', - type: 'integer', - }, - productName: { - description: 'Name of the product', - type: 'string', - }, - price: { - description: 'The price of the product', - type: 'number', - exclusiveMinimum: 0, - }, - tags: { - description: 'Tags for the product', - type: 'array', - items: { - type: 'string', - }, - minItems: 1, - uniqueItems: true, - }, - dimensions: { - type: 'object', - properties: { - length: { - type: 'number', - }, - width: { - type: 'number', - }, - height: { - type: 'number', - }, - }, - required: ['length', 'width', 'height'], - }, - warehouseLocation: { - description: - 'Coordinates of the warehouse where the product is located.', - $ref: 'https://example.com/geographical-location.schema.json', - }, - }, - required: ['productId', 'productName', 'price'], - }; +async function fetchSchemaData() { + const response = await fetch( + '/getting-started-examples/schemas/default.json', + ); + const schemaData = await response.json(); + return schemaData; +} + +async function fetchedInstanceData() { + const response = await fetch( + '/getting-started-examples/instances/default-ok.json', + ); + const schemaData = await response.json(); + return schemaData; +} +const GettingStarted = () => { const [options, setOptions] = useState([]); const [instances, setInstances] = useState([ { @@ -83,11 +46,15 @@ const GettingStarted = () => { 'This is a valid JSON instance for the provided JSON Schema', true, ]); - const [fetchedSchema, setFetchedSchema] = useState(intitalSchemaData); - const [fetchedInstance, setFetchedInstance] = useState(instances[0]); + const [fetchedSchema, setFetchedSchema] = useState(); + const [fetchedInstance, setFetchedInstance] = useState(); useEffect(() => { fetchData().then((data) => setOptions(data)); + fetchSchemaData().then((schemaData) => setFetchedSchema(schemaData)); + fetchedInstanceData().then((instanceData) => + setFetchedInstance(instanceData), + ); }, []); const handleSchemaChange = async (e: any) => { @@ -114,10 +81,10 @@ const GettingStarted = () => { ); if (selectedInstance) { - setDetails([selectedInstance.details, selectedInstance.valid]); const instanceResponse = await fetch(e.target.value); const instanceData = await instanceResponse.json(); setFetchedInstance(instanceData); + setDetails([selectedInstance.details, selectedInstance.valid]); } else { setFetchedInstance(null!); } diff --git a/public/getting-started-examples.json b/public/getting-started-examples.json index 29aad00e5..0c8b17ebf 100644 --- a/public/getting-started-examples.json +++ b/public/getting-started-examples.json @@ -30,7 +30,7 @@ "name": "Valid instance", "default": true, "valid": true, - "file": "/getting-started-examples/instances/default-extended-ok.json", + "file": "/getting-started-examples/instances/default-extended-v.json", "details": "This is a valid JSON instance for the provided JSON Schema" } ] From e7e65742d73092f8e2532b3fd5139e20a207b741 Mon Sep 17 00:00:00 2001 From: Benjamin Granados Date: Thu, 20 Jun 2024 15:08:32 +0200 Subject: [PATCH 21/26] Refactoring and improvements --- components/GettingStarted.tsx | 15 +++++---- .../getting-started-step-by-step.md | 33 +++++-------------- .../{ => data}/getting-started-examples.json | 12 +++---- .../instances/default-extended-ok.json} | 0 .../instances/default-ko.json | 0 .../instances/default-ok.json | 0 .../schemas/default-extended.json} | 2 +- .../schemas/default.json} | 0 .../instances/default.json | 16 --------- 9 files changed, 24 insertions(+), 54 deletions(-) rename public/{ => data}/getting-started-examples.json (59%) rename public/{getting-started-examples/instances/default-extended-v.json => data/getting-started-examples/instances/default-extended-ok.json} (100%) rename public/{ => data}/getting-started-examples/instances/default-ko.json (100%) rename public/{ => data}/getting-started-examples/instances/default-ok.json (100%) rename public/{getting-started-examples/schemas/default.json => data/getting-started-examples/schemas/default-extended.json} (99%) rename public/{getting-started-examples/schemas/default-extended.json => data/getting-started-examples/schemas/default.json} (100%) delete mode 100644 public/getting-started-examples/instances/default.json diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index be04d759c..26b265887 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -3,14 +3,14 @@ import { atomOneDark } from 'react-syntax-highlighter/dist/cjs/styles/hljs'; import Highlight from 'react-syntax-highlighter'; async function fetchData() { - const response = await fetch('/getting-started-examples.json'); + const response = await fetch('/data/getting-started-examples.json'); const data = await response.json(); return data; } async function fetchSchemaData() { const response = await fetch( - '/getting-started-examples/schemas/default.json', + '/data/getting-started-examples/schemas/default.json', ); const schemaData = await response.json(); return schemaData; @@ -18,7 +18,7 @@ async function fetchSchemaData() { async function fetchedInstanceData() { const response = await fetch( - '/getting-started-examples/instances/default-ok.json', + '/data/getting-started-examples/instances/default-ok.json', ); const schemaData = await response.json(); return schemaData; @@ -31,17 +31,18 @@ const GettingStarted = () => { name: 'Valid instance', default: true, valid: true, - file: '/getting-started-examples/instances/default-ok.json', + file: '/data/getting-started-examples/instances/default-ok.json', details: 'This is a valid JSON instance for the provided JSON Schema', }, { name: 'Invalid instance', default: false, valid: false, - file: '/getting-started-examples/instances/default-ko.json', + file: '/data/getting-started-examples/instances/default-ko.json', details: 'This is an invalid JSON instance for the provided JSON Schema', }, ]); + const [details, setDetails] = useState([ 'This is a valid JSON instance for the provided JSON Schema', true, @@ -94,7 +95,7 @@ const GettingStarted = () => { <>
-

JSON Schema

+

JSON Schema

[Tools](https://json-schema.org/implementations) for a current list of supported validators. +After creating your JSON Schema, you can then validate example data against your schema by using a validator in a language of your choice. Please, visit [Tools](https://json-schema.org/implementations#validators) and select the validator that better suit your needs. + +If you already know how to create JSON Schemas and you are looking for different JSON Schema use cases like schema generation, code generation, documentation, UI generation or JSON Schema processing or conversion, please visit [Tools](https://json-schema.org/implementations) and explore the amazing tooling available in the JSON Schema Ecosystem. @@ -573,28 +575,11 @@ With the external schema reference, the overall schema looks like this: ## Validate JSON data against the schema -This section describes how to validate JSON data against the product catalog schema. +Now that you have your JSON Schema is time to validate [JSON data](https://json-schema.org/learn/glossary#instance) against it using a [JSON Schema Validator](https://json-schema.org/implementations#validators). -This example JSON data matches the product catalog schema: - +A Validator is a tool that implements the JSON Schema specification. All validators works in a similar way: they take a JSON Schema and a JSON Instance as input and they returns the validation result as output. + +![How JSON Schema works](https://json-schema.org/img/json_schema.svg) - diff --git a/public/getting-started-examples.json b/public/data/getting-started-examples.json similarity index 59% rename from public/getting-started-examples.json rename to public/data/getting-started-examples.json index 0c8b17ebf..5bf4468a1 100644 --- a/public/getting-started-examples.json +++ b/public/data/getting-started-examples.json @@ -2,21 +2,21 @@ { "name": "Getting started basic schema", "default": true, - "file": "/getting-started-examples/schemas/default.json", + "file": "/data/getting-started-examples/schemas/default.json", "instances": [ { "name": "Valid instance", "default": true, "valid": true, - "file": "/getting-started-examples/instances/default-ok.json", + "file": "/data/getting-started-examples/instances/default-ok.json", "details": "This is a valid JSON instance for the provided JSON Schema" }, { "name": "Invalid instance", "default": false, "valid": false, - "file": "/getting-started-examples/instances/default-ko.json", - "details": "This is an invalid JSON instance for the provided JSON Schema" + "file": "/data/getting-started-examples/instances/default-ko.json", + "details": "Invalid: The value of 'price' property must be a number" } ] }, @@ -24,13 +24,13 @@ { "name": "Getting started extended schema", "default": false, - "file": "/getting-started-examples/schemas/default-extended.json", + "file": "/data/getting-started-examples/schemas/default-extended.json", "instances": [ { "name": "Valid instance", "default": true, "valid": true, - "file": "/getting-started-examples/instances/default-extended-v.json", + "file": "/data/getting-started-examples/instances/default-extended-ok.json", "details": "This is a valid JSON instance for the provided JSON Schema" } ] diff --git a/public/getting-started-examples/instances/default-extended-v.json b/public/data/getting-started-examples/instances/default-extended-ok.json similarity index 100% rename from public/getting-started-examples/instances/default-extended-v.json rename to public/data/getting-started-examples/instances/default-extended-ok.json diff --git a/public/getting-started-examples/instances/default-ko.json b/public/data/getting-started-examples/instances/default-ko.json similarity index 100% rename from public/getting-started-examples/instances/default-ko.json rename to public/data/getting-started-examples/instances/default-ko.json diff --git a/public/getting-started-examples/instances/default-ok.json b/public/data/getting-started-examples/instances/default-ok.json similarity index 100% rename from public/getting-started-examples/instances/default-ok.json rename to public/data/getting-started-examples/instances/default-ok.json diff --git a/public/getting-started-examples/schemas/default.json b/public/data/getting-started-examples/schemas/default-extended.json similarity index 99% rename from public/getting-started-examples/schemas/default.json rename to public/data/getting-started-examples/schemas/default-extended.json index 769c181b6..8ff9cc558 100644 --- a/public/getting-started-examples/schemas/default.json +++ b/public/data/getting-started-examples/schemas/default-extended.json @@ -48,4 +48,4 @@ } }, "required": ["productId", "productName", "price"] -} +} \ No newline at end of file diff --git a/public/getting-started-examples/schemas/default-extended.json b/public/data/getting-started-examples/schemas/default.json similarity index 100% rename from public/getting-started-examples/schemas/default-extended.json rename to public/data/getting-started-examples/schemas/default.json diff --git a/public/getting-started-examples/instances/default.json b/public/getting-started-examples/instances/default.json deleted file mode 100644 index d09d10536..000000000 --- a/public/getting-started-examples/instances/default.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "productId": 1, - "productName": "An ice sculpture", - "price": 12.50, - "tags": [ "cold", "ice" ], - "dimensions": { - "length": 7.0, - "width": 12.0, - "height": 9.5 - }, - "warehouseLocation": { - "latitude": -78.75, - "longitude": 20.4 - } - } - \ No newline at end of file From 8de746cbb5deea615646cd30633302098e750d2c Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Thu, 20 Jun 2024 21:25:54 +0530 Subject: [PATCH 22/26] removing some codes --- components/GettingStarted.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index 26b265887..cb88fcbff 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -44,8 +44,8 @@ const GettingStarted = () => { ]); const [details, setDetails] = useState([ - 'This is a valid JSON instance for the provided JSON Schema', - true, + instances[0].details, + instances[0].valid, ]); const [fetchedSchema, setFetchedSchema] = useState(); const [fetchedInstance, setFetchedInstance] = useState(); From e7bc1be01a3412c231615a9ed2603492c284c8fa Mon Sep 17 00:00:00 2001 From: Dhairya Majmudar <2022kuec2045@iiitkota.ac.in> Date: Sat, 22 Jun 2024 20:30:48 +0530 Subject: [PATCH 23/26] Refactoring component and bug fixes --- components/GettingStarted.tsx | 101 ++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index cb88fcbff..b51aaea67 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -5,78 +5,85 @@ import Highlight from 'react-syntax-highlighter'; async function fetchData() { const response = await fetch('/data/getting-started-examples.json'); const data = await response.json(); - return data; -} -async function fetchSchemaData() { - const response = await fetch( - '/data/getting-started-examples/schemas/default.json', + const defaultSchemaData = data.find((data: any) => data.default === true); + + const schemaResp = await fetch(defaultSchemaData.file); + const schemaData = await schemaResp.json(); + + const defaultInstanceData = defaultSchemaData.instances.find( + (instance: any) => instance.default === true, ); - const schemaData = await response.json(); - return schemaData; + + console.log(defaultInstanceData); + + const instanceResp = await fetch(defaultInstanceData.file); + const instanceData = await instanceResp.json(); + + return { + data, + schemaData, + instanceData, + initialInstance: defaultSchemaData.instances, + initialDetails: [defaultInstanceData.details, defaultInstanceData.valid], + }; +} +interface SchemaOption { + file: string; + instances: InstanceOption[]; } -async function fetchedInstanceData() { - const response = await fetch( - '/data/getting-started-examples/instances/default-ok.json', - ); - const schemaData = await response.json(); - return schemaData; +interface InstanceOption { + file: string; + details: string; + valid: string; } const GettingStarted = () => { - const [options, setOptions] = useState([]); - const [instances, setInstances] = useState([ - { - name: 'Valid instance', - default: true, - valid: true, - file: '/data/getting-started-examples/instances/default-ok.json', - details: 'This is a valid JSON instance for the provided JSON Schema', - }, - { - name: 'Invalid instance', - default: false, - valid: false, - file: '/data/getting-started-examples/instances/default-ko.json', - details: 'This is an invalid JSON instance for the provided JSON Schema', - }, - ]); - - const [details, setDetails] = useState([ - instances[0].details, - instances[0].valid, - ]); - const [fetchedSchema, setFetchedSchema] = useState(); - const [fetchedInstance, setFetchedInstance] = useState(); - useEffect(() => { - fetchData().then((data) => setOptions(data)); - fetchSchemaData().then((schemaData) => setFetchedSchema(schemaData)); - fetchedInstanceData().then((instanceData) => - setFetchedInstance(instanceData), + fetchData().then( + ({ data, schemaData, instanceData, initialInstance, initialDetails }) => { + setOptions(data); + setFetchedSchema(schemaData); + setFetchedInstance(instanceData); + setInstances(initialInstance); + setDetails(initialDetails); + }, ); }, []); - const handleSchemaChange = async (e: any) => { + const [options, setOptions] = useState([]); + const [instances, setInstances] = useState([]); + const [details, setDetails] = useState(['', '']); + + const [fetchedSchema, setFetchedSchema] = useState(); + const [fetchedInstance, setFetchedInstance] = useState(); + + const handleSchemaChange = async ( + e: React.ChangeEvent, + ) => { const selectedSchema = options.find( - // @ts-ignore (schema) => schema.file === e.target.value, ); if (selectedSchema) { - // @ts-ignore - setInstances(selectedSchema.instances); const schemaResponse = await fetch(e.target.value); const schemaData = await schemaResponse.json(); setFetchedSchema(schemaData); + setInstances(selectedSchema.instances); + + const instResp = await fetch(selectedSchema.instances[0].file); + const instData = await instResp.json(); + setFetchedInstance(instData); } else { setInstances([]); setFetchedSchema(null!); } }; - const handleInstanceChange = async (e: any) => { + const handleInstanceChange = async ( + e: React.ChangeEvent, + ) => { const selectedInstance = instances.find( (instance) => instance.file === e.target.value, ); From 1aa7b3dcac5d6ddb5707d58ae6ca1b5b872aed4b Mon Sep 17 00:00:00 2001 From: Benjamin Granados Date: Mon, 24 Jun 2024 23:41:11 +0200 Subject: [PATCH 24/26] Add plausible events --- components/GettingStarted.tsx | 6 +++--- package.json | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index b51aaea67..624d707f6 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -105,7 +105,7 @@ const GettingStarted = () => {

JSON Schema

@@ -197,7 +197,7 @@ const GettingStarted = () => { {JSON.stringify(fetchedInstance, null, 2)}
-

Instance Result

+

Validation Result

{details[0]}

diff --git a/package.json b/package.json index 8bc896efe..98fe3f426 100644 --- a/package.json +++ b/package.json @@ -71,5 +71,6 @@ "prettier": "3.2.5", "tailwindcss": "^3.3.5", "typescript": "5.2.2" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } From 7979703aec7c554c9ec897eed94b84113e76053a Mon Sep 17 00:00:00 2001 From: Benjamin Granados Date: Mon, 24 Jun 2024 23:42:13 +0200 Subject: [PATCH 25/26] Update package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 98fe3f426..8bc896efe 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,5 @@ "prettier": "3.2.5", "tailwindcss": "^3.3.5", "typescript": "5.2.2" - }, - "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" + } } From 8345cd3554abd7e00081611522f0b3341847f882 Mon Sep 17 00:00:00 2001 From: Benjamin Granados Date: Tue, 25 Jun 2024 00:23:51 +0200 Subject: [PATCH 26/26] adding better messaging --- components/GettingStarted.tsx | 58 ++++++++++--------- .../index.page.tsx | 8 ++- .../next-steps.md | 12 ++++ 3 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 pages/learn/getting-started-step-by-step/next-steps.md diff --git a/components/GettingStarted.tsx b/components/GettingStarted.tsx index 624d707f6..2a4725aab 100644 --- a/components/GettingStarted.tsx +++ b/components/GettingStarted.tsx @@ -102,19 +102,22 @@ const GettingStarted = () => { <>
-

JSON Schema

- +

JSON Schema

+
+ + +
@@ -152,19 +155,22 @@ const GettingStarted = () => {
-

JSON Instance

- +

JSON Instance

+
+ + +
{newTitle} + ); diff --git a/pages/learn/getting-started-step-by-step/next-steps.md b/pages/learn/getting-started-step-by-step/next-steps.md new file mode 100644 index 000000000..a986de19d --- /dev/null +++ b/pages/learn/getting-started-step-by-step/next-steps.md @@ -0,0 +1,12 @@ +--- +title: Getting Started Next Steps +section: docs +--- + +## What Next? + +Now that you know how to create a JSON Schema and use it to validate JSON data, we'd invite you to continue your JSON Schema journey: +* Learn more about JSON Schema by visiting the [reference documentation](../understanding-json-schema). +* Explore the details of the current version of the Spec [2020-12](https://json-schema.org/specification). + +If you already know how to create JSON Schemas and you are looking for different JSON Schema use cases like schema generation, code generation, documentation, UI generation or JSON Schema processing or conversion, please visit [Tools](https://json-schema.org/implementations) and explore the amazing tooling available in the JSON Schema Ecosystem. \ No newline at end of file