@gitbook/react-openapi 1.0.3 → 1.0.4

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/OpenAPICodeSample.jsx +6 -7
  3. package/dist/OpenAPIDisclosure.d.ts +2 -1
  4. package/dist/OpenAPIDisclosure.jsx +1 -1
  5. package/dist/OpenAPIDisclosureGroup.d.ts +1 -1
  6. package/dist/OpenAPIDisclosureGroup.jsx +2 -2
  7. package/dist/OpenAPIOperation.jsx +2 -2
  8. package/dist/OpenAPIPath.d.ts +3 -2
  9. package/dist/OpenAPIPath.jsx +4 -15
  10. package/dist/OpenAPIRequestBody.jsx +1 -1
  11. package/dist/OpenAPIResponse.jsx +1 -1
  12. package/dist/OpenAPIResponseExample.jsx +3 -3
  13. package/dist/OpenAPIResponses.d.ts +1 -1
  14. package/dist/OpenAPIResponses.jsx +2 -2
  15. package/dist/OpenAPISchema.d.ts +5 -1
  16. package/dist/OpenAPISchema.jsx +29 -20
  17. package/dist/OpenAPISchemaName.d.ts +4 -3
  18. package/dist/OpenAPISchemaName.jsx +1 -1
  19. package/dist/OpenAPISecurities.jsx +2 -2
  20. package/dist/OpenAPITabs.d.ts +3 -3
  21. package/dist/OpenAPITabs.jsx +11 -12
  22. package/dist/ScalarApiButton.jsx +1 -1
  23. package/dist/code-samples.js +11 -11
  24. package/dist/generateSchemaExample.js +2 -1
  25. package/dist/resolveOpenAPIOperation.d.ts +3 -3
  26. package/dist/resolveOpenAPIOperation.js +1 -1
  27. package/dist/tsconfig.build.tsbuildinfo +1 -1
  28. package/dist/util/server.d.ts +1 -1
  29. package/dist/util/server.js +1 -3
  30. package/dist/utils.d.ts +1 -1
  31. package/dist/utils.js +4 -6
  32. package/package.json +2 -7
  33. package/src/InteractiveSection.tsx +4 -4
  34. package/src/OpenAPICodeSample.tsx +9 -10
  35. package/src/OpenAPIDisclosure.tsx +4 -3
  36. package/src/OpenAPIDisclosureGroup.tsx +5 -5
  37. package/src/OpenAPIOperation.tsx +3 -3
  38. package/src/OpenAPIOperationContext.tsx +1 -1
  39. package/src/OpenAPIPath.tsx +11 -10
  40. package/src/OpenAPIRequestBody.tsx +2 -2
  41. package/src/OpenAPIResponse.tsx +3 -3
  42. package/src/OpenAPIResponseExample.tsx +5 -5
  43. package/src/OpenAPIResponses.tsx +4 -4
  44. package/src/OpenAPISchema.test.ts +5 -5
  45. package/src/OpenAPISchema.tsx +75 -25
  46. package/src/OpenAPISchemaName.tsx +5 -4
  47. package/src/OpenAPISecurities.tsx +3 -3
  48. package/src/OpenAPITabs.tsx +15 -15
  49. package/src/ScalarApiButton.tsx +3 -3
  50. package/src/code-samples.test.ts +66 -66
  51. package/src/code-samples.ts +14 -14
  52. package/src/generateSchemaExample.ts +3 -3
  53. package/src/json2xml.test.ts +1 -1
  54. package/src/resolveOpenAPIOperation.test.ts +6 -6
  55. package/src/resolveOpenAPIOperation.ts +7 -7
  56. package/src/stringifyOpenAPI.ts +1 -1
  57. package/src/util/server.test.ts +3 -3
  58. package/src/util/server.ts +2 -3
  59. package/src/utils.ts +4 -4
@@ -1,7 +1,7 @@
1
- import { it, expect, describe } from 'bun:test';
1
+ import { describe, expect, it } from 'bun:test';
2
2
 
3
- import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
4
3
  import { parseOpenAPI, traverse } from '@gitbook/openapi-parser';
4
+ import { resolveOpenAPIOperation } from './resolveOpenAPIOperation';
5
5
 
6
6
  async function fetchFilesystem(url: string) {
7
7
  const response = await fetch(url);
@@ -19,7 +19,7 @@ async function fetchFilesystem(url: string) {
19
19
  describe('#resolveOpenAPIOperation', () => {
20
20
  it('should resolve refs', async () => {
21
21
  const filesystem = await fetchFilesystem(
22
- 'https://petstore3.swagger.io/api/v3/openapi.json',
22
+ 'https://petstore3.swagger.io/api/v3/openapi.json'
23
23
  );
24
24
  const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
25
25
 
@@ -49,7 +49,7 @@ describe('#resolveOpenAPIOperation', () => {
49
49
 
50
50
  it('should support yaml', async () => {
51
51
  const filesystem = await fetchFilesystem(
52
- 'https://petstore3.swagger.io/api/v3/openapi.yaml',
52
+ 'https://petstore3.swagger.io/api/v3/openapi.yaml'
53
53
  );
54
54
  const resolved = await resolveOpenAPIOperation(filesystem, { method: 'put', path: '/pet' });
55
55
 
@@ -98,7 +98,7 @@ describe('#resolveOpenAPIOperation', () => {
98
98
 
99
99
  it('should resolve to null if the method is not supported', async () => {
100
100
  const filesystem = await fetchFilesystem(
101
- 'https://petstore3.swagger.io/api/v3/openapi.json',
101
+ 'https://petstore3.swagger.io/api/v3/openapi.json'
102
102
  );
103
103
  const resolved = await resolveOpenAPIOperation(filesystem, {
104
104
  method: 'dontexist',
@@ -144,7 +144,7 @@ describe('#resolveOpenAPIOperation', () => {
144
144
 
145
145
  it('should resolve a ref with whitespace', async () => {
146
146
  const filesystem = await fetchFilesystem(
147
- ' https://petstore3.swagger.io/api/v3/openapi.json',
147
+ ' https://petstore3.swagger.io/api/v3/openapi.json'
148
148
  );
149
149
  const resolved = await resolveOpenAPIOperation(filesystem, {
150
150
  method: 'put',
@@ -1,13 +1,13 @@
1
- import { toJSON, fromJSON } from 'flatted';
1
+ import { fromJSON, toJSON } from 'flatted';
2
2
 
3
3
  import {
4
- type OpenAPIV3xDocument,
5
4
  type Filesystem,
6
5
  type OpenAPIV3,
7
6
  type OpenAPIV3_1,
7
+ type OpenAPIV3xDocument,
8
8
  dereference,
9
9
  } from '@gitbook/openapi-parser';
10
- import { OpenAPIOperationData } from './types';
10
+ import type { OpenAPIOperationData } from './types';
11
11
  import { checkIsReference } from './utils';
12
12
 
13
13
  export { toJSON, fromJSON };
@@ -20,7 +20,7 @@ export async function resolveOpenAPIOperation(
20
20
  operationDescriptor: {
21
21
  path: string;
22
22
  method: string;
23
- },
23
+ }
24
24
  ): Promise<OpenAPIOperationData | null> {
25
25
  const { path, method } = operationDescriptor;
26
26
  const schema = await memoDereferenceFilesystem(filesystem);
@@ -102,7 +102,7 @@ async function dereferenceFilesystem(filesystem: Filesystem): Promise<OpenAPIV3x
102
102
  */
103
103
  function getPathObject(
104
104
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
105
- path: string,
105
+ path: string
106
106
  ): OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject | null {
107
107
  if (schema.paths?.[path]) {
108
108
  return schema.paths[path];
@@ -115,7 +115,7 @@ function getPathObject(
115
115
  */
116
116
  function getPathObjectParameter(
117
117
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
118
- path: string,
118
+ path: string
119
119
  ):
120
120
  | (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
121
121
  | (OpenAPIV3.ParameterObject | OpenAPIV3_1.ReferenceObject)[]
@@ -133,7 +133,7 @@ function getPathObjectParameter(
133
133
  function getOperationByPathAndMethod(
134
134
  schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
135
135
  path: string,
136
- method: string,
136
+ method: string
137
137
  ): OpenAPIV3.OperationObject | null {
138
138
  // Types are buffy for OpenAPIV3_1.OperationObject, so we use v3
139
139
  const pathObject = getPathObject(schema, path);
@@ -12,6 +12,6 @@ export function stringifyOpenAPI(body: unknown, _?: null, indent?: number): stri
12
12
 
13
13
  return value;
14
14
  },
15
- indent,
15
+ indent
16
16
  );
17
17
  }
@@ -1,6 +1,6 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { interpolateServerURL, getDefaultServerURL } from './server';
3
- import { OpenAPIV3 } from '@gitbook/openapi-parser';
1
+ import { describe, expect, it } from 'bun:test';
2
+ import type { OpenAPIV3 } from '@gitbook/openapi-parser';
3
+ import { getDefaultServerURL, interpolateServerURL } from './server';
4
4
 
5
5
  describe('#interpolateServerURL', () => {
6
6
  it('interpolates the server URL with the default values of the variables', () => {
@@ -1,4 +1,4 @@
1
- import { OpenAPIV3 } from '@gitbook/openapi-parser';
1
+ import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2
2
 
3
3
  /**
4
4
  * Get the default URL for the server.
@@ -23,9 +23,8 @@ export function interpolateServerURL(server: OpenAPIV3.ServerObject) {
23
23
  .map((part) => {
24
24
  if (part.kind === 'text') {
25
25
  return part.text;
26
- } else {
27
- return server.variables?.[part.name]?.default ?? `{${part.name}}`;
28
26
  }
27
+ return server.variables?.[part.name]?.default ?? `{${part.name}}`;
29
28
  })
30
29
  .join('');
31
30
  }
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { AnyObject, OpenAPIV3, OpenAPIV3_1 } from '@gitbook/openapi-parser';
2
2
 
3
3
  export function checkIsReference(
4
- input: unknown,
4
+ input: unknown
5
5
  ): input is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
6
6
  return typeof input === 'object' && !!input && '$ref' in input;
7
7
  }
@@ -32,7 +32,7 @@ export function resolveDescription(object: OpenAPIV3.SchemaObject | AnyObject) {
32
32
  export function extractDescriptions(object: AnyObject) {
33
33
  return {
34
34
  description: object.description,
35
- ['x-gitbook-description-html']:
35
+ 'x-gitbook-description-html':
36
36
  'x-gitbook-description-html' in object
37
37
  ? object['x-gitbook-description-html']
38
38
  : undefined,
@@ -61,7 +61,7 @@ export function resolveFirstExample(object: AnyObject) {
61
61
  * Extract the description, example and deprecated from parameter.
62
62
  */
63
63
  export function resolveParameterSchema(
64
- parameter: OpenAPIV3.ParameterBaseObject,
64
+ parameter: OpenAPIV3.ParameterBaseObject
65
65
  ): OpenAPIV3.SchemaObject {
66
66
  const schema = checkIsReference(parameter.schema) ? undefined : parameter.schema;
67
67
  return {
@@ -79,7 +79,7 @@ export function resolveParameterSchema(
79
79
  * Transform a parameter object to a property object.
80
80
  */
81
81
  export function parameterToProperty(
82
- parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject,
82
+ parameter: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject
83
83
  ): {
84
84
  propertyName: string | undefined;
85
85
  schema: OpenAPIV3.SchemaObject;