docusaurus-plugin-openapi-docs 0.0.0-1069 → 0.0.0-1073

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.
@@ -77,7 +77,7 @@ const sampleFromSchema = (schema = {}, context) => {
77
77
  try {
78
78
  // deep copy schema before processing
79
79
  let schemaCopy = JSON.parse(JSON.stringify(schema));
80
- let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
80
+ let { type, example, allOf, properties, items, oneOf, anyOf, const: constant, } = schemaCopy;
81
81
  if (example !== undefined) {
82
82
  return example;
83
83
  }
@@ -169,6 +169,9 @@ const sampleFromSchema = (schema = {}, context) => {
169
169
  if (shouldExcludeProperty(schemaCopy, context)) {
170
170
  return undefined;
171
171
  }
172
+ if (constant) {
173
+ return constant;
174
+ }
172
175
  return primitive(schemaCopy);
173
176
  }
174
177
  catch (err) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const createSchemaExample_1 = require("./createSchemaExample");
10
+ describe("sampleFromSchema", () => {
11
+ describe("const support", () => {
12
+ it("should return default string value when const is not present", () => {
13
+ const schema = {
14
+ type: "string",
15
+ };
16
+ const context = { type: "request" };
17
+ const result = (0, createSchemaExample_1.sampleFromSchema)(schema, context);
18
+ expect(result).toBe("string");
19
+ });
20
+ it("should return const value when const is present", () => {
21
+ const schema = {
22
+ type: "string",
23
+ const: "example",
24
+ };
25
+ const context = { type: "request" };
26
+ const result = (0, createSchemaExample_1.sampleFromSchema)(schema, context);
27
+ expect(result).toBe("example");
28
+ });
29
+ it("should handle anyOf with const values", () => {
30
+ const schema = {
31
+ type: "string",
32
+ anyOf: [
33
+ {
34
+ type: "string",
35
+ const: "dog",
36
+ },
37
+ {
38
+ type: "string",
39
+ const: "cat",
40
+ },
41
+ ],
42
+ };
43
+ const context = { type: "request" };
44
+ const result = (0, createSchemaExample_1.sampleFromSchema)(schema, context);
45
+ expect(result).toBe("dog");
46
+ });
47
+ });
48
+ });
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-1069",
4
+ "version": "0.0.0-1073",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=14"
67
67
  },
68
- "gitHead": "68650d41c8460a20c228d851f869e495c5608796"
68
+ "gitHead": "d6c29401ee71e04536c4ece3054c414a79e750da"
69
69
  }
@@ -0,0 +1,57 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { sampleFromSchema } from "./createSchemaExample";
9
+ import { SchemaObject } from "./types";
10
+
11
+ describe("sampleFromSchema", () => {
12
+ describe("const support", () => {
13
+ it("should return default string value when const is not present", () => {
14
+ const schema: SchemaObject = {
15
+ type: "string",
16
+ };
17
+ const context = { type: "request" as const };
18
+
19
+ const result = sampleFromSchema(schema, context);
20
+
21
+ expect(result).toBe("string");
22
+ });
23
+
24
+ it("should return const value when const is present", () => {
25
+ const schema: SchemaObject = {
26
+ type: "string",
27
+ const: "example",
28
+ };
29
+ const context = { type: "request" as const };
30
+
31
+ const result = sampleFromSchema(schema, context);
32
+
33
+ expect(result).toBe("example");
34
+ });
35
+
36
+ it("should handle anyOf with const values", () => {
37
+ const schema: SchemaObject = {
38
+ type: "string",
39
+ anyOf: [
40
+ {
41
+ type: "string",
42
+ const: "dog",
43
+ },
44
+ {
45
+ type: "string",
46
+ const: "cat",
47
+ },
48
+ ],
49
+ };
50
+ const context = { type: "request" as const };
51
+
52
+ const result = sampleFromSchema(schema, context);
53
+
54
+ expect(result).toBe("dog");
55
+ });
56
+ });
57
+ });
@@ -111,7 +111,16 @@ export const sampleFromSchema = (
111
111
  try {
112
112
  // deep copy schema before processing
113
113
  let schemaCopy = JSON.parse(JSON.stringify(schema));
114
- let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
114
+ let {
115
+ type,
116
+ example,
117
+ allOf,
118
+ properties,
119
+ items,
120
+ oneOf,
121
+ anyOf,
122
+ const: constant,
123
+ } = schemaCopy;
115
124
 
116
125
  if (example !== undefined) {
117
126
  return example;
@@ -218,6 +227,10 @@ export const sampleFromSchema = (
218
227
  return undefined;
219
228
  }
220
229
 
230
+ if (constant) {
231
+ return constant;
232
+ }
233
+
221
234
  return primitive(schemaCopy);
222
235
  } catch (err) {
223
236
  console.error(