Skip to content

Handle grouped OpenAPISchemas #3071

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Handle grouped OpenAPISchemas
  • Loading branch information
nolannbiron committed Apr 1, 2025
commit 7af379cdd2fa33418a300782bf71632b77bbea39
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async function OpenAPISchemasBody(props: BlockProps<OpenAPISchemasBlock>) {
return (
<BaseOpenAPISchemas
data={data}
grouped={block.data.grouped}
context={{
specUrl,
icons: {
Expand Down
13 changes: 9 additions & 4 deletions packages/react-openapi/src/schemas/OpenAPISchemas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ export function OpenAPISchemas(props: {
className?: string;
data: OpenAPISchemasData;
context: OpenAPISchemasContextProps;
/**
* Whether to show the schema directly if there is only one.
*/
grouped?: boolean;
}) {
const { className, data, context } = props;
const { className, data, context, grouped } = props;
const { schemas } = data;

const clientContext: OpenAPIClientContext = {
Expand All @@ -32,7 +36,7 @@ export function OpenAPISchemas(props: {

return (
<div className={clsx('openapi-schemas', className)}>
<OpenAPIRootSchemasSchema schemas={schemas} context={clientContext} />
<OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext} />
</div>
);
}
Expand All @@ -44,11 +48,12 @@ export function OpenAPISchemas(props: {
function OpenAPIRootSchemasSchema(props: {
schemas: OpenAPISchemasData['schemas'];
context: OpenAPIClientContext;
grouped?: boolean;
}) {
const { schemas, context } = props;
const { schemas, context, grouped } = props;

// If there is only one model, we show it directly.
if (schemas.length === 1) {
if (schemas.length === 1 && !grouped) {
const schema = schemas?.[0]?.schema;

if (!schema) {
Expand Down