docusaurus-plugin-openapi-docs 0.0.0-419 → 0.0.0-422

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.
@@ -10,7 +10,7 @@ exports.createStatusCodes = 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) {
@@ -114,7 +114,7 @@ function createStatusCodes({ responses }) {
114
114
  ],
115
115
  }),
116
116
  (0, utils_1.create)("div", {
117
- children: (0, createSchemaDetails_1.createSchemaDetails)({
117
+ children: (0, createResponseSchema_1.createResponseSchema)({
118
118
  title: "Schema",
119
119
  body: {
120
120
  content: responses[code].content,
@@ -140,7 +140,7 @@ function createStatusCodes({ responses }) {
140
140
  ],
141
141
  })),
142
142
  (0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
143
- children: (0, createSchemaDetails_1.createSchemaDetails)({
143
+ children: (0, createResponseSchema_1.createResponseSchema)({
144
144
  title: "Schema",
145
145
  body: {
146
146
  content: responses[code].content,
@@ -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, _r;
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,12 +132,12 @@ 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
139
  // Handle vendor JSON media types
140
- const bodyContent = (_q = operationObject.requestBody) === null || _q === void 0 ? void 0 : _q.content;
140
+ const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
141
141
  if (bodyContent) {
142
142
  const firstBodyContentKey = Object.keys(bodyContent)[0];
143
143
  if (firstBodyContentKey.endsWith("+json")) {
@@ -159,7 +159,7 @@ function createItems(openapiData, sidebarOptions) {
159
159
  frontMatter: {},
160
160
  api: {
161
161
  ...defaults,
162
- tags: (_r = operationObject.tags) === null || _r === void 0 ? void 0 : _r.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
162
+ tags: operationObject.tags,
163
163
  method,
164
164
  path,
165
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": "0.0.0-419",
4
+ "version": "0.0.0-422",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=14"
69
69
  },
70
- "gitHead": "c5df2d9c69e2d3881b329ba3586cbc3853ba553b"
70
+ "gitHead": "14d14041e6826bf3a0c6e851d3d8a2ac464811f4"
71
71
  }
@@ -6,7 +6,7 @@
6
6
  * ========================================================================== */
7
7
 
8
8
  import { MediaTypeObject } from "../openapi/types";
9
- import { createSchemaDetails } from "./createSchemaDetails";
9
+ import { createRequestSchema } from "./createRequestSchema";
10
10
 
11
11
  interface Props {
12
12
  title: string;
@@ -20,5 +20,5 @@ interface Props {
20
20
  }
21
21
 
22
22
  export function createRequestBodyDetails({ title, body }: Props): any {
23
- return createSchemaDetails({ title, body });
23
+ return createRequestSchema({ title, body });
24
24
  }
@@ -17,7 +17,7 @@ const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
17
17
  /**
18
18
  * Returns a merged representation of allOf array of schemas.
19
19
  */
20
- function mergeAllOf(allOf: SchemaObject[]) {
20
+ export function mergeAllOf(allOf: SchemaObject[]) {
21
21
  const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
22
22
  resolvers: {
23
23
  readOnly: function () {
@@ -534,8 +534,6 @@ function createEdges({
534
534
  }: EdgeProps): any {
535
535
  const schemaName = getSchemaName(schema);
536
536
 
537
- // if (name === "id") console.log(name, schema, required);
538
-
539
537
  if (discriminator !== undefined && discriminator.propertyName === name) {
540
538
  return createPropertyDiscriminator(
541
539
  name,
@@ -578,6 +576,10 @@ function createEdges({
578
576
  return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
579
577
  }
580
578
 
579
+ if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
580
+ return undefined;
581
+ }
582
+
581
583
  return create("SchemaItem", {
582
584
  collapsible: false,
583
585
  name,
@@ -585,7 +587,7 @@ function createEdges({
585
587
  schemaDescription: mergedSchemas.description,
586
588
  schemaName: schemaName,
587
589
  qualifierMessage: getQualifierMessage(schema),
588
- defaultValue: schema.default,
590
+ defaultValue: mergedSchemas.default,
589
591
  });
590
592
  }
591
593
 
@@ -602,6 +604,10 @@ function createEdges({
602
604
  return createDetailsNode(name, schemaName, schema, required);
603
605
  }
604
606
 
607
+ if (schema.readOnly && schema.readOnly === true) {
608
+ return undefined;
609
+ }
610
+
605
611
  // primitives and array of non-objects
606
612
  return create("SchemaItem", {
607
613
  collapsible: false,
@@ -694,7 +700,7 @@ interface Props {
694
700
  };
695
701
  }
696
702
 
697
- export function createSchemaDetails({ title, body, ...rest }: Props) {
703
+ export function createRequestSchema({ title, body, ...rest }: Props) {
698
704
  if (
699
705
  body === undefined ||
700
706
  body.content === undefined ||