@gitbook/react-openapi 1.1.8 → 1.1.10

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 (65) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/InteractiveSection.jsx +7 -6
  3. package/dist/OpenAPICodeSample.d.ts +2 -2
  4. package/dist/OpenAPICodeSample.jsx +3 -8
  5. package/dist/OpenAPICodeSampleInteractive.jsx +31 -19
  6. package/dist/OpenAPICodeSampleSelector.d.ts +15 -0
  7. package/dist/OpenAPICodeSampleSelector.jsx +49 -0
  8. package/dist/OpenAPIExample.d.ts +34 -0
  9. package/dist/OpenAPIExample.jsx +103 -0
  10. package/dist/OpenAPIOperation.d.ts +2 -2
  11. package/dist/OpenAPIOperation.jsx +3 -7
  12. package/dist/OpenAPIPath.d.ts +10 -2
  13. package/dist/OpenAPIPath.jsx +9 -4
  14. package/dist/OpenAPIResponse.jsx +3 -3
  15. package/dist/OpenAPIResponseExample.d.ts +2 -2
  16. package/dist/OpenAPIResponseExample.jsx +4 -90
  17. package/dist/OpenAPIResponses.jsx +23 -10
  18. package/dist/OpenAPISchema.jsx +26 -15
  19. package/dist/OpenAPISchemaName.jsx +2 -7
  20. package/dist/OpenAPISecurities.jsx +6 -6
  21. package/dist/OpenAPISelect.d.ts +15 -0
  22. package/dist/OpenAPISelect.jsx +32 -0
  23. package/dist/OpenAPITabs.jsx +9 -9
  24. package/dist/context.d.ts +54 -0
  25. package/dist/context.js +11 -0
  26. package/dist/generateSchemaExample.d.ts +1 -1
  27. package/dist/generateSchemaExample.js +28 -26
  28. package/dist/getOrCreateStoreByKey.d.ts +10 -0
  29. package/dist/getOrCreateStoreByKey.js +20 -0
  30. package/dist/index.d.ts +1 -1
  31. package/dist/resolveOpenAPIOperation.js +10 -5
  32. package/dist/schemas/OpenAPISchemas.d.ts +5 -6
  33. package/dist/schemas/OpenAPISchemas.jsx +45 -38
  34. package/dist/schemas/resolveOpenAPISchemas.d.ts +4 -3
  35. package/dist/schemas/resolveOpenAPISchemas.js +0 -1
  36. package/dist/tsconfig.build.tsbuildinfo +1 -1
  37. package/dist/types.d.ts +32 -26
  38. package/package.json +1 -1
  39. package/src/InteractiveSection.tsx +10 -8
  40. package/src/OpenAPICodeSample.tsx +8 -15
  41. package/src/OpenAPICodeSampleInteractive.tsx +43 -26
  42. package/src/OpenAPICodeSampleSelector.tsx +87 -0
  43. package/src/OpenAPIExample.tsx +129 -0
  44. package/src/OpenAPIOperation.tsx +6 -10
  45. package/src/OpenAPIPath.tsx +23 -6
  46. package/src/OpenAPIResponse.tsx +9 -7
  47. package/src/OpenAPIResponseExample.tsx +13 -113
  48. package/src/OpenAPIResponses.tsx +37 -12
  49. package/src/OpenAPISchema.tsx +40 -25
  50. package/src/OpenAPISchemaName.tsx +2 -8
  51. package/src/OpenAPISecurities.tsx +22 -9
  52. package/src/OpenAPISelect.tsx +70 -0
  53. package/src/OpenAPITabs.tsx +9 -9
  54. package/src/context.ts +64 -0
  55. package/src/generateSchemaExample.test.ts +1020 -0
  56. package/src/generateSchemaExample.ts +103 -36
  57. package/src/getOrCreateStoreByKey.ts +35 -0
  58. package/src/index.ts +1 -1
  59. package/src/resolveOpenAPIOperation.ts +14 -3
  60. package/src/schemas/OpenAPISchemas.tsx +75 -70
  61. package/src/schemas/resolveOpenAPISchemas.ts +4 -5
  62. package/src/types.ts +36 -29
  63. package/dist/useSyncedTabsGlobalState.d.ts +0 -10
  64. package/dist/useSyncedTabsGlobalState.js +0 -20
  65. package/src/useSyncedTabsGlobalState.ts +0 -35
@@ -1,62 +1,69 @@
1
1
  import clsx from 'clsx';
2
2
  import { OpenAPIDisclosureGroup } from '../OpenAPIDisclosureGroup';
3
+ import { OpenAPIExample, getExampleFromSchema } from '../OpenAPIExample';
3
4
  import { OpenAPIRootSchema } from '../OpenAPISchemaServer';
4
- import { Section, SectionBody } from '../StaticSection';
5
+ import { Section, SectionBody, StaticSection } from '../StaticSection';
6
+ import { getOpenAPIClientContext } from '../context';
5
7
  /**
6
- * Display OpenAPI Schemas.
8
+ * OpenAPI Schemas component.
7
9
  */
8
10
  export function OpenAPISchemas(props) {
9
- var className = props.className, data = props.data, context = props.context, grouped = props.grouped;
10
- var schemas = data.schemas;
11
- var clientContext = {
12
- defaultInteractiveOpened: context.defaultInteractiveOpened,
13
- icons: context.icons,
14
- blockKey: context.blockKey,
15
- };
16
- if (!schemas.length) {
11
+ var schemas = props.schemas, context = props.context, grouped = props.grouped, className = props.className;
12
+ var firstSchema = schemas[0];
13
+ if (!firstSchema) {
17
14
  return null;
18
15
  }
19
- return (<div className={clsx('openapi-schemas', className)}>
20
- <OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext}/>
21
- </div>);
22
- }
23
- /**
24
- * Root schema for OpenAPI schemas.
25
- * It displays a single model or a disclosure group for multiple schemas.
26
- */
27
- function OpenAPIRootSchemasSchema(props) {
28
- var _a;
29
- var schemas = props.schemas, context = props.context, grouped = props.grouped;
16
+ var clientContext = getOpenAPIClientContext(context);
30
17
  // If there is only one model and we are not grouping, we show it directly.
31
18
  if (schemas.length === 1 && !grouped) {
32
- var schema = (_a = schemas === null || schemas === void 0 ? void 0 : schemas[0]) === null || _a === void 0 ? void 0 : _a.schema;
33
- if (!schema) {
34
- return null;
35
- }
36
- return (<Section>
37
- <SectionBody>
38
- <OpenAPIRootSchema schema={schema} context={context}/>
39
- </SectionBody>
40
- </Section>);
19
+ var title = "The ".concat(firstSchema.name, " object");
20
+ return (<div className={clsx('openapi-schemas', className)}>
21
+ <div className="openapi-summary" id={context.id}>
22
+ {context.renderHeading({
23
+ title: title,
24
+ })}
25
+ </div>
26
+ <div className="openapi-columns">
27
+ <div className="openapi-column-spec">
28
+ <StaticSection className="openapi-parameters" header="Attributes">
29
+ <OpenAPIRootSchema schema={firstSchema.schema} context={clientContext}/>
30
+ </StaticSection>
31
+ </div>
32
+ <div className="openapi-column-preview">
33
+ <div className="openapi-column-preview-body">
34
+ <div className="openapi-panel">
35
+ <h4 className="openapi-panel-heading">{title}</h4>
36
+ <div className="openapi-panel-body">
37
+ <OpenAPIExample example={getExampleFromSchema({
38
+ schema: firstSchema.schema,
39
+ })} context={context} syntax="json"/>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>);
41
46
  }
42
47
  // If there are multiple schemas, we use a disclosure group to show them all.
43
- return (<OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={schemas.map(function (_a) {
48
+ return (<div className={clsx('openapi-schemas', className)}>
49
+ <OpenAPIDisclosureGroup allowsMultipleExpanded icon={context.icons.chevronRight} groups={schemas.map(function (_a) {
44
50
  var name = _a.name, schema = _a.schema;
45
51
  return ({
46
52
  id: name,
47
53
  label: (<div className="openapi-response-tab-content" key={"model-".concat(name)}>
48
- <span className="openapi-response-statuscode">{name}</span>
49
- </div>),
54
+ <span className="openapi-response-statuscode">{name}</span>
55
+ </div>),
50
56
  tabs: [
51
57
  {
52
58
  id: 'model',
53
59
  body: (<Section className="openapi-section-schemas">
54
- <SectionBody>
55
- <OpenAPIRootSchema schema={schema} context={context}/>
56
- </SectionBody>
57
- </Section>),
60
+ <SectionBody>
61
+ <OpenAPIRootSchema schema={schema} context={clientContext}/>
62
+ </SectionBody>
63
+ </Section>),
58
64
  },
59
65
  ],
60
66
  });
61
- })}/>);
67
+ })}/>
68
+ </div>);
62
69
  }
@@ -1,9 +1,10 @@
1
- import type { Filesystem, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
2
- import type { OpenAPISchemasData } from '../types';
1
+ import type { Filesystem, OpenAPISchema, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
3
2
  /**
4
3
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
5
4
  * Schemas are extracted from the OpenAPI components.schemas
6
5
  */
7
6
  export declare function resolveOpenAPISchemas(filesystem: Filesystem<OpenAPIV3xDocument>, options: {
8
7
  schemas: string[];
9
- }): Promise<OpenAPISchemasData | null>;
8
+ }): Promise<{
9
+ schemas: OpenAPISchema[];
10
+ } | null>;
@@ -36,7 +36,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser';
38
38
  import { dereferenceFilesystem } from '../dereference';
39
- //!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
40
39
  /**
41
40
  * Resolve an OpenAPI schemas from a file and compile it to a more usable format.
42
41
  * Schemas are extracted from the OpenAPI components.schemas