@gitbook/react-openapi 1.3.0 → 1.3.2
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 +23 -0
- package/dist/OpenAPICodeSample.jsx +7 -4
- package/dist/OpenAPIRequestBody.jsx +7 -2
- package/dist/OpenAPIRequestBodyHeaderType.d.ts +8 -0
- package/dist/OpenAPIRequestBodyHeaderType.jsx +25 -0
- package/dist/OpenAPIResponse.d.ts +1 -1
- package/dist/OpenAPIResponse.jsx +2 -2
- package/dist/OpenAPIResponseExample.jsx +7 -0
- package/dist/OpenAPISchema.jsx +1 -39
- package/dist/OpenAPISchemaName.jsx +4 -4
- package/dist/OpenAPISecurities.jsx +59 -1
- package/dist/OpenAPISelect.jsx +1 -0
- package/dist/OpenAPISpec.jsx +16 -1
- package/dist/OpenAPIWebhookExample.jsx +1 -1
- package/dist/code-samples.js +1 -1
- package/dist/generateSchemaExample.js +14 -14
- package/dist/translations/de.d.ts +1 -0
- package/dist/translations/de.js +1 -0
- package/dist/translations/en.d.ts +1 -0
- package/dist/translations/en.js +1 -0
- package/dist/translations/es.d.ts +1 -0
- package/dist/translations/es.js +1 -0
- package/dist/translations/fr.d.ts +1 -0
- package/dist/translations/fr.js +1 -0
- package/dist/translations/index.d.ts +9 -0
- package/dist/translations/ja.d.ts +1 -0
- package/dist/translations/ja.js +1 -0
- package/dist/translations/nl.d.ts +1 -0
- package/dist/translations/nl.js +1 -0
- package/dist/translations/no.d.ts +1 -0
- package/dist/translations/no.js +1 -0
- package/dist/translations/pt-br.d.ts +1 -0
- package/dist/translations/pt-br.js +1 -0
- package/dist/translations/zh.d.ts +1 -0
- package/dist/translations/zh.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +38 -0
- package/package.json +2 -2
- package/src/OpenAPICodeSample.tsx +7 -6
- package/src/OpenAPIRequestBody.tsx +11 -2
- package/src/OpenAPIRequestBodyHeaderType.tsx +36 -0
- package/src/OpenAPIResponse.tsx +3 -3
- package/src/OpenAPIResponseExample.tsx +10 -1
- package/src/OpenAPISchema.tsx +1 -38
- package/src/OpenAPISchemaName.tsx +8 -6
- package/src/OpenAPISecurities.tsx +111 -7
- package/src/OpenAPISelect.tsx +1 -1
- package/src/OpenAPISpec.tsx +21 -1
- package/src/OpenAPIWebhookExample.tsx +2 -2
- package/src/code-samples.test.ts +2 -2
- package/src/code-samples.ts +16 -12
- package/src/generateSchemaExample.test.ts +20 -0
- package/src/generateSchemaExample.ts +1 -1
- package/src/translations/de.ts +1 -0
- package/src/translations/en.ts +1 -0
- package/src/translations/es.ts +1 -0
- package/src/translations/fr.ts +1 -0
- package/src/translations/ja.ts +1 -0
- package/src/translations/nl.ts +1 -0
- package/src/translations/no.ts +1 -0
- package/src/translations/pt-br.ts +1 -0
- package/src/translations/zh.ts +1 -0
- package/src/utils.ts +37 -0
package/src/utils.ts
CHANGED
|
@@ -216,3 +216,40 @@ function getStatusCodeCategory(statusCode: number | string): number | string {
|
|
|
216
216
|
|
|
217
217
|
return category;
|
|
218
218
|
}
|
|
219
|
+
|
|
220
|
+
export function getSchemaTitle(schema: OpenAPIV3.SchemaObject): string {
|
|
221
|
+
// Otherwise try to infer a nice title
|
|
222
|
+
let type = 'any';
|
|
223
|
+
|
|
224
|
+
if (schema.enum || schema['x-enumDescriptions'] || schema['x-gitbook-enum']) {
|
|
225
|
+
type = `${schema.type} · enum`;
|
|
226
|
+
// check array AND schema.items as this is sometimes null despite what the type indicates
|
|
227
|
+
} else if (schema.type === 'array' && !!schema.items) {
|
|
228
|
+
type = `${getSchemaTitle(schema.items)}[]`;
|
|
229
|
+
} else if (Array.isArray(schema.type)) {
|
|
230
|
+
type = schema.type.join(' | ');
|
|
231
|
+
} else if (schema.type || schema.properties) {
|
|
232
|
+
type = schema.type ?? 'object';
|
|
233
|
+
|
|
234
|
+
if (schema.format) {
|
|
235
|
+
type += ` · ${schema.format}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Only add the title if it's an object (no need for the title of a string, number, etc.)
|
|
239
|
+
if (type === 'object' && schema.title) {
|
|
240
|
+
type += ` · ${schema.title.replaceAll(' ', '')}`;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if ('anyOf' in schema) {
|
|
245
|
+
type = 'any of';
|
|
246
|
+
} else if ('oneOf' in schema) {
|
|
247
|
+
type = 'one of';
|
|
248
|
+
} else if ('allOf' in schema) {
|
|
249
|
+
type = 'all of';
|
|
250
|
+
} else if ('not' in schema) {
|
|
251
|
+
type = 'not';
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return type;
|
|
255
|
+
}
|