From 7e31f489603bfe23993753fe0d796d8435a4f8b8 Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Tue, 14 May 2024 17:29:00 +0200 Subject: [PATCH 1/8] Add support for examples in OpenAPI block --- packages/react-openapi/src/OpenAPISchema.tsx | 7 +++++++ packages/react-openapi/src/OpenAPISpec.tsx | 1 + 2 files changed, 8 insertions(+) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index 87f0ddb0b..1f820644b 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -14,6 +14,7 @@ interface OpenAPISchemaPropertyEntry { propertyName?: string; required?: boolean; schema: OpenAPIV3.SchemaObject; + example?: string; } /** @@ -92,6 +93,12 @@ export function OpenAPISchemaProperty( className="openapi-schema-description" /> ) : null} + {schema.example ? ( + + ) : null} } > diff --git a/packages/react-openapi/src/OpenAPISpec.tsx b/packages/react-openapi/src/OpenAPISpec.tsx index 7e2ab6afe..34bde07b6 100644 --- a/packages/react-openapi/src/OpenAPISpec.tsx +++ b/packages/react-openapi/src/OpenAPISpec.tsx @@ -48,6 +48,7 @@ export function OpenAPISpec(props: { rawData: any; context: OpenAPIClientContext // Description of the parameter is defined at the parameter level // we use display it if the schema doesn't override it description: parameter.description, + example: parameter.example, ...(noReference(parameter.schema) ?? {}), }, required: parameter.required, From 1345854ede5fde3783e307956b409893b89c6207 Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Wed, 15 May 2024 10:29:58 +0200 Subject: [PATCH 2/8] Fix classname --- packages/react-openapi/src/OpenAPISchema.tsx | 2 +- src/components/DocumentView/OpenAPI/style.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index 1f820644b..b2b3cfc1e 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -96,7 +96,7 @@ export function OpenAPISchemaProperty( {schema.example ? ( ) : null} diff --git a/src/components/DocumentView/OpenAPI/style.css b/src/components/DocumentView/OpenAPI/style.css index 5f618fcea..cf1b6f785 100644 --- a/src/components/DocumentView/OpenAPI/style.css +++ b/src/components/DocumentView/OpenAPI/style.css @@ -172,6 +172,10 @@ @apply prose-sm; } +.openapi-schema-example.openapi-markdown { + @apply prose-sm; +} + /** Authentication */ .openapi-securities { From af21a159bcddb0889346c407a752a8f85c6481d1 Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Wed, 15 May 2024 14:20:15 +0200 Subject: [PATCH 3/8] Implement requested changes --- packages/react-openapi/src/OpenAPISchema.tsx | 5 +---- src/components/DocumentView/OpenAPI/style.css | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index b2b3cfc1e..21c5cb8ff 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -94,10 +94,7 @@ export function OpenAPISchemaProperty( /> ) : null} {schema.example ? ( - + Example: {schema.example} ) : null} } diff --git a/src/components/DocumentView/OpenAPI/style.css b/src/components/DocumentView/OpenAPI/style.css index cf1b6f785..3ee1f65e2 100644 --- a/src/components/DocumentView/OpenAPI/style.css +++ b/src/components/DocumentView/OpenAPI/style.css @@ -172,8 +172,8 @@ @apply prose-sm; } -.openapi-schema-example.openapi-markdown { - @apply prose-sm; +.openapi-schema-example { + @apply py-2; } /** Authentication */ From ecb9e2c549b037affd0f6bd2cfbc85a0b1ac6b7c Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Wed, 15 May 2024 14:29:28 +0200 Subject: [PATCH 4/8] Use margin --- src/components/DocumentView/OpenAPI/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DocumentView/OpenAPI/style.css b/src/components/DocumentView/OpenAPI/style.css index 3ee1f65e2..4ece6c9cf 100644 --- a/src/components/DocumentView/OpenAPI/style.css +++ b/src/components/DocumentView/OpenAPI/style.css @@ -173,7 +173,7 @@ } .openapi-schema-example { - @apply py-2; + @apply mt-2; } /** Authentication */ From 678843c5469fa125cc78cf975a0e46fbb381be5d Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Tue, 21 May 2024 10:57:23 +0100 Subject: [PATCH 5/8] Use lighter black color --- src/components/DocumentView/OpenAPI/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DocumentView/OpenAPI/style.css b/src/components/DocumentView/OpenAPI/style.css index 4ece6c9cf..517739f1b 100644 --- a/src/components/DocumentView/OpenAPI/style.css +++ b/src/components/DocumentView/OpenAPI/style.css @@ -173,7 +173,7 @@ } .openapi-schema-example { - @apply mt-2; + @apply mt-2 text-base text-dark/10 dark:text-light/10; } /** Authentication */ From 7dc4b7a7a75e8a2126f12f60b3ad2afb96bc82cd Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Wed, 22 May 2024 11:49:12 +0100 Subject: [PATCH 6/8] Review --- packages/react-openapi/src/OpenAPISchema.tsx | 9 ++++++--- src/components/DocumentView/OpenAPI/style.css | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index 21c5cb8ff..f3e405b93 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -14,7 +14,6 @@ interface OpenAPISchemaPropertyEntry { propertyName?: string; required?: boolean; schema: OpenAPIV3.SchemaObject; - example?: string; } /** @@ -48,6 +47,10 @@ export function OpenAPISchemaProperty( ? null : getSchemaAlternatives(schema, new Set(circularRefs.keys())); + const shouldDisplayExample = (schema: OpenAPIV3.SchemaObject): boolean => { + schema.example; + return (typeof schema.example === 'string' || typeof schema.example === 'number' || typeof schema.example === 'boolean') + } return ( ) : null} - {schema.example ? ( - Example: {schema.example} + {shouldDisplayExample(schema) ? ( + Example: {schema.example} ) : null} } diff --git a/src/components/DocumentView/OpenAPI/style.css b/src/components/DocumentView/OpenAPI/style.css index 517739f1b..00945d644 100644 --- a/src/components/DocumentView/OpenAPI/style.css +++ b/src/components/DocumentView/OpenAPI/style.css @@ -173,7 +173,7 @@ } .openapi-schema-example { - @apply mt-2 text-base text-dark/10 dark:text-light/10; + @apply prose-sm mt-2 text-dark/10 dark:text-light/10; } /** Authentication */ From 45e34d0760a85e5d74578c9e7e12a5955fba5d8b Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Wed, 22 May 2024 11:52:55 +0100 Subject: [PATCH 7/8] Remove extra line --- packages/react-openapi/src/OpenAPISchema.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index f3e405b93..c9c9b91c7 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -48,7 +48,6 @@ export function OpenAPISchemaProperty( : getSchemaAlternatives(schema, new Set(circularRefs.keys())); const shouldDisplayExample = (schema: OpenAPIV3.SchemaObject): boolean => { - schema.example; return (typeof schema.example === 'string' || typeof schema.example === 'number' || typeof schema.example === 'boolean') } return ( From 08a289196f66c4d23d229ccea007cc0b35a5b698 Mon Sep 17 00:00:00 2001 From: Vib Bhardwaj Date: Thu, 20 Jun 2024 15:52:15 +0530 Subject: [PATCH 8/8] Handle boolean examples --- packages/react-openapi/src/OpenAPISchema.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index c9c9b91c7..6a9dfab7e 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -96,7 +96,7 @@ export function OpenAPISchemaProperty( /> ) : null} {shouldDisplayExample(schema) ? ( - Example: {schema.example} + Example: {JSON.stringify(schema.example)} ) : null} }