docusaurus-plugin-openapi-docs 0.0.0-1155 → 0.0.0-1157

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 @@ import { LicenseObject } from "../openapi/types";
10
10
 
11
11
  export function createLicense(license: LicenseObject) {
12
12
  if (!license || !Object.keys(license).length) return "";
13
- const { name, url } = license;
13
+ const { name, url, identifier } = license;
14
14
 
15
15
  return create("div", {
16
16
  style: {
@@ -29,6 +29,12 @@ export function createLicense(license: LicenseObject) {
29
29
  children: name ?? url,
30
30
  })
31
31
  ),
32
+ guard(identifier, () =>
33
+ create("a", {
34
+ href: `https://spdx.org/licenses/${identifier}.html`,
35
+ children: name ?? identifier,
36
+ })
37
+ ),
32
38
  ],
33
39
  });
34
40
  }
@@ -17,7 +17,7 @@ import {
17
17
  import { createDescription } from "./createDescription";
18
18
  import { createDetails } from "./createDetails";
19
19
  import { createDetailsSummary } from "./createDetailsSummary";
20
- import { getQualifierMessage, getSchemaName } from "./schema";
20
+ import { getSchemaName } from "./schema";
21
21
  import { create, guard } from "./utils";
22
22
  import { SchemaObject } from "../openapi/types";
23
23
 
@@ -140,7 +140,6 @@ function createProperties(schema: SchemaObject) {
140
140
  name: "",
141
141
  required: false,
142
142
  schemaName: "object",
143
- qualifierMessage: undefined,
144
143
  schema: {},
145
144
  });
146
145
  }
@@ -169,7 +168,6 @@ function createAdditionalProperties(schema: SchemaObject) {
169
168
  name: "property name*",
170
169
  required: false,
171
170
  schemaName: "any",
172
- qualifierMessage: getQualifierMessage(schema),
173
171
  schema: schema,
174
172
  collapsible: false,
175
173
  discriminator: false,
@@ -209,7 +207,6 @@ function createAdditionalProperties(schema: SchemaObject) {
209
207
  name: "property name*",
210
208
  required: false,
211
209
  schemaName: schemaName,
212
- qualifierMessage: getQualifierMessage(schema),
213
210
  schema: additionalProperties,
214
211
  collapsible: false,
215
212
  discriminator: false,
@@ -399,12 +396,6 @@ function createDetailsNode(
399
396
  children: createDescription(description),
400
397
  })
401
398
  ),
402
- guard(getQualifierMessage(schema), (message) =>
403
- create("div", {
404
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
405
- children: createDescription(message),
406
- })
407
- ),
408
399
  createNodes(schema, SCHEMA_TYPE),
409
400
  ],
410
401
  }),
@@ -545,14 +536,6 @@ function createPropertyDiscriminator(
545
536
  children: createDescription(description),
546
537
  })
547
538
  ),
548
- guard(getQualifierMessage(discriminator), (message) =>
549
- create("div", {
550
- style: {
551
- paddingLeft: "1rem",
552
- },
553
- children: createDescription(message),
554
- })
555
- ),
556
539
  create("DiscriminatorTabs", {
557
540
  className: "openapi-tabs__discriminator",
558
541
  children: Object.keys(discriminator?.mapping!).map((key, index) => {
@@ -727,7 +710,6 @@ function createEdges({
727
710
  name,
728
711
  required: Array.isArray(required) ? required.includes(name) : required,
729
712
  schemaName: mergedSchemaName,
730
- qualifierMessage: getQualifierMessage(mergedSchemas),
731
713
  schema: mergedSchemas,
732
714
  });
733
715
  }
@@ -738,7 +720,6 @@ function createEdges({
738
720
  name,
739
721
  required: Array.isArray(required) ? required.includes(name) : required,
740
722
  schemaName: schemaName,
741
- qualifierMessage: getQualifierMessage(schema),
742
723
  schema: schema,
743
724
  });
744
725
  }
@@ -823,17 +804,7 @@ export function createNodes(
823
804
  marginTop: ".5rem",
824
805
  marginBottom: ".5rem",
825
806
  },
826
- children: [
827
- createDescription(schema.type),
828
- guard(getQualifierMessage(schema), (message) =>
829
- create("div", {
830
- style: {
831
- paddingTop: "1rem",
832
- },
833
- children: createDescription(message),
834
- })
835
- ),
836
- ],
807
+ children: [createDescription(schema.type)],
837
808
  });
838
809
  }
839
810
 
@@ -844,17 +815,7 @@ export function createNodes(
844
815
  marginTop: ".5rem",
845
816
  marginBottom: ".5rem",
846
817
  },
847
- children: [
848
- createDescription(schema),
849
- guard(getQualifierMessage(schema), (message) =>
850
- create("div", {
851
- style: {
852
- paddingTop: "1rem",
853
- },
854
- children: createDescription(message),
855
- })
856
- ),
857
- ],
818
+ children: [createDescription(schema)],
858
819
  });
859
820
  }
860
821
 
@@ -66,129 +66,3 @@ export function getSchemaName(
66
66
 
67
67
  return prettyName(schema, circular) ?? "";
68
68
  }
69
-
70
- export function getQualifierMessage(schema?: SchemaObject): string | undefined {
71
- // TODO:
72
- // - uniqueItems
73
- // - maxProperties
74
- // - minProperties
75
- // - multipleOf
76
- if (!schema) {
77
- return undefined;
78
- }
79
-
80
- if (
81
- schema.items &&
82
- schema.minItems === undefined &&
83
- schema.maxItems === undefined
84
- ) {
85
- return getQualifierMessage(schema.items);
86
- }
87
-
88
- let message = "**Possible values:** ";
89
-
90
- let qualifierGroups = [];
91
-
92
- if (schema.items && schema.items.enum) {
93
- if (schema.items.enum) {
94
- qualifierGroups.push(
95
- `[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`
96
- );
97
- }
98
- }
99
-
100
- if (schema.minLength || schema.maxLength) {
101
- let lengthQualifier = "";
102
- let minLength;
103
- let maxLength;
104
- if (schema.minLength && schema.minLength > 1) {
105
- minLength = `\`>= ${schema.minLength} characters\``;
106
- }
107
- if (schema.minLength && schema.minLength === 1) {
108
- minLength = `\`non-empty\``;
109
- }
110
- if (schema.maxLength) {
111
- maxLength = `\`<= ${schema.maxLength} characters\``;
112
- }
113
-
114
- if (minLength && !maxLength) {
115
- lengthQualifier += minLength;
116
- }
117
- if (maxLength && !minLength) {
118
- lengthQualifier += maxLength;
119
- }
120
- if (minLength && maxLength) {
121
- lengthQualifier += `${minLength} and ${maxLength}`;
122
- }
123
-
124
- qualifierGroups.push(lengthQualifier);
125
- }
126
-
127
- if (
128
- schema.minimum != null ||
129
- schema.maximum != null ||
130
- typeof schema.exclusiveMinimum === "number" ||
131
- typeof schema.exclusiveMaximum === "number"
132
- ) {
133
- let minmaxQualifier = "";
134
- let minimum;
135
- let maximum;
136
- if (typeof schema.exclusiveMinimum === "number") {
137
- minimum = `\`> ${schema.exclusiveMinimum}\``;
138
- } else if (schema.minimum != null && !schema.exclusiveMinimum) {
139
- minimum = `\`>= ${schema.minimum}\``;
140
- } else if (schema.minimum != null && schema.exclusiveMinimum === true) {
141
- minimum = `\`> ${schema.minimum}\``;
142
- }
143
- if (typeof schema.exclusiveMaximum === "number") {
144
- maximum = `\`< ${schema.exclusiveMaximum}\``;
145
- } else if (schema.maximum != null && !schema.exclusiveMaximum) {
146
- maximum = `\`<= ${schema.maximum}\``;
147
- } else if (schema.maximum != null && schema.exclusiveMaximum === true) {
148
- maximum = `\`< ${schema.maximum}\``;
149
- }
150
-
151
- if (minimum && !maximum) {
152
- minmaxQualifier += minimum;
153
- }
154
- if (maximum && !minimum) {
155
- minmaxQualifier += maximum;
156
- }
157
- if (minimum && maximum) {
158
- minmaxQualifier += `${minimum} and ${maximum}`;
159
- }
160
-
161
- qualifierGroups.push(minmaxQualifier);
162
- }
163
-
164
- if (schema.pattern) {
165
- qualifierGroups.push(
166
- `Value must match regular expression \`${schema.pattern}\``
167
- );
168
- }
169
-
170
- // Check if discriminator mapping
171
- const discriminator = schema as any;
172
- if (discriminator.mapping) {
173
- const values = Object.keys(discriminator.mapping);
174
- qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
175
- }
176
-
177
- if (schema.enum) {
178
- qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
179
- }
180
-
181
- if (schema.minItems) {
182
- qualifierGroups.push(`\`>= ${schema.minItems}\``);
183
- }
184
-
185
- if (schema.maxItems) {
186
- qualifierGroups.push(`\`<= ${schema.maxItems}\``);
187
- }
188
-
189
- if (qualifierGroups.length === 0) {
190
- return undefined;
191
- }
192
-
193
- return message + qualifierGroups.join(", ");
194
- }
@@ -129,7 +129,9 @@ export function create(
129
129
  } else {
130
130
  // Inline props as usual
131
131
  for (const [key, value] of Object.entries(rest)) {
132
- propString += `\n ${key}={${JSON.stringify(value)}}`;
132
+ if (value !== undefined) {
133
+ propString += `\n ${key}={${JSON.stringify(value)}}`;
134
+ }
133
135
  }
134
136
  }
135
137
 
@@ -65,6 +65,7 @@ export interface ContactObject {
65
65
  export interface LicenseObject {
66
66
  name: string;
67
67
  url?: string;
68
+ identifier?: string;
68
69
  }
69
70
 
70
71
  export interface ServerObject {
@@ -450,116 +450,6 @@ export function getDefinitionName(pointer?: string): string | undefined {
450
450
  return name;
451
451
  }
452
452
 
453
- function humanizeMultipleOfConstraint(
454
- multipleOf: number | undefined
455
- ): string | undefined {
456
- if (multipleOf === undefined) {
457
- return;
458
- }
459
- const strigifiedMultipleOf = multipleOf.toString(10);
460
- if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
461
- return `multiple of ${strigifiedMultipleOf}`;
462
- }
463
- return `decimal places <= ${strigifiedMultipleOf.split(".")[1].length}`;
464
- }
465
-
466
- function humanizeRangeConstraint(
467
- description: string,
468
- min: number | undefined,
469
- max: number | undefined
470
- ): string | undefined {
471
- let stringRange;
472
- if (min !== undefined && max !== undefined) {
473
- if (min === max) {
474
- stringRange = `= ${min} ${description}`;
475
- } else {
476
- stringRange = `[ ${min} .. ${max} ] ${description}`;
477
- }
478
- } else if (max !== undefined) {
479
- stringRange = `<= ${max} ${description}`;
480
- } else if (min !== undefined) {
481
- if (min === 1) {
482
- stringRange = "non-empty";
483
- } else {
484
- stringRange = `>= ${min} ${description}`;
485
- }
486
- }
487
-
488
- return stringRange;
489
- }
490
-
491
- export function humanizeNumberRange(schema: OpenAPISchema): string | undefined {
492
- const minimum =
493
- typeof schema.exclusiveMinimum === "number"
494
- ? Math.min(schema.exclusiveMinimum, schema.minimum ?? Infinity)
495
- : schema.minimum;
496
- const maximum =
497
- typeof schema.exclusiveMaximum === "number"
498
- ? Math.max(schema.exclusiveMaximum, schema.maximum ?? -Infinity)
499
- : schema.maximum;
500
- const exclusiveMinimum =
501
- typeof schema.exclusiveMinimum === "number" || schema.exclusiveMinimum;
502
- const exclusiveMaximum =
503
- typeof schema.exclusiveMaximum === "number" || schema.exclusiveMaximum;
504
-
505
- if (minimum !== undefined && maximum !== undefined) {
506
- return `${exclusiveMinimum ? "( " : "[ "}${minimum} .. ${maximum}${
507
- exclusiveMaximum ? " )" : " ]"
508
- }`;
509
- } else if (maximum !== undefined) {
510
- return `${exclusiveMaximum ? "< " : "<= "}${maximum}`;
511
- } else if (minimum !== undefined) {
512
- return `${exclusiveMinimum ? "> " : ">= "}${minimum}`;
513
- }
514
- }
515
-
516
- export function humanizeConstraints(schema: OpenAPISchema): string[] {
517
- const res: string[] = [];
518
-
519
- const stringRange = humanizeRangeConstraint(
520
- "characters",
521
- schema.minLength,
522
- schema.maxLength
523
- );
524
- if (stringRange !== undefined) {
525
- res.push(stringRange);
526
- }
527
-
528
- const arrayRange = humanizeRangeConstraint(
529
- "items",
530
- schema.minItems,
531
- schema.maxItems
532
- );
533
- if (arrayRange !== undefined) {
534
- res.push(arrayRange);
535
- }
536
-
537
- const propertiesRange = humanizeRangeConstraint(
538
- "properties",
539
- schema.minProperties,
540
- schema.maxProperties
541
- );
542
- if (propertiesRange !== undefined) {
543
- res.push(propertiesRange);
544
- }
545
-
546
- const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf);
547
- if (multipleOfConstraint !== undefined) {
548
- res.push(multipleOfConstraint);
549
- }
550
-
551
- const numberRange = humanizeNumberRange(schema);
552
- if (numberRange !== undefined) {
553
- res.push(numberRange);
554
- }
555
-
556
- if (schema.uniqueItems) {
557
- res.push("unique");
558
- }
559
-
560
- return res;
561
- }
562
-
563
453
  export function sortByRequired(fields: any[], order: string[] = []) {
564
454
  const unrequiredFields: any[] = [];
565
455
  const orderedFields: any[] = [];
@@ -1 +0,0 @@
1
- export {};
@@ -1,181 +0,0 @@
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 schema_1 = require("./schema");
10
- describe("getQualifierMessage", () => {
11
- it("should render nothing", () => {
12
- const actual = (0, schema_1.getQualifierMessage)({});
13
- expect(actual).toBeUndefined();
14
- });
15
- //
16
- // minLength + maxLength
17
- //
18
- it("should render minLength", () => {
19
- const expected = "**Possible values:** `non-empty`";
20
- const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
21
- expect(actual).toBe(expected);
22
- });
23
- it("should render maxLength", () => {
24
- const expected = "**Possible values:** `<= 40 characters`";
25
- const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
26
- expect(actual).toBe(expected);
27
- });
28
- it("should render minLength and maxLength", () => {
29
- const expected = "**Possible values:** `non-empty` and `<= 40 characters`";
30
- const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
31
- expect(actual).toBe(expected);
32
- });
33
- //
34
- // pattern
35
- //
36
- it("should render pattern", () => {
37
- const expected = "**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
38
- const actual = (0, schema_1.getQualifierMessage)({ pattern: "^[a-zA-Z0-9_-]*$" });
39
- expect(actual).toBe(expected);
40
- });
41
- it("should render multiple string qualifiers", () => {
42
- const expected = "**Possible values:** `non-empty` and `<= 40 characters`, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
43
- const actual = (0, schema_1.getQualifierMessage)({
44
- minLength: 1,
45
- maxLength: 40,
46
- pattern: "^[a-zA-Z0-9_-]*$",
47
- });
48
- expect(actual).toBe(expected);
49
- });
50
- //
51
- // enum
52
- //
53
- it("should render enum", () => {
54
- const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
55
- const actual = (0, schema_1.getQualifierMessage)({ enum: ["cat", "dog", "mouse"] });
56
- expect(actual).toBe(expected);
57
- });
58
- //
59
- // minimum + maximum + exclusiveMinimum + exclusiveMaximum
60
- //
61
- it("should render minimum", () => {
62
- const expected = "**Possible values:** `>= 1`";
63
- const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
64
- expect(actual).toBe(expected);
65
- });
66
- it("should render maximum", () => {
67
- const expected = "**Possible values:** `<= 40`";
68
- const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
69
- expect(actual).toBe(expected);
70
- });
71
- it("should render numeric exclusiveMinimum", () => {
72
- const expected = "**Possible values:** `> 1`";
73
- const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
74
- expect(actual).toBe(expected);
75
- });
76
- it("should render numeric exclusiveMaximum", () => {
77
- const expected = "**Possible values:** `< 40`";
78
- const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
79
- expect(actual).toBe(expected);
80
- });
81
- it("should render boolean exclusiveMinimum", () => {
82
- const expected = "**Possible values:** `> 1`";
83
- const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
84
- expect(actual).toBe(expected);
85
- });
86
- it("should render boolean exclusiveMaximum", () => {
87
- const expected = "**Possible values:** `< 40`";
88
- const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
89
- expect(actual).toBe(expected);
90
- });
91
- it("should render minimum when exclusiveMinimum is false", () => {
92
- const expected = "**Possible values:** `>= 1`";
93
- const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
94
- expect(actual).toBe(expected);
95
- });
96
- it("should render maximum when exclusiveMaximum is false", () => {
97
- const expected = "**Possible values:** `<= 40`";
98
- const actual = (0, schema_1.getQualifierMessage)({
99
- maximum: 40,
100
- exclusiveMaximum: false,
101
- });
102
- expect(actual).toBe(expected);
103
- });
104
- it("should render minimum and maximum", () => {
105
- const expected = "**Possible values:** `>= 1` and `<= 40`";
106
- const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
107
- expect(actual).toBe(expected);
108
- });
109
- it("should render 0 minimum and maximum", () => {
110
- const expected = "**Possible values:** `>= 0` and `<= 40`";
111
- const actual = (0, schema_1.getQualifierMessage)({ minimum: 0, maximum: 40 });
112
- expect(actual).toBe(expected);
113
- });
114
- it("should render minimum and 0 maximum", () => {
115
- const expected = "**Possible values:** `>= -10` and `<= 0`";
116
- const actual = (0, schema_1.getQualifierMessage)({ minimum: -10, maximum: 0 });
117
- expect(actual).toBe(expected);
118
- });
119
- it("should render boolean exclusiveMinimum and maximum", () => {
120
- const expected = "**Possible values:** `> 1` and `<= 40`";
121
- const actual = (0, schema_1.getQualifierMessage)({
122
- minimum: 1,
123
- maximum: 40,
124
- exclusiveMinimum: true,
125
- });
126
- expect(actual).toBe(expected);
127
- });
128
- it("should render minimum and boolean exclusiveMaximum", () => {
129
- const expected = "**Possible values:** `>= 1` and `< 40`";
130
- const actual = (0, schema_1.getQualifierMessage)({
131
- minimum: 1,
132
- maximum: 40,
133
- exclusiveMaximum: true,
134
- });
135
- expect(actual).toBe(expected);
136
- });
137
- it("should render numeric exclusiveMinimum and maximum", () => {
138
- const expected = "**Possible values:** `> 1` and `<= 40`";
139
- const actual = (0, schema_1.getQualifierMessage)({
140
- exclusiveMinimum: 1,
141
- maximum: 40,
142
- });
143
- expect(actual).toBe(expected);
144
- });
145
- it("should render minimum and numeric exclusiveMaximum", () => {
146
- const expected = "**Possible values:** `>= 1` and `< 40`";
147
- const actual = (0, schema_1.getQualifierMessage)({
148
- minimum: 1,
149
- exclusiveMaximum: 40,
150
- });
151
- expect(actual).toBe(expected);
152
- });
153
- it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
154
- const expected = "**Possible values:** `> 1` and `< 40`";
155
- const actual = (0, schema_1.getQualifierMessage)({
156
- exclusiveMinimum: 1,
157
- maximum: 40,
158
- exclusiveMaximum: true,
159
- });
160
- expect(actual).toBe(expected);
161
- });
162
- it("should render nothing with empty boolean exclusiveMinimum", () => {
163
- const actual = (0, schema_1.getQualifierMessage)({
164
- exclusiveMinimum: true,
165
- });
166
- expect(actual).toBeUndefined();
167
- });
168
- it("should render nothing with empty boolean exclusiveMaximum", () => {
169
- const actual = (0, schema_1.getQualifierMessage)({
170
- exclusiveMaximum: true,
171
- });
172
- expect(actual).toBeUndefined();
173
- });
174
- it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
175
- const actual = (0, schema_1.getQualifierMessage)({
176
- exclusiveMinimum: true,
177
- exclusiveMaximum: true,
178
- });
179
- expect(actual).toBeUndefined();
180
- });
181
- });