@gitbook/react-openapi 1.1.4 → 1.1.6
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 +21 -0
- package/dist/OpenAPICodeSample.d.ts +9 -0
- package/dist/OpenAPICodeSample.jsx +121 -41
- package/dist/OpenAPICodeSampleInteractive.d.ts +10 -0
- package/dist/OpenAPICodeSampleInteractive.jsx +78 -0
- 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 +7 -6
- package/dist/OpenAPITabs.d.ts +1 -1
- package/dist/OpenAPITabs.jsx +9 -2
- package/dist/ScalarApiButton.jsx +2 -2
- package/dist/code-samples.d.ts +1 -2
- package/dist/code-samples.js +2 -2
- package/dist/generateSchemaExample.d.ts +31 -2
- package/dist/generateSchemaExample.js +307 -24
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +11 -7
- package/package.json +3 -3
- package/src/OpenAPICodeSample.tsx +181 -51
- package/src/OpenAPICodeSampleInteractive.tsx +114 -0
- 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 +11 -6
- package/src/OpenAPITabs.tsx +13 -4
- package/src/ScalarApiButton.tsx +2 -2
- package/src/code-samples.ts +3 -3
- package/src/generateSchemaExample.ts +412 -25
- package/src/resolveOpenAPIOperation.test.ts +6 -6
- package/src/utils.ts +13 -10
|
@@ -31,8 +31,8 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
31
31
|
],
|
|
32
32
|
operation: {
|
|
33
33
|
tags: ['pet'],
|
|
34
|
-
summary: 'Update an existing pet',
|
|
35
|
-
description: 'Update an existing pet by Id',
|
|
34
|
+
summary: 'Update an existing pet.',
|
|
35
|
+
description: 'Update an existing pet by Id.',
|
|
36
36
|
requestBody: {
|
|
37
37
|
content: {
|
|
38
38
|
'application/json': {
|
|
@@ -61,8 +61,8 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
61
61
|
],
|
|
62
62
|
operation: {
|
|
63
63
|
tags: ['pet'],
|
|
64
|
-
summary: 'Update an existing pet',
|
|
65
|
-
description: 'Update an existing pet by Id',
|
|
64
|
+
summary: 'Update an existing pet.',
|
|
65
|
+
description: 'Update an existing pet by Id.',
|
|
66
66
|
requestBody: {
|
|
67
67
|
content: {
|
|
68
68
|
'application/json': {
|
|
@@ -159,8 +159,8 @@ describe('#resolveOpenAPIOperation', () => {
|
|
|
159
159
|
],
|
|
160
160
|
operation: {
|
|
161
161
|
tags: ['pet'],
|
|
162
|
-
summary: 'Update an existing pet',
|
|
163
|
-
description: 'Update an existing pet by Id',
|
|
162
|
+
summary: 'Update an existing pet.',
|
|
163
|
+
description: 'Update an existing pet by Id.',
|
|
164
164
|
requestBody: {
|
|
165
165
|
content: {
|
|
166
166
|
'application/json': {
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AnyObject, OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
|
|
2
2
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
|
3
3
|
|
|
4
|
-
export function checkIsReference(
|
|
5
|
-
input: unknown
|
|
6
|
-
): input is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
|
|
4
|
+
export function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
|
|
7
5
|
return typeof input === 'object' && !!input && '$ref' in input;
|
|
8
6
|
}
|
|
9
7
|
|
|
@@ -22,17 +20,22 @@ function hasDescription(object: AnyObject) {
|
|
|
22
20
|
* Resolve the description of an object.
|
|
23
21
|
*/
|
|
24
22
|
export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) {
|
|
25
|
-
//
|
|
23
|
+
// Resolve description from the object first
|
|
24
|
+
if (hasDescription(object)) {
|
|
25
|
+
return 'x-gitbook-description-html' in object &&
|
|
26
|
+
typeof object['x-gitbook-description-html'] === 'string'
|
|
27
|
+
? object['x-gitbook-description-html'].trim()
|
|
28
|
+
: typeof object.description === 'string'
|
|
29
|
+
? object.description.trim()
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// If the object has no description, try to resolve it from the items
|
|
26
34
|
if ('items' in object && typeof object.items === 'object' && hasDescription(object.items)) {
|
|
27
35
|
return resolveDescription(object.items);
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
return
|
|
31
|
-
typeof object['x-gitbook-description-html'] === 'string'
|
|
32
|
-
? object['x-gitbook-description-html'].trim()
|
|
33
|
-
: typeof object.description === 'string'
|
|
34
|
-
? object.description.trim()
|
|
35
|
-
: undefined;
|
|
38
|
+
return undefined;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/**
|