@gitbook/react-openapi 1.1.3 → 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,203 +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
+
3
11
  ## 1.1.3
4
12
 
5
13
  ### Patch Changes
6
14
 
7
- - 844059f: Fix spacing in OpenAPISecurities
15
+ - 844059f: Fix spacing in OpenAPISecurities
8
16
 
9
17
  ## 1.1.2
10
18
 
11
19
  ### Patch Changes
12
20
 
13
- - f127d28: Rename OpenAPIModels to OpenAPISchemas
21
+ - f127d28: Rename OpenAPIModels to OpenAPISchemas
14
22
 
15
23
  ## 1.1.1
16
24
 
17
25
  ### Patch Changes
18
26
 
19
- - f574858: Fix OpenAPI example display error
27
+ - f574858: Fix OpenAPI example display error
20
28
 
21
29
  ## 1.1.0
22
30
 
23
31
  ### Minor Changes
24
32
 
25
- - bb3ca9c: Implement OpenAPI models blocks
33
+ - bb3ca9c: Implement OpenAPI models blocks
26
34
 
27
35
  ### Patch Changes
28
36
 
29
- - 0278a14: Upgrade Scalar dependencies
30
- - 3173d8e: Remove top level circular refs in alternatives
31
- - Updated dependencies [0278a14]
32
- - Updated dependencies [bb3ca9c]
33
- - Updated dependencies [052e07a]
34
- - @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
35
43
 
36
44
  ## 1.0.5
37
45
 
38
46
  ### Patch Changes
39
47
 
40
- - Updated dependencies [53f5dbe]
41
- - @gitbook/openapi-parser@2.0.2
48
+ - Updated dependencies [53f5dbe]
49
+ - @gitbook/openapi-parser@2.0.2
42
50
 
43
51
  ## 1.0.4
44
52
 
45
53
  ### Patch Changes
46
54
 
47
- - 722f02e: Fix recursion in OpenAPISchemaAlternative
48
- - Updated dependencies [0924259]
49
- - @gitbook/openapi-parser@2.0.1
55
+ - 722f02e: Fix recursion in OpenAPISchemaAlternative
56
+ - Updated dependencies [0924259]
57
+ - @gitbook/openapi-parser@2.0.1
50
58
 
51
59
  ## 1.0.3
52
60
 
53
61
  ### Patch Changes
54
62
 
55
- - dc2dbc5: Update OpenAPI code examples to support multiple content-type
56
- - f1d1d2f: Return empty string if no server provided
57
- - 05e1d8c: Hide x-gitbook-\* symbols in OpenAPI blocks
58
- - b4a12d6: Fix circularRef in schema + examples OpenAPI
59
- - 9f0de74: Fix ID not set when there is no operation summary
60
- - da55fac: Render GitBook blocks in OpenAPI operation description
61
- - Updated dependencies [c808bb1]
62
- - Updated dependencies [e24206e]
63
- - Updated dependencies [a054554]
64
- - Updated dependencies [da55fac]
65
- - @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
66
74
 
67
75
  ## 1.0.2
68
76
 
69
77
  ### Patch Changes
70
78
 
71
- - bb5c6a4: Support multiple response media types and examples
72
- - a3f1fea: Fix display of OpenAPI header description
73
- - 6157583: Improve Markdown parsing
74
- - 7419ee7: Show additional fields in OpenAPI block
75
- - 82cd9f2: Add support for anchor links in OpenAPI blocks
76
- - Updated dependencies [6157583]
77
- - @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
78
86
 
79
87
  ## 1.0.1
80
88
 
81
89
  ### Patch Changes
82
90
 
83
- - f8d4c76: Sync tabs across all OpenAPI blocks
84
- - dddb4ec: Fix long tab group description
85
- - 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
86
94
 
87
95
  ## 1.0.0
88
96
 
89
97
  ### Major Changes
90
98
 
91
- - 727bde2: Improve and split OpenAPI parser into its own package
92
- - 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:
93
101
 
94
- - `fetcher.fetch` must now returns a valid OpenAPI document
95
- - `parseOpenAPIV3` has been replaced by `parseOpenAPI`
102
+ - `fetcher.fetch` must now returns a valid OpenAPI document
103
+ - `parseOpenAPIV3` has been replaced by `parseOpenAPI`
96
104
 
97
105
  ### Minor Changes
98
106
 
99
- - 162b4b7: Add in HTTP example code blocks
100
- - e4e2f52: Add an optional client context to get a callback called when the Scalar client is opened for a block.
101
- - eb7c22f: Revert scalar to 1.0.87 to mitigate an issue with ApiClientModalProvider
102
- - 160fca1: new OpenAPI blocks design
103
- - e721f17: Use `@scalar/oas-utils` getExampleFromSchema to generate OpenAPI examples
104
- - fe8acc9: Fix an issue where a missing OpenAPI example would crash the page.
105
- - 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.
106
114
 
107
115
  ### Patch Changes
108
116
 
109
- - d9029c7: Support apiKey in CodeSample security headers
110
- - 6e54a06: Support response examples
111
- - 0c03676: Better securities sample and headers
112
- - 3e5e458: Handle isArray schema type
113
- - 46edde9: Improve the OpenAPI package API
114
- - d9c8d57: Do not dereference before caching OpenAPI spec.
115
- - ccf2cff: Fix an issue where a response object using a special ref would crash the page.
116
- - dda0cc6: Flatten OpenAPI security object
117
- - f92e906: Prevent codemirror from loading multiple versions in scalar
118
- - dff08ae: Improve performances by loading Scalar API Client only when the button is clicked
119
- - fc7b16f: Updated scalar depdenency
120
- - a652958: Fix error on unresolvable refs by replacing with property name and any type
121
- - 2f73db7: Support non primitive examples in OpenAPI block
122
- - 160fca1: Support deprecated and x-deprecated-sunset in OpenAPI spec
123
- - b41d425: Improve OpenAPI rendering performances by caching markdown parsing
124
- - Updated dependencies [46edde9]
125
- - Updated dependencies [727bde2]
126
- - @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
127
135
 
128
136
  ## 0.7.1
129
137
 
130
138
  ### Patch Changes
131
139
 
132
- - 4771c78: Fixed scalar api client routing
133
- - ff50ac2: Bump @scalar/api-client-react version
134
- - 867481c: Support Integers in Response example
135
- - 7ba67fd: bumped the scalar api client dependency
136
- - 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
137
145
 
138
146
  ## 0.7.0
139
147
 
140
148
  ### Minor Changes
141
149
 
142
- - cf3045a: Add Python support in Code Samples
143
- - 4247361: Add required query parameters to the code sample
144
- - aa8c49e: Display pattern if available in parmas in OpenAPI block
145
- - e914903: Synchronize response and response example tabs
146
- - 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
147
155
 
148
156
  ### Patch Changes
149
157
 
150
- - 51fa3ab: Adds content-visibility css property to OpenAPI Operation for better render performance
151
- - f89b31c: Upgrade the scalar api client package
152
- - 094e9cd: bump: scalar from 1.0.5 to 1.0.7
153
- - 237b703: Fix crash when `example` is undefined for a response
154
- - 51955da: Adds tabs to Response Example section e.g. for status code examples
155
- - a679e72: Render mandatory headers in code sample
156
- - 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
157
165
 
158
166
  ## 0.6.0
159
167
 
160
168
  ### Minor Changes
161
169
 
162
- - 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
163
171
 
164
172
  ### Patch Changes
165
173
 
166
- - ede2335: Fix x-codeSamples: false not working at the single operation level
167
- - 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
168
176
 
169
177
  ## 0.5.0
170
178
 
171
179
  ### Minor Changes
172
180
 
173
- - 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"
174
182
 
175
183
  ## 0.4.0
176
184
 
177
185
  ### Minor Changes
178
186
 
179
- - 24cd72e: Fix changeset CI workflow
187
+ - 24cd72e: Fix changeset CI workflow
180
188
 
181
189
  ## 0.3.0
182
190
 
183
191
  ### Minor Changes
184
192
 
185
- - 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.
186
194
 
187
195
  ## 0.3.0
188
196
 
189
197
  ### Minor Changes
190
198
 
191
- - bd0ca5b: Fix missing react imports
199
+ - bd0ca5b: Fix missing react imports
192
200
 
193
201
  ## 0.2.0
194
202
 
195
203
  ### Minor Changes
196
204
 
197
- - 57adb3e: Second release to fix publishing with changeset
205
+ - 57adb3e: Second release to fix publishing with changeset
198
206
 
199
207
  ## 0.1.0
200
208
 
201
209
  ### Minor Changes
202
210
 
203
- - 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>);
@@ -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
  }