docusaurus-plugin-openapi-docs 0.0.0-420 → 0.0.0-423

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.
@@ -9,7 +9,7 @@ import { ApiItem } from "../types";
9
9
  import { createDescription } from "./createDescription";
10
10
  import { createDetails } from "./createDetails";
11
11
  import { createDetailsSummary } from "./createDetailsSummary";
12
- import { createSchemaDetails } from "./createSchemaDetails";
12
+ import { createResponseSchema } from "./createResponseSchema";
13
13
  import { create } from "./utils";
14
14
  import { guard } from "./utils";
15
15
 
@@ -79,7 +79,11 @@ function createResponseExamples(responseExamples: any) {
79
79
  value: `${finalFormattedName}`,
80
80
  children: [
81
81
  create("ResponseSamples", {
82
- responseExample: JSON.stringify(exampleValue.value, null, 2),
82
+ responseExample: JSON.stringify(
83
+ exampleValue.value ?? exampleValue,
84
+ null,
85
+ 2
86
+ ),
83
87
  }),
84
88
  ],
85
89
  });
@@ -106,7 +110,9 @@ export function createStatusCodes({ responses }: Props) {
106
110
  const responseContentKey: any =
107
111
  responseContent && Object.keys(responseContent)[0];
108
112
  const responseExamples: any =
109
- responseContentKey && responseContent[responseContentKey].examples;
113
+ responseContentKey &&
114
+ (responseContent[responseContentKey].examples ||
115
+ responseContent[responseContentKey].example);
110
116
 
111
117
  return create("TabItem", {
112
118
  label: code,
@@ -126,7 +132,7 @@ export function createStatusCodes({ responses }: Props) {
126
132
  createDetails({
127
133
  "data-collaposed": false,
128
134
  open: true,
129
- style: { textAlign: "left" },
135
+ style: { textAlign: "left", marginBottom: "1rem" },
130
136
  children: [
131
137
  createDetailsSummary({
132
138
  children: [
@@ -139,7 +145,7 @@ export function createStatusCodes({ responses }: Props) {
139
145
  ],
140
146
  }),
141
147
  create("div", {
142
- children: createSchemaDetails({
148
+ children: createResponseSchema({
143
149
  title: "Schema",
144
150
  body: {
145
151
  content: responses[code].content,
@@ -152,7 +158,7 @@ export function createStatusCodes({ responses }: Props) {
152
158
  ],
153
159
  })
154
160
  ),
155
- guard(responseHeaders, () =>
161
+ guard(responseHeaders && !responseExamples, () =>
156
162
  createDetails({
157
163
  "data-collaposed": false,
158
164
  open: true,
@@ -169,7 +175,7 @@ export function createStatusCodes({ responses }: Props) {
169
175
  ),
170
176
  guard(!responseExamples, () =>
171
177
  create("div", {
172
- children: createSchemaDetails({
178
+ children: createResponseSchema({
173
179
  title: "Schema",
174
180
  body: {
175
181
  content: responses[code].content,
@@ -7,6 +7,7 @@
7
7
 
8
8
  import chalk from "chalk";
9
9
 
10
+ import { mergeAllOf } from "../markdown/createRequestSchema";
10
11
  import { SchemaObject } from "./types";
11
12
 
12
13
  interface OASTypeToTypeMap {
@@ -29,6 +30,7 @@ const primitives: Primitives = {
29
30
  default: () => "string",
30
31
  email: () => "user@example.com",
31
32
  date: () => new Date().toISOString().substring(0, 10),
33
+ "date-time": () => new Date().toISOString().substring(0, 10),
32
34
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
33
35
  hostname: () => "example.com",
34
36
  ipv4: () => "198.51.100.42",
@@ -58,21 +60,16 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
58
60
  }
59
61
 
60
62
  if (allOf) {
61
- // TODO: We are just assuming it will always be an object for now
62
- let obj: SchemaObject = {
63
- type: "object",
64
- properties: {},
65
- required: [], // NOTE: We shouldn't need to worry about required
66
- };
67
- for (let item of allOf) {
68
- if (item.properties) {
69
- obj.properties = {
70
- ...obj.properties,
71
- ...item.properties,
72
- };
63
+ const { mergedSchemas }: { mergedSchemas: SchemaObject } =
64
+ mergeAllOf(allOf);
65
+ if (mergedSchemas.properties) {
66
+ for (const [key, value] of Object.entries(mergedSchemas.properties)) {
67
+ if (value.readOnly && value.readOnly === true) {
68
+ delete mergedSchemas.properties[key];
69
+ }
73
70
  }
74
71
  }
75
- return sampleFromSchema(obj);
72
+ return sampleFromSchema(mergedSchemas);
76
73
  }
77
74
 
78
75
  if (!type) {
@@ -88,6 +85,22 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
88
85
  if (type === "object") {
89
86
  let obj: any = {};
90
87
  for (let [name, prop] of Object.entries(properties ?? {})) {
88
+ if (prop.properties) {
89
+ for (const [key, value] of Object.entries(prop.properties)) {
90
+ if (value.readOnly && value.readOnly === true) {
91
+ delete prop.properties[key];
92
+ }
93
+ }
94
+ }
95
+
96
+ if (prop.items && prop.items.properties) {
97
+ for (const [key, value] of Object.entries(prop.items.properties)) {
98
+ if (value.readOnly && value.readOnly === true) {
99
+ delete prop.items.properties[key];
100
+ }
101
+ }
102
+ }
103
+
91
104
  if (prop.deprecated) {
92
105
  continue;
93
106
  }
@@ -115,6 +128,10 @@ export const sampleFromSchema = (schema: SchemaObject = {}): any => {
115
128
  return normalizeArray(schema.enum)[0];
116
129
  }
117
130
 
131
+ if (schema.readOnly && schema.readOnly === true) {
132
+ return undefined;
133
+ }
134
+
118
135
  return primitive(schema);
119
136
  } catch (err) {
120
137
  console.error(
@@ -131,7 +148,7 @@ function primitive(schema: SchemaObject = {}) {
131
148
  return;
132
149
  }
133
150
 
134
- let fn = primitives[type].default;
151
+ let fn = schema.default ? () => schema.default : primitives[type].default;
135
152
 
136
153
  if (format !== undefined) {
137
154
  fn = primitives[type][format] || fn;
@@ -124,9 +124,7 @@ function createItems(
124
124
  securitySchemes: openapiData.components?.securitySchemes,
125
125
  info: {
126
126
  ...openapiData.info,
127
- tags: openapiData.tags?.map((tagName) =>
128
- getTagDisplayName(tagName.name!, openapiData.tags ?? [])
129
- ),
127
+ tags: openapiData.tags,
130
128
  title: openapiData.info.title ?? "Introduction",
131
129
  logo: openapiData.info["x-logo"]! as any,
132
130
  darkLogo: openapiData.info["x-dark-logo"]! as any,
@@ -200,9 +198,7 @@ function createItems(
200
198
  frontMatter: {},
201
199
  api: {
202
200
  ...defaults,
203
- tags: operationObject.tags?.map((tagName) =>
204
- getTagDisplayName(tagName, openapiData.tags ?? [])
205
- ),
201
+ tags: operationObject.tags,
206
202
  method,
207
203
  path,
208
204
  servers,
@@ -303,7 +299,7 @@ export async function readOpenapiFiles(
303
299
  export async function processOpenapiFiles(
304
300
  files: OpenApiFiles[],
305
301
  sidebarOptions: SidebarOptions
306
- ): Promise<[ApiMetadata[], TagObject[]]> {
302
+ ): Promise<[ApiMetadata[], TagObject[][]]> {
307
303
  const promises = files.map(async (file) => {
308
304
  if (file.data !== undefined) {
309
305
  const processedFile = await processOpenapiFile(file.data, sidebarOptions);
@@ -338,7 +334,7 @@ export async function processOpenapiFiles(
338
334
  // Remove undefined tags due to transient parsing errors
339
335
  return x !== undefined;
340
336
  });
341
- return [items as ApiMetadata[], tags[0] as TagObject[]];
337
+ return [items as ApiMetadata[], tags as TagObject[][]];
342
338
  }
343
339
 
344
340
  export async function processOpenapiFile(
@@ -41,7 +41,7 @@ export interface InfoObject {
41
41
  contact?: ContactObject;
42
42
  license?: LicenseObject;
43
43
  version: string;
44
- tags?: String[];
44
+ tags?: TagObject[];
45
45
  "x-logo"?: LogoObject;
46
46
  "x-dark-logo"?: LogoObject;
47
47
  logo?: LogoObject;
@@ -37,7 +37,7 @@ function groupByTags(
37
37
  items: ApiPageMetadata[],
38
38
  sidebarOptions: SidebarOptions,
39
39
  options: APIOptions,
40
- tags: TagObject[],
40
+ tags: TagObject[][],
41
41
  docPath: string
42
42
  ): ProcessedSidebar {
43
43
  const { outputDir, label } = options;
@@ -65,9 +65,10 @@ function groupByTags(
65
65
  .flatMap((item) => item.api.tags)
66
66
  .filter((item): item is string => !!item)
67
67
  );
68
+
69
+ // Only include operation tags that are globally defined
68
70
  const apiTags: string[] = [];
69
- // eslint-disable-next-line array-callback-return
70
- tags.map((tag) => {
71
+ tags.flat().forEach((tag) => {
71
72
  if (operationTags.includes(tag.name!)) {
72
73
  apiTags.push(tag.name!);
73
74
  }
@@ -114,7 +115,7 @@ function groupByTags(
114
115
  );
115
116
  const tagObject = tags.flat().find(
116
117
  (t) =>
117
- (tag === t.name || tag === t["x-displayName"]) ?? {
118
+ tag === t.name ?? {
118
119
  name: tag,
119
120
  description: `${tag} Index`,
120
121
  }
@@ -155,7 +156,7 @@ function groupByTags(
155
156
 
156
157
  return {
157
158
  type: "category" as const,
158
- label: tag,
159
+ label: tagObject?.["x-displayName"] ?? tag,
159
160
  link: linkConfig,
160
161
  collapsible: sidebarCollapsible,
161
162
  collapsed: sidebarCollapsed,
@@ -198,7 +199,7 @@ export default function generateSidebarSlice(
198
199
  sidebarOptions: SidebarOptions,
199
200
  options: APIOptions,
200
201
  api: ApiMetadata[],
201
- tags: TagObject[],
202
+ tags: TagObject[][],
202
203
  docPath: string
203
204
  ) {
204
205
  let sidebarSlice: ProcessedSidebar = [];