Skip to content

Commit f127d28

Browse files
authored
Rename OpenAPIModels to OpenAPISchemas (#2946)
1 parent 65c1bdc commit f127d28

File tree

10 files changed

+55
-49
lines changed

10 files changed

+55
-49
lines changed

.changeset/healthy-paws-flash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
'gitbook': patch
4+
---
5+
6+
Rename OpenAPIModels to OpenAPISchemas

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@apply flex-1 flex flex-col gap-4 mb-14;
44
}
55

6-
.openapi-models {
6+
.openapi-schemas {
77
@apply flex flex-col mb-14 flex-1;
88
}
99

@@ -620,10 +620,10 @@
620620
@apply space-y-2.5;
621621
}
622622

623-
.openapi-section-models {
623+
.openapi-section-schemas {
624624
@apply border border-tint-subtle rounded-lg;
625625
}
626626

627-
.openapi-section-models > .openapi-section-body > .openapi-schema-properties > .openapi-schema {
627+
.openapi-section-schemas > .openapi-section-body > .openapi-schema-properties > .openapi-schema {
628628
@apply p-2.5;
629629
}

packages/gitbook/src/lib/openapi/resolveOpenAPIModelsBlock.ts renamed to packages/gitbook/src/lib/openapi/resolveOpenAPISchemasBlock.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch';
22
import type { ResolveOpenAPIBlockResult } from '@/lib/openapi/types';
33
import { OpenAPIParseError } from '@gitbook/openapi-parser';
4-
import { type OpenAPIModelsData, resolveOpenAPIModels } from '@gitbook/react-openapi';
4+
import { type OpenAPISchemasData, resolveOpenAPISchemas } from '@gitbook/react-openapi';
55
import type { AnyOpenAPIBlock, ResolveOpenAPIBlockArgs } from './types';
66

7-
type ResolveOpenAPIModelsBlockResult = ResolveOpenAPIBlockResult<OpenAPIModelsData>;
7+
type ResolveOpenAPISchemasBlockResult = ResolveOpenAPIBlockResult<OpenAPISchemasData>;
88

9-
const weakmap = new WeakMap<AnyOpenAPIBlock, Promise<ResolveOpenAPIModelsBlockResult>>();
9+
const weakmap = new WeakMap<AnyOpenAPIBlock, Promise<ResolveOpenAPISchemasBlockResult>>();
1010

1111
/**
1212
* Cache the result of resolving an OpenAPI block.
1313
* It is important because the resolve is called in sections and in the block itself.
1414
*/
15-
export function resolveOpenAPIModelsBlock(
15+
export function resolveOpenAPISchemasBlock(
1616
args: ResolveOpenAPIBlockArgs
17-
): Promise<ResolveOpenAPIModelsBlockResult> {
17+
): Promise<ResolveOpenAPISchemasBlockResult> {
1818
if (weakmap.has(args.block)) {
1919
return weakmap.get(args.block)!;
2020
}
2121

22-
const result = baseResolveOpenAPIModelsBlock(args);
22+
const result = baseResolveOpenAPISchemasBlock(args);
2323
weakmap.set(args.block, result);
2424
return result;
2525
}
2626

2727
/**
28-
* Resolve OpenAPI models block.
28+
* Resolve OpenAPI schemas block.
2929
*/
30-
async function baseResolveOpenAPIModelsBlock(
30+
async function baseResolveOpenAPISchemasBlock(
3131
args: ResolveOpenAPIBlockArgs
32-
): Promise<ResolveOpenAPIModelsBlockResult> {
32+
): Promise<ResolveOpenAPISchemasBlockResult> {
3333
const { context, block } = args;
3434
if (!block.data.path || !block.data.method) {
3535
return { data: null, specUrl: null };
@@ -42,7 +42,7 @@ async function baseResolveOpenAPIModelsBlock(
4242
return { data: null, specUrl: null };
4343
}
4444

45-
const data = await resolveOpenAPIModels(filesystem);
45+
const data = await resolveOpenAPISchemas(filesystem);
4646

4747
return { data, specUrl };
4848
} catch (error) {

packages/gitbook/src/lib/openapi/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DocumentBlockOpenAPI, DocumentBlockOpenAPIOperation } from '@gitbo
22
import type { Filesystem, OpenAPIParseError, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
33
import type { GitBookAnyContext } from '@v2/lib/context';
44

5-
//!!TODO: Add DocumentBlockOpenAPIModels when available in @gitbook/api
5+
//!!TODO: Add DocumentBlockOpenAPISchemas when available in @gitbook/api
66
export type AnyOpenAPIBlock = DocumentBlockOpenAPI | DocumentBlockOpenAPIOperation;
77

88
/**

packages/react-openapi/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from './models';
1+
export * from './schemas';
22
export * from './OpenAPIOperation';
33
export * from './OpenAPIOperationContext';
44
export * from './resolveOpenAPIOperation';
5-
export type { OpenAPIModelsData, OpenAPIOperationData } from './types';
5+
export type { OpenAPISchemasData, OpenAPIOperationData } from './types';

packages/react-openapi/src/models/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/react-openapi/src/models/OpenAPIModels.tsx renamed to packages/react-openapi/src/schemas/OpenAPISchemas.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,49 @@ import clsx from 'clsx';
22
import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
33
import { OpenAPIRootSchema } from '../OpenAPISchema';
44
import { Section, SectionBody } from '../StaticSection';
5-
import type { OpenAPIClientContext, OpenAPIContextProps, OpenAPIModelsData } from '../types';
5+
import type { OpenAPIClientContext, OpenAPIContextProps, OpenAPISchemasData } from '../types';
66

77
/**
8-
* Display OpenAPI Models.
8+
* Display OpenAPI Schemas.
99
*/
10-
export function OpenAPIModels(props: {
10+
export function OpenAPISchemas(props: {
1111
className?: string;
12-
data: OpenAPIModelsData;
12+
data: OpenAPISchemasData;
1313
context: OpenAPIContextProps;
1414
}) {
1515
const { className, data, context } = props;
16-
const { models } = data;
16+
const { schemas } = data;
1717

1818
const clientContext: OpenAPIClientContext = {
1919
defaultInteractiveOpened: context.defaultInteractiveOpened,
2020
icons: context.icons,
2121
blockKey: context.blockKey,
2222
};
2323

24-
if (!models.length) {
24+
if (!schemas.length) {
2525
return null;
2626
}
2727

2828
return (
29-
<div className={clsx('openapi-models', className)}>
30-
<OpenAPIRootModelsSchema models={models} context={clientContext} />
29+
<div className={clsx('openapi-schemas', className)}>
30+
<OpenAPIRootSchemasSchema schemas={schemas} context={clientContext} />
3131
</div>
3232
);
3333
}
3434

3535
/**
36-
* Root schema for OpenAPI models.
37-
* It displays a single model or a disclosure group for multiple models.
36+
* Root schema for OpenAPI schemas.
37+
* It displays a single model or a disclosure group for multiple schemas.
3838
*/
39-
function OpenAPIRootModelsSchema(props: {
40-
models: OpenAPIModelsData['models'];
39+
function OpenAPIRootSchemasSchema(props: {
40+
schemas: OpenAPISchemasData['schemas'];
4141
context: OpenAPIClientContext;
4242
}) {
43-
const { models, context } = props;
43+
const { schemas, context } = props;
4444

4545
// If there is only one model, we show it directly.
46-
if (models.length === 1) {
47-
const schema = models?.[0]?.schema;
46+
if (schemas.length === 1) {
47+
const schema = schemas?.[0]?.schema;
4848

4949
if (!schema) {
5050
return null;
@@ -59,12 +59,12 @@ function OpenAPIRootModelsSchema(props: {
5959
);
6060
}
6161

62-
// If there are multiple models, we use a disclosure group to show them all.
62+
// If there are multiple schemas, we use a disclosure group to show them all.
6363
return (
6464
<OpenAPIDisclosureGroup
6565
allowsMultipleExpanded
6666
icon={context.icons.chevronRight}
67-
groups={models.map(({ name, schema }) => ({
67+
groups={schemas.map(({ name, schema }) => ({
6868
id: name,
6969
label: (
7070
<div className="openapi-response-tab-content" key={`model-${name}`}>
@@ -75,7 +75,7 @@ function OpenAPIRootModelsSchema(props: {
7575
{
7676
id: 'model',
7777
body: (
78-
<Section className="openapi-section-models">
78+
<Section className="openapi-section-schemas">
7979
<SectionBody>
8080
<OpenAPIRootSchema schema={schema} context={context} />
8181
</SectionBody>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './OpenAPISchemas';
2+
export * from './resolveOpenAPISchemas';

packages/react-openapi/src/models/resolveOpenAPIModels.ts renamed to packages/react-openapi/src/schemas/resolveOpenAPISchemas.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ import {
66
shouldIgnoreEntity,
77
} from '@gitbook/openapi-parser';
88
import { dereferenceFilesystem } from '../dereference';
9-
import type { OpenAPIModel, OpenAPIModelsData } from '../types';
9+
import type { OpenAPISchema, OpenAPISchemasData } from '../types';
1010

11-
//!!TODO: We should return only the models that are used in the block. Still a WIP awaiting future work.
11+
//!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
1212

1313
/**
14-
* Resolve an OpenAPI models from a file and compile it to a more usable format.
15-
* Models are extracted from the OpenAPI components.schemas
14+
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
15+
* Schemas are extracted from the OpenAPI components.schemas
1616
*/
17-
export async function resolveOpenAPIModels(
17+
export async function resolveOpenAPISchemas(
1818
filesystem: Filesystem<OpenAPIV3xDocument>
19-
): Promise<OpenAPIModelsData | null> {
19+
): Promise<OpenAPISchemasData | null> {
2020
const schema = await dereferenceFilesystem(filesystem);
2121

22-
const models = getOpenAPIComponents(schema);
22+
const schemas = getOpenAPIComponents(schema);
2323

24-
return { models };
24+
return { schemas };
2525
}
2626

2727
/**
2828
* Get OpenAPI components.schemas that are not ignored.
2929
*/
30-
function getOpenAPIComponents(schema: OpenAPIV3.Document | OpenAPIV3_1.Document): OpenAPIModel[] {
30+
function getOpenAPIComponents(schema: OpenAPIV3.Document | OpenAPIV3_1.Document): OpenAPISchema[] {
3131
const schemas = schema.components?.schemas ?? {};
3232
return Object.entries(schemas)
3333
.filter(([, schema]) => !shouldIgnoreEntity(schema))

packages/react-openapi/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
5656
securities: [string, OpenAPIV3.SecuritySchemeObject][];
5757
}
5858

59-
export type OpenAPIModel = {
59+
export type OpenAPISchema = {
6060
name: string;
6161
schema: OpenAPIV3.SchemaObject;
6262
};
6363

64-
export interface OpenAPIModelsData {
65-
/** Components schemas to be used for models */
66-
models: OpenAPIModel[];
64+
export interface OpenAPISchemasData {
65+
/** Components schemas to be used for schemas */
66+
schemas: OpenAPISchema[];
6767
}

0 commit comments

Comments
 (0)