docusaurus-plugin-openapi-docs 0.0.0-421 → 0.0.0-424

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;
@@ -299,7 +299,7 @@ export async function readOpenapiFiles(
299
299
  export async function processOpenapiFiles(
300
300
  files: OpenApiFiles[],
301
301
  sidebarOptions: SidebarOptions
302
- ): Promise<[ApiMetadata[], TagObject[]]> {
302
+ ): Promise<[ApiMetadata[], TagObject[][]]> {
303
303
  const promises = files.map(async (file) => {
304
304
  if (file.data !== undefined) {
305
305
  const processedFile = await processOpenapiFile(file.data, sidebarOptions);
@@ -334,7 +334,7 @@ export async function processOpenapiFiles(
334
334
  // Remove undefined tags due to transient parsing errors
335
335
  return x !== undefined;
336
336
  });
337
- return [items as ApiMetadata[], tags[0] as TagObject[]];
337
+ return [items as ApiMetadata[], tags as TagObject[][]];
338
338
  }
339
339
 
340
340
  export async function processOpenapiFile(
@@ -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;
@@ -68,7 +68,7 @@ function groupByTags(
68
68
 
69
69
  // Only include operation tags that are globally defined
70
70
  const apiTags: string[] = [];
71
- tags.forEach((tag) => {
71
+ tags.flat().forEach((tag) => {
72
72
  if (operationTags.includes(tag.name!)) {
73
73
  apiTags.push(tag.name!);
74
74
  }
@@ -199,7 +199,7 @@ export default function generateSidebarSlice(
199
199
  sidebarOptions: SidebarOptions,
200
200
  options: APIOptions,
201
201
  api: ApiMetadata[],
202
- tags: TagObject[],
202
+ tags: TagObject[][],
203
203
  docPath: string
204
204
  ) {
205
205
  let sidebarSlice: ProcessedSidebar = [];