@gitbook/react-openapi 1.1.2 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -1,197 +1,211 @@
1
1
  # @gitbook/react-openapi
2
2
 
3
+ ## 1.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - c60e9ba: Handle read-only in OpenAPISchemaName
8
+ - 31d800e: Render OpenAPISchemas block
9
+ - ff3b708: Remove read-only properties from codesample
10
+
11
+ ## 1.1.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 844059f: Fix spacing in OpenAPISecurities
16
+
3
17
  ## 1.1.2
4
18
 
5
19
  ### Patch Changes
6
20
 
7
- - f127d28: Rename OpenAPIModels to OpenAPISchemas
21
+ - f127d28: Rename OpenAPIModels to OpenAPISchemas
8
22
 
9
23
  ## 1.1.1
10
24
 
11
25
  ### Patch Changes
12
26
 
13
- - f574858: Fix OpenAPI example display error
27
+ - f574858: Fix OpenAPI example display error
14
28
 
15
29
  ## 1.1.0
16
30
 
17
31
  ### Minor Changes
18
32
 
19
- - bb3ca9c: Implement OpenAPI models blocks
33
+ - bb3ca9c: Implement OpenAPI models blocks
20
34
 
21
35
  ### Patch Changes
22
36
 
23
- - 0278a14: Upgrade Scalar dependencies
24
- - 3173d8e: Remove top level circular refs in alternatives
25
- - Updated dependencies [0278a14]
26
- - Updated dependencies [bb3ca9c]
27
- - Updated dependencies [052e07a]
28
- - @gitbook/openapi-parser@2.1.0
37
+ - 0278a14: Upgrade Scalar dependencies
38
+ - 3173d8e: Remove top level circular refs in alternatives
39
+ - Updated dependencies [0278a14]
40
+ - Updated dependencies [bb3ca9c]
41
+ - Updated dependencies [052e07a]
42
+ - @gitbook/openapi-parser@2.1.0
29
43
 
30
44
  ## 1.0.5
31
45
 
32
46
  ### Patch Changes
33
47
 
34
- - Updated dependencies [53f5dbe]
35
- - @gitbook/openapi-parser@2.0.2
48
+ - Updated dependencies [53f5dbe]
49
+ - @gitbook/openapi-parser@2.0.2
36
50
 
37
51
  ## 1.0.4
38
52
 
39
53
  ### Patch Changes
40
54
 
41
- - 722f02e: Fix recursion in OpenAPISchemaAlternative
42
- - Updated dependencies [0924259]
43
- - @gitbook/openapi-parser@2.0.1
55
+ - 722f02e: Fix recursion in OpenAPISchemaAlternative
56
+ - Updated dependencies [0924259]
57
+ - @gitbook/openapi-parser@2.0.1
44
58
 
45
59
  ## 1.0.3
46
60
 
47
61
  ### Patch Changes
48
62
 
49
- - dc2dbc5: Update OpenAPI code examples to support multiple content-type
50
- - f1d1d2f: Return empty string if no server provided
51
- - 05e1d8c: Hide x-gitbook-\* symbols in OpenAPI blocks
52
- - b4a12d6: Fix circularRef in schema + examples OpenAPI
53
- - 9f0de74: Fix ID not set when there is no operation summary
54
- - da55fac: Render GitBook blocks in OpenAPI operation description
55
- - Updated dependencies [c808bb1]
56
- - Updated dependencies [e24206e]
57
- - Updated dependencies [a054554]
58
- - Updated dependencies [da55fac]
59
- - @gitbook/openapi-parser@2.0.0
63
+ - dc2dbc5: Update OpenAPI code examples to support multiple content-type
64
+ - f1d1d2f: Return empty string if no server provided
65
+ - 05e1d8c: Hide x-gitbook-\* symbols in OpenAPI blocks
66
+ - b4a12d6: Fix circularRef in schema + examples OpenAPI
67
+ - 9f0de74: Fix ID not set when there is no operation summary
68
+ - da55fac: Render GitBook blocks in OpenAPI operation description
69
+ - Updated dependencies [c808bb1]
70
+ - Updated dependencies [e24206e]
71
+ - Updated dependencies [a054554]
72
+ - Updated dependencies [da55fac]
73
+ - @gitbook/openapi-parser@2.0.0
60
74
 
61
75
  ## 1.0.2
62
76
 
63
77
  ### Patch Changes
64
78
 
65
- - bb5c6a4: Support multiple response media types and examples
66
- - a3f1fea: Fix display of OpenAPI header description
67
- - 6157583: Improve Markdown parsing
68
- - 7419ee7: Show additional fields in OpenAPI block
69
- - 82cd9f2: Add support for anchor links in OpenAPI blocks
70
- - Updated dependencies [6157583]
71
- - @gitbook/openapi-parser@1.0.1
79
+ - bb5c6a4: Support multiple response media types and examples
80
+ - a3f1fea: Fix display of OpenAPI header description
81
+ - 6157583: Improve Markdown parsing
82
+ - 7419ee7: Show additional fields in OpenAPI block
83
+ - 82cd9f2: Add support for anchor links in OpenAPI blocks
84
+ - Updated dependencies [6157583]
85
+ - @gitbook/openapi-parser@1.0.1
72
86
 
73
87
  ## 1.0.1
74
88
 
75
89
  ### Patch Changes
76
90
 
77
- - f8d4c76: Sync tabs across all OpenAPI blocks
78
- - dddb4ec: Fix long tab group description
79
- - f8d4c76: Support for OpenAPI references
91
+ - f8d4c76: Sync tabs across all OpenAPI blocks
92
+ - dddb4ec: Fix long tab group description
93
+ - f8d4c76: Support for OpenAPI references
80
94
 
81
95
  ## 1.0.0
82
96
 
83
97
  ### Major Changes
84
98
 
85
- - 727bde2: Improve and split OpenAPI parser into its own package
86
- - 12c7862: Use `@scalar/openapi-parser` to be more resilient and perf on OpenAPI spec parsing:
99
+ - 727bde2: Improve and split OpenAPI parser into its own package
100
+ - 12c7862: Use `@scalar/openapi-parser` to be more resilient and perf on OpenAPI spec parsing:
87
101
 
88
- - `fetcher.fetch` must now returns a valid OpenAPI document
89
- - `parseOpenAPIV3` has been replaced by `parseOpenAPI`
102
+ - `fetcher.fetch` must now returns a valid OpenAPI document
103
+ - `parseOpenAPIV3` has been replaced by `parseOpenAPI`
90
104
 
91
105
  ### Minor Changes
92
106
 
93
- - 162b4b7: Add in HTTP example code blocks
94
- - e4e2f52: Add an optional client context to get a callback called when the Scalar client is opened for a block.
95
- - eb7c22f: Revert scalar to 1.0.87 to mitigate an issue with ApiClientModalProvider
96
- - 160fca1: new OpenAPI blocks design
97
- - e721f17: Use `@scalar/oas-utils` getExampleFromSchema to generate OpenAPI examples
98
- - fe8acc9: Fix an issue where a missing OpenAPI example would crash the page.
99
- - 1823101: Fix internal properties appearing in OpenAPI docs.
107
+ - 162b4b7: Add in HTTP example code blocks
108
+ - e4e2f52: Add an optional client context to get a callback called when the Scalar client is opened for a block.
109
+ - eb7c22f: Revert scalar to 1.0.87 to mitigate an issue with ApiClientModalProvider
110
+ - 160fca1: new OpenAPI blocks design
111
+ - e721f17: Use `@scalar/oas-utils` getExampleFromSchema to generate OpenAPI examples
112
+ - fe8acc9: Fix an issue where a missing OpenAPI example would crash the page.
113
+ - 1823101: Fix internal properties appearing in OpenAPI docs.
100
114
 
101
115
  ### Patch Changes
102
116
 
103
- - d9029c7: Support apiKey in CodeSample security headers
104
- - 6e54a06: Support response examples
105
- - 0c03676: Better securities sample and headers
106
- - 3e5e458: Handle isArray schema type
107
- - 46edde9: Improve the OpenAPI package API
108
- - d9c8d57: Do not dereference before caching OpenAPI spec.
109
- - ccf2cff: Fix an issue where a response object using a special ref would crash the page.
110
- - dda0cc6: Flatten OpenAPI security object
111
- - f92e906: Prevent codemirror from loading multiple versions in scalar
112
- - dff08ae: Improve performances by loading Scalar API Client only when the button is clicked
113
- - fc7b16f: Updated scalar depdenency
114
- - a652958: Fix error on unresolvable refs by replacing with property name and any type
115
- - 2f73db7: Support non primitive examples in OpenAPI block
116
- - 160fca1: Support deprecated and x-deprecated-sunset in OpenAPI spec
117
- - b41d425: Improve OpenAPI rendering performances by caching markdown parsing
118
- - Updated dependencies [46edde9]
119
- - Updated dependencies [727bde2]
120
- - @gitbook/openapi-parser@1.0.0
117
+ - d9029c7: Support apiKey in CodeSample security headers
118
+ - 6e54a06: Support response examples
119
+ - 0c03676: Better securities sample and headers
120
+ - 3e5e458: Handle isArray schema type
121
+ - 46edde9: Improve the OpenAPI package API
122
+ - d9c8d57: Do not dereference before caching OpenAPI spec.
123
+ - ccf2cff: Fix an issue where a response object using a special ref would crash the page.
124
+ - dda0cc6: Flatten OpenAPI security object
125
+ - f92e906: Prevent codemirror from loading multiple versions in scalar
126
+ - dff08ae: Improve performances by loading Scalar API Client only when the button is clicked
127
+ - fc7b16f: Updated scalar depdenency
128
+ - a652958: Fix error on unresolvable refs by replacing with property name and any type
129
+ - 2f73db7: Support non primitive examples in OpenAPI block
130
+ - 160fca1: Support deprecated and x-deprecated-sunset in OpenAPI spec
131
+ - b41d425: Improve OpenAPI rendering performances by caching markdown parsing
132
+ - Updated dependencies [46edde9]
133
+ - Updated dependencies [727bde2]
134
+ - @gitbook/openapi-parser@1.0.0
121
135
 
122
136
  ## 0.7.1
123
137
 
124
138
  ### Patch Changes
125
139
 
126
- - 4771c78: Fixed scalar api client routing
127
- - ff50ac2: Bump @scalar/api-client-react version
128
- - 867481c: Support Integers in Response example
129
- - 7ba67fd: bumped the scalar api client dependency
130
- - a78c1ec: Bumped scalar api client pacakge
140
+ - 4771c78: Fixed scalar api client routing
141
+ - ff50ac2: Bump @scalar/api-client-react version
142
+ - 867481c: Support Integers in Response example
143
+ - 7ba67fd: bumped the scalar api client dependency
144
+ - a78c1ec: Bumped scalar api client pacakge
131
145
 
132
146
  ## 0.7.0
133
147
 
134
148
  ### Minor Changes
135
149
 
136
- - cf3045a: Add Python support in Code Samples
137
- - 4247361: Add required query parameters to the code sample
138
- - aa8c49e: Display pattern if available in parmas in OpenAPI block
139
- - e914903: Synchronize response and response example tabs
140
- - 4cbcc5b: Rollback of scalar modal while fixing perf issue
150
+ - cf3045a: Add Python support in Code Samples
151
+ - 4247361: Add required query parameters to the code sample
152
+ - aa8c49e: Display pattern if available in parmas in OpenAPI block
153
+ - e914903: Synchronize response and response example tabs
154
+ - 4cbcc5b: Rollback of scalar modal while fixing perf issue
141
155
 
142
156
  ### Patch Changes
143
157
 
144
- - 51fa3ab: Adds content-visibility css property to OpenAPI Operation for better render performance
145
- - f89b31c: Upgrade the scalar api client package
146
- - 094e9cd: bump: scalar from 1.0.5 to 1.0.7
147
- - 237b703: Fix crash when `example` is undefined for a response
148
- - 51955da: Adds tabs to Response Example section e.g. for status code examples
149
- - a679e72: Render mandatory headers in code sample
150
- - c079c3c: Update Scalar client to latest version
158
+ - 51fa3ab: Adds content-visibility css property to OpenAPI Operation for better render performance
159
+ - f89b31c: Upgrade the scalar api client package
160
+ - 094e9cd: bump: scalar from 1.0.5 to 1.0.7
161
+ - 237b703: Fix crash when `example` is undefined for a response
162
+ - 51955da: Adds tabs to Response Example section e.g. for status code examples
163
+ - a679e72: Render mandatory headers in code sample
164
+ - c079c3c: Update Scalar client to latest version
151
165
 
152
166
  ## 0.6.0
153
167
 
154
168
  ### Minor Changes
155
169
 
156
- - 709f1a1: Update Scalar to the latest version, with faster performances and an improved experience
170
+ - 709f1a1: Update Scalar to the latest version, with faster performances and an improved experience
157
171
 
158
172
  ### Patch Changes
159
173
 
160
- - ede2335: Fix x-codeSamples: false not working at the single operation level
161
- - 0426312: Fix tabs being empty for code samples when they are updated dynamically
174
+ - ede2335: Fix x-codeSamples: false not working at the single operation level
175
+ - 0426312: Fix tabs being empty for code samples when they are updated dynamically
162
176
 
163
177
  ## 0.5.0
164
178
 
165
179
  ### Minor Changes
166
180
 
167
- - 3445db4: Fix files published in the NPM packages by defining "files" in "package.json"
181
+ - 3445db4: Fix files published in the NPM packages by defining "files" in "package.json"
168
182
 
169
183
  ## 0.4.0
170
184
 
171
185
  ### Minor Changes
172
186
 
173
- - 24cd72e: Fix changeset CI workflow
187
+ - 24cd72e: Fix changeset CI workflow
174
188
 
175
189
  ## 0.3.0
176
190
 
177
191
  ### Minor Changes
178
192
 
179
- - de747b7: Refactor the repository to be a proper monorepo and publish JS files on NPM instead of TypeScript files.
193
+ - de747b7: Refactor the repository to be a proper monorepo and publish JS files on NPM instead of TypeScript files.
180
194
 
181
195
  ## 0.3.0
182
196
 
183
197
  ### Minor Changes
184
198
 
185
- - bd0ca5b: Fix missing react imports
199
+ - bd0ca5b: Fix missing react imports
186
200
 
187
201
  ## 0.2.0
188
202
 
189
203
  ### Minor Changes
190
204
 
191
- - 57adb3e: Second release to fix publishing with changeset
205
+ - 57adb3e: Second release to fix publishing with changeset
192
206
 
193
207
  ## 0.1.0
194
208
 
195
209
  ### Minor Changes
196
210
 
197
- - 5f8a8fe: Initial release
211
+ - 5f8a8fe: Initial release
@@ -30,14 +30,18 @@ export function OpenAPICodeSample(props) {
30
30
  return;
31
31
  }
32
32
  if (param.in === 'header' && param.required) {
33
- var example = param.schema ? generateSchemaExample(param.schema) : undefined;
33
+ var example = param.schema
34
+ ? generateSchemaExample(param.schema, { mode: 'write' })
35
+ : undefined;
34
36
  if (example !== undefined && param.name) {
35
37
  headersObject[param.name] =
36
38
  typeof example !== 'string' ? stringifyOpenAPI(example) : example;
37
39
  }
38
40
  }
39
41
  else if (param.in === 'query' && param.required) {
40
- var example = param.schema ? generateSchemaExample(param.schema) : undefined;
42
+ var example = param.schema
43
+ ? generateSchemaExample(param.schema, { mode: 'write' })
44
+ : undefined;
41
45
  if (example !== undefined && param.name) {
42
46
  searchParams.append(param.name, String(Array.isArray(example) ? example[0] : example));
43
47
  }
@@ -13,6 +13,7 @@ export function OpenAPISchemaName(props) {
13
13
  {type ? <span className="openapi-schema-type">{type}</span> : null}
14
14
  {additionalItems ? (<span className="openapi-schema-type">{additionalItems}</span>) : null}
15
15
  </span>
16
+ {(schema === null || schema === void 0 ? void 0 : schema.readOnly) ? <span className="openapi-schema-readonly">read-only</span> : null}
16
17
  {required ? <span className="openapi-schema-required">required</span> : null}
17
18
  {(schema === null || schema === void 0 ? void 0 : schema.deprecated) ? <span className="openapi-deprecated">Deprecated</span> : null}
18
19
  </div>);
@@ -16,7 +16,7 @@ export function OpenAPISecurities(props) {
16
16
  return {
17
17
  key: key,
18
18
  label: key,
19
- body: (<div className="openapi-schema-body">
19
+ body: (<div className="openapi-schema">
20
20
  <div className="openapi-schema-presentation">
21
21
  {getLabelForType(security)}
22
22
 
@@ -1,9 +1,11 @@
1
1
  import type { OpenAPIContextProps, OpenAPISchemasData } from '../types';
2
+ type OpenAPISchemasContextProps = Omit<OpenAPIContextProps, 'renderCodeBlock' | 'renderHeading' | 'renderDocument'>;
2
3
  /**
3
4
  * Display OpenAPI Schemas.
4
5
  */
5
6
  export declare function OpenAPISchemas(props: {
6
7
  className?: string;
7
8
  data: OpenAPISchemasData;
8
- context: OpenAPIContextProps;
9
+ context: OpenAPISchemasContextProps;
9
10
  }): import("react").JSX.Element | null;
11
+ export {};
@@ -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>): Promise<OpenAPISchemasData | null>;
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: return [4 /*yield*/, dereferenceFilesystem(filesystem)];
49
+ case 0:
50
+ selectedSchemas = options.schemas;
51
+ return [4 /*yield*/, dereferenceFilesystem(filesystem)];
50
52
  case 1:
51
53
  schema = _a.sent();
52
- schemas = getOpenAPIComponents(schema);
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
- * Get OpenAPI components.schemas that are not ignored.
64
+ * Extract selected schemas from the OpenAPI document.
60
65
  */
61
- function getOpenAPIComponents(schema) {
66
+ export function filterSelectedOpenAPISchemas(schema, selectedSchemas) {
62
67
  var _a, _b;
63
- var schemas = (_b = (_a = schema.components) === null || _a === void 0 ? void 0 : _a.schemas) !== null && _b !== void 0 ? _b : {};
64
- return Object.entries(schemas)
65
- .filter(function (_a) {
66
- var schema = _a[1];
67
- return !shouldIgnoreEntity(schema);
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
- .map(function (_a) {
70
- var key = _a[0], schema = _a[1];
71
- return ({ name: key, schema: schema });
72
- });
81
+ .filter(function (schema) { return !!schema; });
73
82
  }