docusaurus-plugin-openapi-docs 1.1.4 → 1.1.7

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.
@@ -192,7 +192,8 @@ function createItems(schema) {
192
192
  return createAnyOneOf(schema.items);
193
193
  }
194
194
  if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
195
- const { mergedSchemas } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
195
+ // TODO: figure out if and how we should pass merged required array
196
+ const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
196
197
  // Handles combo anyOf/oneOf + properties
197
198
  if ((mergedSchemas.oneOf !== undefined ||
198
199
  mergedSchemas.anyOf !== undefined) &&
@@ -331,7 +332,7 @@ function createDetailsNode(name, schemaName, schema, required) {
331
332
  style: { opacity: "0.6" },
332
333
  children: ` ${schemaName}`,
333
334
  }),
334
- (0, utils_1.guard)(required, () => [
335
+ (0, utils_1.guard)(schema.required && schema.required === true, () => [
335
336
  (0, utils_1.create)("strong", {
336
337
  style: {
337
338
  fontSize: "var(--ifm-code-font-size)",
@@ -427,6 +428,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
427
428
  function createEdges({ name, schema, required, discriminator, }) {
428
429
  var _a, _b;
429
430
  const schemaName = (0, schema_1.getSchemaName)(schema);
431
+ // if (name === "id") console.log(name, schema, required);
430
432
  if (discriminator !== undefined && discriminator.propertyName === name) {
431
433
  return createPropertyDiscriminator(name, "string", schema, discriminator, required);
432
434
  }
@@ -453,7 +455,7 @@ function createEdges({ name, schema, required, discriminator, }) {
453
455
  return (0, utils_1.create)("SchemaItem", {
454
456
  collapsible: false,
455
457
  name,
456
- required,
458
+ required: Array.isArray(required) ? required.includes(name) : required,
457
459
  schemaDescription: mergedSchemas.description,
458
460
  schemaName: schemaName,
459
461
  qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
@@ -474,7 +476,7 @@ function createEdges({ name, schema, required, discriminator, }) {
474
476
  return (0, utils_1.create)("SchemaItem", {
475
477
  collapsible: false,
476
478
  name,
477
- required,
479
+ required: Array.isArray(required) ? required.includes(name) : required,
478
480
  schemaDescription: schema.description,
479
481
  schemaName: schemaName,
480
482
  qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
@@ -541,8 +543,71 @@ function createSchemaDetails({ title, body, ...rest }) {
541
543
  Object.keys(body.content).length === 0) {
542
544
  return undefined;
543
545
  }
544
- // NOTE: We just pick a random content-type.
545
- // How common is it to have multiple?
546
+ // Get all MIME types, including vendor-specific
547
+ const mimeTypes = Object.keys(body.content);
548
+ if (mimeTypes && mimeTypes.length > 1) {
549
+ return (0, utils_1.create)("MimeTabs", {
550
+ groupId: "mime-type",
551
+ children: mimeTypes.map((mimeType) => {
552
+ const firstBody = body.content[mimeType].schema;
553
+ if (firstBody === undefined) {
554
+ return undefined;
555
+ }
556
+ if (firstBody.properties !== undefined) {
557
+ if (Object.keys(firstBody.properties).length === 0) {
558
+ return undefined;
559
+ }
560
+ }
561
+ return (0, utils_1.create)("TabItem", {
562
+ label: mimeType,
563
+ value: `${mimeType}`,
564
+ children: [
565
+ (0, createDetails_1.createDetails)({
566
+ "data-collapsed": false,
567
+ open: true,
568
+ ...rest,
569
+ children: [
570
+ (0, createDetailsSummary_1.createDetailsSummary)({
571
+ style: { textAlign: "left" },
572
+ children: [
573
+ (0, utils_1.create)("strong", { children: `${title}` }),
574
+ (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
575
+ style: { opacity: "0.6" },
576
+ children: ` array`,
577
+ })),
578
+ (0, utils_1.guard)(body.required && body.required === true, () => [
579
+ (0, utils_1.create)("strong", {
580
+ style: {
581
+ fontSize: "var(--ifm-code-font-size)",
582
+ color: "var(--openapi-required)",
583
+ },
584
+ children: " required",
585
+ }),
586
+ ]),
587
+ ],
588
+ }),
589
+ (0, utils_1.create)("div", {
590
+ style: { textAlign: "left", marginLeft: "1rem" },
591
+ children: [
592
+ (0, utils_1.guard)(body.description, () => [
593
+ (0, utils_1.create)("div", {
594
+ style: { marginTop: "1rem", marginBottom: "1rem" },
595
+ children: (0, createDescription_1.createDescription)(body.description),
596
+ }),
597
+ ]),
598
+ ],
599
+ }),
600
+ (0, utils_1.create)("ul", {
601
+ style: { marginLeft: "1rem" },
602
+ children: createNodes(firstBody),
603
+ }),
604
+ ],
605
+ }),
606
+ ],
607
+ });
608
+ }),
609
+ });
610
+ }
546
611
  const randomFirstKey = Object.keys(body.content)[0];
547
612
  const firstBody = body.content[randomFirstKey].schema;
548
613
  if (firstBody === undefined) {
@@ -554,46 +619,55 @@ function createSchemaDetails({ title, body, ...rest }) {
554
619
  return undefined;
555
620
  }
556
621
  }
557
- // Root-level schema dropdown
558
- return (0, createDetails_1.createDetails)({
559
- "data-collapsed": false,
560
- open: true,
561
- ...rest,
622
+ return (0, utils_1.create)("MimeTabs", {
562
623
  children: [
563
- (0, createDetailsSummary_1.createDetailsSummary)({
564
- style: { textAlign: "left" },
624
+ (0, utils_1.create)("TabItem", {
625
+ label: randomFirstKey,
626
+ value: `${randomFirstKey}-schema`,
565
627
  children: [
566
- (0, utils_1.create)("strong", { children: `${title}` }),
567
- (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
568
- style: { opacity: "0.6" },
569
- children: ` array`,
570
- })),
571
- (0, utils_1.guard)(body.required, () => [
572
- (0, utils_1.create)("strong", {
573
- style: {
574
- fontSize: "var(--ifm-code-font-size)",
575
- color: "var(--openapi-required)",
576
- },
577
- children: " required",
578
- }),
579
- ]),
580
- ],
581
- }),
582
- (0, utils_1.create)("div", {
583
- style: { textAlign: "left", marginLeft: "1rem" },
584
- children: [
585
- (0, utils_1.guard)(body.description, () => [
586
- (0, utils_1.create)("div", {
587
- style: { marginTop: "1rem", marginBottom: "1rem" },
588
- children: (0, createDescription_1.createDescription)(body.description),
589
- }),
590
- ]),
628
+ (0, createDetails_1.createDetails)({
629
+ "data-collapsed": false,
630
+ open: true,
631
+ ...rest,
632
+ children: [
633
+ (0, createDetailsSummary_1.createDetailsSummary)({
634
+ style: { textAlign: "left" },
635
+ children: [
636
+ (0, utils_1.create)("strong", { children: `${title}` }),
637
+ (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
638
+ style: { opacity: "0.6" },
639
+ children: ` array`,
640
+ })),
641
+ (0, utils_1.guard)(body.required, () => [
642
+ (0, utils_1.create)("strong", {
643
+ style: {
644
+ fontSize: "var(--ifm-code-font-size)",
645
+ color: "var(--openapi-required)",
646
+ },
647
+ children: " required",
648
+ }),
649
+ ]),
650
+ ],
651
+ }),
652
+ (0, utils_1.create)("div", {
653
+ style: { textAlign: "left", marginLeft: "1rem" },
654
+ children: [
655
+ (0, utils_1.guard)(body.description, () => [
656
+ (0, utils_1.create)("div", {
657
+ style: { marginTop: "1rem", marginBottom: "1rem" },
658
+ children: (0, createDescription_1.createDescription)(body.description),
659
+ }),
660
+ ]),
661
+ ],
662
+ }),
663
+ (0, utils_1.create)("ul", {
664
+ style: { marginLeft: "1rem" },
665
+ children: createNodes(firstBody),
666
+ }),
667
+ ],
668
+ }),
591
669
  ],
592
670
  }),
593
- (0, utils_1.create)("ul", {
594
- style: { marginLeft: "1rem" },
595
- children: createNodes(firstBody),
596
- }),
597
671
  ],
598
672
  });
599
673
  }
@@ -2,5 +2,7 @@ import { ApiItem } from "../types";
2
2
  interface Props {
3
3
  responses: ApiItem["responses"];
4
4
  }
5
+ export declare function createResponseExamples(responseExamples: any): string[];
6
+ export declare function createResponseExample(responseExample: any): string;
5
7
  export declare function createStatusCodes({ responses }: Props): string | undefined;
6
8
  export {};
@@ -6,11 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createStatusCodes = void 0;
9
+ exports.createStatusCodes = exports.createResponseExample = exports.createResponseExamples = void 0;
10
10
  const createDescription_1 = require("./createDescription");
11
11
  const createDetails_1 = require("./createDetails");
12
12
  const createDetailsSummary_1 = require("./createDetailsSummary");
13
- const createSchemaDetails_1 = require("./createSchemaDetails");
13
+ const createResponseSchema_1 = require("./createResponseSchema");
14
14
  const utils_1 = require("./utils");
15
15
  const utils_2 = require("./utils");
16
16
  function createResponseHeaders(responseHeaders) {
@@ -57,17 +57,52 @@ function createResponseExamples(responseExamples) {
57
57
  return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
58
58
  const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
59
59
  let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
60
+ if (typeof exampleValue.value === "object") {
61
+ return (0, utils_1.create)("TabItem", {
62
+ label: `${finalFormattedName}`,
63
+ value: `${finalFormattedName}`,
64
+ children: [
65
+ (0, utils_1.create)("ResponseSamples", {
66
+ responseExample: JSON.stringify(exampleValue.value, null, 2),
67
+ }),
68
+ ],
69
+ });
70
+ }
60
71
  return (0, utils_1.create)("TabItem", {
61
72
  label: `${finalFormattedName}`,
62
73
  value: `${finalFormattedName}`,
63
74
  children: [
64
75
  (0, utils_1.create)("ResponseSamples", {
65
- responseExample: JSON.stringify(exampleValue.value, null, 2),
76
+ responseExample: exampleValue.value,
66
77
  }),
67
78
  ],
68
79
  });
69
80
  });
70
81
  }
82
+ exports.createResponseExamples = createResponseExamples;
83
+ function createResponseExample(responseExample) {
84
+ if (typeof responseExample === "object") {
85
+ return (0, utils_1.create)("TabItem", {
86
+ label: `Example`,
87
+ value: `Example`,
88
+ children: [
89
+ (0, utils_1.create)("ResponseSamples", {
90
+ responseExample: JSON.stringify(responseExample, null, 2),
91
+ }),
92
+ ],
93
+ });
94
+ }
95
+ return (0, utils_1.create)("TabItem", {
96
+ label: `Example`,
97
+ value: `Example`,
98
+ children: [
99
+ (0, utils_1.create)("ResponseSamples", {
100
+ responseExample: responseExample,
101
+ }),
102
+ ],
103
+ });
104
+ }
105
+ exports.createResponseExample = createResponseExample;
71
106
  function createStatusCodes({ responses }) {
72
107
  if (responses === undefined) {
73
108
  return undefined;
@@ -79,11 +114,10 @@ function createStatusCodes({ responses }) {
79
114
  return (0, utils_1.create)("div", {
80
115
  children: [
81
116
  (0, utils_1.create)("ApiTabs", {
117
+ // TODO: determine if we should persist status code selection
118
+ // groupId: "api-tabs",
82
119
  children: codes.map((code) => {
83
120
  const responseHeaders = responses[code].headers;
84
- const responseContent = responses[code].content;
85
- const responseContentKey = responseContent && Object.keys(responseContent)[0];
86
- const responseExamples = responseContentKey && responseContent[responseContentKey].examples;
87
121
  return (0, utils_1.create)("TabItem", {
88
122
  label: code,
89
123
  value: code,
@@ -91,62 +125,30 @@ function createStatusCodes({ responses }) {
91
125
  (0, utils_1.create)("div", {
92
126
  children: (0, createDescription_1.createDescription)(responses[code].description),
93
127
  }),
94
- (0, utils_2.guard)(responseExamples, () => (0, utils_1.create)("SchemaTabs", {
95
- children: [
96
- (0, utils_1.create)("TabTtem", {
97
- label: "Schema",
98
- value: "Schema",
99
- children: [
100
- responseHeaders &&
101
- (0, createDetails_1.createDetails)({
102
- "data-collaposed": false,
103
- open: true,
104
- style: { textAlign: "left" },
105
- children: [
106
- (0, createDetailsSummary_1.createDetailsSummary)({
107
- children: [
108
- (0, utils_1.create)("strong", {
109
- children: "Response Headers",
110
- }),
111
- ],
112
- }),
113
- createResponseHeaders(responseHeaders),
114
- ],
115
- }),
116
- (0, utils_1.create)("div", {
117
- children: (0, createSchemaDetails_1.createSchemaDetails)({
118
- title: "Schema",
119
- body: {
120
- content: responses[code].content,
121
- },
128
+ responseHeaders &&
129
+ (0, createDetails_1.createDetails)({
130
+ "data-collaposed": false,
131
+ open: true,
132
+ style: { textAlign: "left", marginBottom: "1rem" },
133
+ children: [
134
+ (0, createDetailsSummary_1.createDetailsSummary)({
135
+ children: [
136
+ (0, utils_1.create)("strong", {
137
+ children: "Response Headers",
122
138
  }),
123
- }),
124
- ],
125
- }),
126
- createResponseExamples(responseExamples),
127
- ],
128
- })),
129
- (0, utils_2.guard)(responseHeaders, () => (0, createDetails_1.createDetails)({
130
- "data-collaposed": false,
131
- open: true,
132
- style: { textAlign: "left" },
133
- children: [
134
- (0, createDetailsSummary_1.createDetailsSummary)({
135
- children: [
136
- (0, utils_1.create)("strong", { children: "Response Headers" }),
137
- ],
138
- }),
139
- createResponseHeaders(responseHeaders),
140
- ],
141
- })),
142
- (0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
143
- children: (0, createSchemaDetails_1.createSchemaDetails)({
139
+ ],
140
+ }),
141
+ createResponseHeaders(responseHeaders),
142
+ ],
143
+ }),
144
+ (0, utils_1.create)("div", {
145
+ children: (0, createResponseSchema_1.createResponseSchema)({
144
146
  title: "Schema",
145
147
  body: {
146
148
  content: responses[code].content,
147
149
  },
148
150
  }),
149
- })),
151
+ }),
150
152
  ],
151
153
  });
152
154
  }),
@@ -23,6 +23,7 @@ const utils_1 = require("./utils");
23
23
  function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
24
24
  return (0, utils_1.render)([
25
25
  `import ApiTabs from "@theme/ApiTabs";\n`,
26
+ `import MimeTabs from "@theme/MimeTabs";\n`,
26
27
  `import ParamsItem from "@theme/ParamsItem";\n`,
27
28
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
28
29
  `import SchemaItem from "@theme/SchemaItem"\n`,
@@ -36,7 +37,10 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
36
37
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
37
38
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
38
39
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "cookie" }),
39
- (0, createRequestBodyDetails_1.createRequestBodyDetails)({ title: "Request Body", body: requestBody }),
40
+ (0, createRequestBodyDetails_1.createRequestBodyDetails)({
41
+ title: "Request Body",
42
+ body: requestBody,
43
+ }),
40
44
  (0, createStatusCodes_1.createStatusCodes)({ responses }),
41
45
  ]);
42
46
  }
@@ -11,11 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.sampleFromSchema = void 0;
13
13
  const chalk_1 = __importDefault(require("chalk"));
14
+ const createRequestSchema_1 = require("../markdown/createRequestSchema");
14
15
  const primitives = {
15
16
  string: {
16
17
  default: () => "string",
17
18
  email: () => "user@example.com",
18
19
  date: () => new Date().toISOString().substring(0, 10),
20
+ "date-time": () => new Date().toISOString().substring(0, 10),
19
21
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
20
22
  hostname: () => "example.com",
21
23
  ipv4: () => "198.51.100.42",
@@ -41,21 +43,15 @@ const sampleFromSchema = (schema = {}) => {
41
43
  return example;
42
44
  }
43
45
  if (allOf) {
44
- // TODO: We are just assuming it will always be an object for now
45
- let obj = {
46
- type: "object",
47
- properties: {},
48
- required: [], // NOTE: We shouldn't need to worry about required
49
- };
50
- for (let item of allOf) {
51
- if (item.properties) {
52
- obj.properties = {
53
- ...obj.properties,
54
- ...item.properties,
55
- };
46
+ const { mergedSchemas } = (0, createRequestSchema_1.mergeAllOf)(allOf);
47
+ if (mergedSchemas.properties) {
48
+ for (const [key, value] of Object.entries(mergedSchemas.properties)) {
49
+ if (value.readOnly && value.readOnly === true) {
50
+ delete mergedSchemas.properties[key];
51
+ }
56
52
  }
57
53
  }
58
- return (0, exports.sampleFromSchema)(obj);
54
+ return (0, exports.sampleFromSchema)(mergedSchemas);
59
55
  }
60
56
  if (!type) {
61
57
  if (properties) {
@@ -71,6 +67,20 @@ const sampleFromSchema = (schema = {}) => {
71
67
  if (type === "object") {
72
68
  let obj = {};
73
69
  for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
70
+ if (prop.properties) {
71
+ for (const [key, value] of Object.entries(prop.properties)) {
72
+ if (value.readOnly && value.readOnly === true) {
73
+ delete prop.properties[key];
74
+ }
75
+ }
76
+ }
77
+ if (prop.items && prop.items.properties) {
78
+ for (const [key, value] of Object.entries(prop.items.properties)) {
79
+ if (value.readOnly && value.readOnly === true) {
80
+ delete prop.items.properties[key];
81
+ }
82
+ }
83
+ }
74
84
  if (prop.deprecated) {
75
85
  continue;
76
86
  }
@@ -93,6 +103,9 @@ const sampleFromSchema = (schema = {}) => {
93
103
  }
94
104
  return normalizeArray(schema.enum)[0];
95
105
  }
106
+ if (schema.readOnly && schema.readOnly === true) {
107
+ return undefined;
108
+ }
96
109
  return primitive(schema);
97
110
  }
98
111
  catch (err) {
@@ -106,7 +119,7 @@ function primitive(schema = {}) {
106
119
  if (type === undefined) {
107
120
  return;
108
121
  }
109
- let fn = primitives[type].default;
122
+ let fn = schema.default ? () => schema.default : primitives[type].default;
110
123
  if (format !== undefined) {
111
124
  fn = primitives[type][format] || fn;
112
125
  }
@@ -6,7 +6,7 @@ interface OpenApiFiles {
6
6
  data: OpenApiObject;
7
7
  }
8
8
  export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
9
- export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
9
+ export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
10
10
  export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
11
11
  export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
12
12
  export {};
@@ -59,7 +59,7 @@ async function createPostmanCollection(openapiData) {
59
59
  return await jsonToCollection(data);
60
60
  }
61
61
  function createItems(openapiData, sidebarOptions) {
62
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
62
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
63
63
  // TODO: Find a better way to handle this
64
64
  let items = [];
65
65
  const infoId = (0, kebabCase_1.default)(openapiData.info.title);
@@ -100,8 +100,8 @@ function createItems(openapiData, sidebarOptions) {
100
100
  securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
101
101
  info: {
102
102
  ...openapiData.info,
103
- tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
104
- title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
103
+ tags: openapiData.tags,
104
+ title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
105
105
  logo: openapiData.info["x-logo"],
106
106
  darkLogo: openapiData.info["x-dark-logo"],
107
107
  },
@@ -111,18 +111,18 @@ function createItems(openapiData, sidebarOptions) {
111
111
  for (let [path, pathObject] of Object.entries(openapiData.paths)) {
112
112
  const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
113
113
  for (let [method, operationObject] of Object.entries({ ...rest })) {
114
- const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
114
+ const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
115
115
  if (operationObject.description === undefined) {
116
116
  operationObject.description =
117
- (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
117
+ (_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
118
118
  }
119
119
  const baseId = operationObject.operationId
120
120
  ? (0, kebabCase_1.default)(operationObject.operationId)
121
121
  : (0, kebabCase_1.default)(operationObject.summary);
122
- const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
123
- const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
122
+ const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
123
+ const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
124
124
  // Add security schemes so we know how to handle security.
125
- const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
125
+ const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
126
126
  // Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
127
127
  if (securitySchemes) {
128
128
  for (let securityScheme of Object.values(securitySchemes)) {
@@ -132,10 +132,21 @@ function createItems(openapiData, sidebarOptions) {
132
132
  }
133
133
  }
134
134
  let jsonRequestBodyExample;
135
- const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
135
+ const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
136
136
  if (body === null || body === void 0 ? void 0 : body.schema) {
137
137
  jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
138
138
  }
139
+ // Handle vendor JSON media types
140
+ const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
141
+ if (bodyContent) {
142
+ const firstBodyContentKey = Object.keys(bodyContent)[0];
143
+ if (firstBodyContentKey.endsWith("+json")) {
144
+ const firstBody = bodyContent[firstBodyContentKey];
145
+ if (firstBody === null || firstBody === void 0 ? void 0 : firstBody.schema) {
146
+ jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(firstBody.schema);
147
+ }
148
+ }
149
+ }
139
150
  // TODO: Don't include summary temporarilly
140
151
  const { summary, ...defaults } = operationObject;
141
152
  const apiPage = {
@@ -148,7 +159,7 @@ function createItems(openapiData, sidebarOptions) {
148
159
  frontMatter: {},
149
160
  api: {
150
161
  ...defaults,
151
- tags: (_q = operationObject.tags) === null || _q === void 0 ? void 0 : _q.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
162
+ tags: operationObject.tags,
152
163
  method,
153
164
  path,
154
165
  servers,
@@ -30,7 +30,7 @@ export interface InfoObject {
30
30
  contact?: ContactObject;
31
31
  license?: LicenseObject;
32
32
  version: string;
33
- tags?: String[];
33
+ tags?: TagObject[];
34
34
  "x-logo"?: LogoObject;
35
35
  "x-dark-logo"?: LogoObject;
36
36
  logo?: LogoObject;
@@ -1,4 +1,4 @@
1
1
  import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
2
2
  import { TagObject } from "../openapi/types";
3
3
  import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
4
- export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
4
+ export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string): ProcessedSidebar;
@@ -33,9 +33,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
33
33
  };
34
34
  });
35
35
  // TODO: make sure we only take the first tag
36
- const apiTags = (0, uniq_1.default)(apiItems
36
+ const operationTags = (0, uniq_1.default)(apiItems
37
37
  .flatMap((item) => item.api.tags)
38
38
  .filter((item) => !!item));
39
+ // Only include operation tags that are globally defined
40
+ const apiTags = [];
41
+ tags.flat().forEach((tag) => {
42
+ if (operationTags.includes(tag.name)) {
43
+ apiTags.push(tag.name);
44
+ }
45
+ });
39
46
  const basePath = docPath
40
47
  ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
41
48
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
@@ -66,11 +73,12 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
66
73
  }
67
74
  const tagged = apiTags
68
75
  .map((tag) => {
76
+ var _a;
69
77
  // Map info object to tag
70
78
  const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
71
79
  const tagObject = tags.flat().find((t) => {
72
80
  var _a;
73
- return (_a = (tag === t.name || tag === t["x-displayName"])) !== null && _a !== void 0 ? _a : {
81
+ return (_a = tag === t.name) !== null && _a !== void 0 ? _a : {
74
82
  name: tag,
75
83
  description: `${tag} Index`,
76
84
  };
@@ -105,7 +113,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
105
113
  }
106
114
  return {
107
115
  type: "category",
108
- label: tag,
116
+ label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
109
117
  link: linkConfig,
110
118
  collapsible: sidebarCollapsible,
111
119
  collapsed: sidebarCollapsed,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "1.1.4",
4
+ "version": "1.1.7",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -66,6 +66,5 @@
66
66
  },
67
67
  "engines": {
68
68
  "node": ">=14"
69
- },
70
- "gitHead": "dadb0aa5d3516b3020ff1d94288efd6f136e02ba"
69
+ }
71
70
  }