@gitbook/react-openapi 1.3.0 → 1.3.1

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 (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/OpenAPICodeSample.jsx +7 -4
  3. package/dist/OpenAPIRequestBody.jsx +7 -2
  4. package/dist/OpenAPIRequestBodyHeaderType.d.ts +8 -0
  5. package/dist/OpenAPIRequestBodyHeaderType.jsx +25 -0
  6. package/dist/OpenAPIResponse.d.ts +1 -1
  7. package/dist/OpenAPIResponse.jsx +2 -2
  8. package/dist/OpenAPIResponseExample.jsx +7 -0
  9. package/dist/OpenAPISchema.jsx +1 -39
  10. package/dist/OpenAPISchemaName.jsx +4 -4
  11. package/dist/OpenAPISecurities.jsx +59 -1
  12. package/dist/OpenAPISelect.jsx +1 -0
  13. package/dist/OpenAPISpec.jsx +16 -1
  14. package/dist/OpenAPIWebhookExample.jsx +1 -1
  15. package/dist/code-samples.js +1 -1
  16. package/dist/generateSchemaExample.js +14 -14
  17. package/dist/translations/de.d.ts +1 -0
  18. package/dist/translations/de.js +1 -0
  19. package/dist/translations/en.d.ts +1 -0
  20. package/dist/translations/en.js +1 -0
  21. package/dist/translations/es.d.ts +1 -0
  22. package/dist/translations/es.js +1 -0
  23. package/dist/translations/fr.d.ts +1 -0
  24. package/dist/translations/fr.js +1 -0
  25. package/dist/translations/index.d.ts +9 -0
  26. package/dist/translations/ja.d.ts +1 -0
  27. package/dist/translations/ja.js +1 -0
  28. package/dist/translations/nl.d.ts +1 -0
  29. package/dist/translations/nl.js +1 -0
  30. package/dist/translations/no.d.ts +1 -0
  31. package/dist/translations/no.js +1 -0
  32. package/dist/translations/pt-br.d.ts +1 -0
  33. package/dist/translations/pt-br.js +1 -0
  34. package/dist/translations/zh.d.ts +1 -0
  35. package/dist/translations/zh.js +1 -0
  36. package/dist/tsconfig.build.tsbuildinfo +1 -1
  37. package/dist/utils.d.ts +1 -0
  38. package/dist/utils.js +38 -0
  39. package/package.json +2 -2
  40. package/src/OpenAPICodeSample.tsx +7 -6
  41. package/src/OpenAPIRequestBody.tsx +11 -2
  42. package/src/OpenAPIRequestBodyHeaderType.tsx +36 -0
  43. package/src/OpenAPIResponse.tsx +3 -3
  44. package/src/OpenAPIResponseExample.tsx +10 -1
  45. package/src/OpenAPISchema.tsx +1 -38
  46. package/src/OpenAPISchemaName.tsx +8 -6
  47. package/src/OpenAPISecurities.tsx +111 -7
  48. package/src/OpenAPISelect.tsx +1 -1
  49. package/src/OpenAPISpec.tsx +21 -1
  50. package/src/OpenAPIWebhookExample.tsx +2 -2
  51. package/src/code-samples.test.ts +2 -2
  52. package/src/code-samples.ts +16 -12
  53. package/src/generateSchemaExample.test.ts +20 -0
  54. package/src/generateSchemaExample.ts +1 -1
  55. package/src/translations/de.ts +1 -0
  56. package/src/translations/en.ts +1 -0
  57. package/src/translations/es.ts +1 -0
  58. package/src/translations/fr.ts +1 -0
  59. package/src/translations/ja.ts +1 -0
  60. package/src/translations/nl.ts +1 -0
  61. package/src/translations/no.ts +1 -0
  62. package/src/translations/pt-br.ts +1 -0
  63. package/src/translations/zh.ts +1 -0
  64. 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
+ }