@gitbook/react-openapi 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -91
- package/dist/OpenAPICodeSample.jsx +27 -2
- package/dist/OpenAPICopyButton.d.ts +4 -0
- package/dist/OpenAPICopyButton.jsx +32 -0
- package/dist/OpenAPIOperation.jsx +1 -1
- package/dist/OpenAPIPath.d.ts +1 -2
- package/dist/OpenAPIPath.jsx +32 -30
- package/dist/OpenAPIResponseExample.jsx +5 -8
- package/dist/OpenAPISchemaName.jsx +1 -0
- package/dist/OpenAPITabs.d.ts +1 -1
- package/dist/OpenAPITabs.jsx +9 -2
- package/dist/ScalarApiButton.jsx +2 -2
- package/dist/schemas/OpenAPISchemas.d.ts +3 -1
- package/dist/schemas/resolveOpenAPISchemas.d.ts +9 -3
- package/dist/schemas/resolveOpenAPISchemas.js +24 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/OpenAPICodeSample.tsx +38 -2
- package/src/OpenAPICopyButton.tsx +54 -0
- package/src/OpenAPIOperation.tsx +1 -1
- package/src/OpenAPIPath.tsx +40 -42
- package/src/OpenAPIResponseExample.tsx +30 -33
- package/src/OpenAPISchemaName.tsx +1 -0
- package/src/OpenAPITabs.tsx +13 -4
- package/src/ScalarApiButton.tsx +2 -2
- package/src/schemas/OpenAPISchemas.tsx +6 -1
- package/src/schemas/resolveOpenAPISchemas.test.ts +174 -0
- package/src/schemas/resolveOpenAPISchemas.ts +31 -9
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { type Filesystem, type OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
|
2
|
-
import type { OpenAPISchemasData } from '../types';
|
|
1
|
+
import { type Filesystem, type OpenAPIV3, type OpenAPIV3_1, type OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
|
2
|
+
import type { OpenAPISchema, OpenAPISchemasData } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
|
|
5
5
|
* Schemas are extracted from the OpenAPI components.schemas
|
|
6
6
|
*/
|
|
7
|
-
export declare function resolveOpenAPISchemas(filesystem: Filesystem<OpenAPIV3xDocument
|
|
7
|
+
export declare function resolveOpenAPISchemas(filesystem: Filesystem<OpenAPIV3xDocument>, options: {
|
|
8
|
+
schemas: string[];
|
|
9
|
+
}): Promise<OpenAPISchemasData | null>;
|
|
10
|
+
/**
|
|
11
|
+
* Extract selected schemas from the OpenAPI document.
|
|
12
|
+
*/
|
|
13
|
+
export declare function filterSelectedOpenAPISchemas(schema: OpenAPIV3.Document | OpenAPIV3_1.Document, selectedSchemas: string[]): OpenAPISchema[];
|
|
@@ -41,33 +41,42 @@ import { dereferenceFilesystem } from '../dereference';
|
|
|
41
41
|
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
|
|
42
42
|
* Schemas are extracted from the OpenAPI components.schemas
|
|
43
43
|
*/
|
|
44
|
-
export function resolveOpenAPISchemas(filesystem) {
|
|
44
|
+
export function resolveOpenAPISchemas(filesystem, options) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var schema, schemas;
|
|
46
|
+
var selectedSchemas, schema, schemas;
|
|
47
47
|
return __generator(this, function (_a) {
|
|
48
48
|
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
49
|
+
case 0:
|
|
50
|
+
selectedSchemas = options.schemas;
|
|
51
|
+
return [4 /*yield*/, dereferenceFilesystem(filesystem)];
|
|
50
52
|
case 1:
|
|
51
53
|
schema = _a.sent();
|
|
52
|
-
schemas =
|
|
54
|
+
schemas = filterSelectedOpenAPISchemas(schema, selectedSchemas);
|
|
55
|
+
if (schemas.length === 0) {
|
|
56
|
+
return [2 /*return*/, null];
|
|
57
|
+
}
|
|
53
58
|
return [2 /*return*/, { schemas: schemas }];
|
|
54
59
|
}
|
|
55
60
|
});
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
|
-
*
|
|
64
|
+
* Extract selected schemas from the OpenAPI document.
|
|
60
65
|
*/
|
|
61
|
-
function
|
|
66
|
+
export function filterSelectedOpenAPISchemas(schema, selectedSchemas) {
|
|
62
67
|
var _a, _b;
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
var componentsSchemas = (_b = (_a = schema.components) === null || _a === void 0 ? void 0 : _a.schemas) !== null && _b !== void 0 ? _b : {};
|
|
69
|
+
// Preserve the order of the selected schemas
|
|
70
|
+
return selectedSchemas
|
|
71
|
+
.map(function (name) {
|
|
72
|
+
var schema = componentsSchemas[name];
|
|
73
|
+
if (schema && !shouldIgnoreEntity(schema)) {
|
|
74
|
+
return {
|
|
75
|
+
name: name,
|
|
76
|
+
schema: schema,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
68
80
|
})
|
|
69
|
-
.
|
|
70
|
-
var key = _a[0], schema = _a[1];
|
|
71
|
-
return ({ name: key, schema: schema });
|
|
72
|
-
});
|
|
81
|
+
.filter(function (schema) { return !!schema; });
|
|
73
82
|
}
|