Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for examples in OpenAPI block #2314

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-openapi/src/OpenAPISchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function OpenAPISchemaProperty(
? null
: getSchemaAlternatives(schema, new Set(circularRefs.keys()));

const shouldDisplayExample = (schema: OpenAPIV3.SchemaObject): boolean => {
return (typeof schema.example === 'string' || typeof schema.example === 'number' || typeof schema.example === 'boolean')
}
return (
<InteractiveSection
id={id}
Expand Down Expand Up @@ -92,6 +95,9 @@ export function OpenAPISchemaProperty(
className="openapi-schema-description"
/>
) : null}
{shouldDisplayExample(schema) ? (
<span className="openapi-schema-example">Example: <code>{JSON.stringify(schema.example)}</code></span>
) : null}
</div>
}
>
Expand Down
1 change: 1 addition & 0 deletions packages/react-openapi/src/OpenAPISpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
vibhanshub marked this conversation as resolved.
Show resolved Hide resolved
...(noReference(parameter.schema) ?? {}),
},
required: parameter.required,
Expand Down
4 changes: 4 additions & 0 deletions src/components/DocumentView/OpenAPI/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
@apply prose-sm;
}

.openapi-schema-example {
@apply prose-sm mt-2 text-dark/10 dark:text-light/10;
}

/** Authentication */

.openapi-securities {
Expand Down
Loading