Skip to content

Commit 3947fa9

Browse files
committed
build
1 parent aaa6b74 commit 3947fa9

File tree

16 files changed

+51
-249
lines changed

16 files changed

+51
-249
lines changed

packages/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ function createProperties(schema) {
122122
name: "",
123123
required: false,
124124
schemaName: "object",
125-
qualifierMessage: undefined,
126125
schema: {},
127126
});
128127
}
@@ -151,7 +150,6 @@ function createAdditionalProperties(schema) {
151150
name: "property name*",
152151
required: false,
153152
schemaName: "any",
154-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
155153
schema: schema,
156154
collapsible: false,
157155
discriminator: false,
@@ -179,7 +177,6 @@ function createAdditionalProperties(schema) {
179177
name: "property name*",
180178
required: false,
181179
schemaName: schemaName,
182-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
183180
schema: additionalProperties,
184181
collapsible: false,
185182
discriminator: false,
@@ -336,10 +333,6 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
336333
style: { marginTop: ".5rem", marginBottom: ".5rem" },
337334
children: (0, createDescription_1.createDescription)(description),
338335
})),
339-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
340-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
341-
children: (0, createDescription_1.createDescription)(message),
342-
})),
343336
createNodes(schema, SCHEMA_TYPE),
344337
],
345338
}),
@@ -465,12 +458,6 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
465458
},
466459
children: (0, createDescription_1.createDescription)(description),
467460
})),
468-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
469-
style: {
470-
paddingLeft: "1rem",
471-
},
472-
children: (0, createDescription_1.createDescription)(message),
473-
})),
474461
(0, utils_1.create)("DiscriminatorTabs", {
475462
className: "openapi-tabs__discriminator",
476463
children: Object.keys(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping).map((key, index) => {
@@ -554,7 +541,6 @@ function createEdges({ name, schema, required, discriminator, }) {
554541
name,
555542
required: Array.isArray(required) ? required.includes(name) : required,
556543
schemaName: mergedSchemaName,
557-
qualifierMessage: (0, schema_1.getQualifierMessage)(mergedSchemas),
558544
schema: mergedSchemas,
559545
});
560546
}
@@ -564,7 +550,6 @@ function createEdges({ name, schema, required, discriminator, }) {
564550
name,
565551
required: Array.isArray(required) ? required.includes(name) : required,
566552
schemaName: schemaName,
567-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
568553
schema: schema,
569554
});
570555
}
@@ -633,15 +618,7 @@ function createNodes(schema, schemaType) {
633618
marginTop: ".5rem",
634619
marginBottom: ".5rem",
635620
},
636-
children: [
637-
(0, createDescription_1.createDescription)(schema.type),
638-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
639-
style: {
640-
paddingTop: "1rem",
641-
},
642-
children: (0, createDescription_1.createDescription)(message),
643-
})),
644-
],
621+
children: [(0, createDescription_1.createDescription)(schema.type)],
645622
});
646623
}
647624
// handle circular references
@@ -651,15 +628,7 @@ function createNodes(schema, schemaType) {
651628
marginTop: ".5rem",
652629
marginBottom: ".5rem",
653630
},
654-
children: [
655-
(0, createDescription_1.createDescription)(schema),
656-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
657-
style: {
658-
paddingTop: "1rem",
659-
},
660-
children: (0, createDescription_1.createDescription)(message),
661-
})),
662-
],
631+
children: [(0, createDescription_1.createDescription)(schema)],
663632
});
664633
}
665634
// Unknown node/schema type should return undefined
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import { SchemaObject } from "../openapi/types";
22
export declare function getSchemaName(schema: SchemaObject, circular?: boolean): string;
3-
export declare function getQualifierMessage(schema?: SchemaObject): string | undefined;

packages/docusaurus-plugin-openapi-docs/lib/markdown/schema.js

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* ========================================================================== */
88
Object.defineProperty(exports, "__esModule", { value: true });
99
exports.getSchemaName = getSchemaName;
10-
exports.getQualifierMessage = getQualifierMessage;
1110
function prettyName(schema, circular) {
1211
var _a, _b, _c, _d, _e;
1312
if (schema.format) {
@@ -51,107 +50,3 @@ function getSchemaName(schema, circular) {
5150
}
5251
return (_a = prettyName(schema, circular)) !== null && _a !== void 0 ? _a : "";
5352
}
54-
function getQualifierMessage(schema) {
55-
// TODO:
56-
// - uniqueItems
57-
// - maxProperties
58-
// - minProperties
59-
// - multipleOf
60-
if (!schema) {
61-
return undefined;
62-
}
63-
if (schema.items &&
64-
schema.minItems === undefined &&
65-
schema.maxItems === undefined) {
66-
return getQualifierMessage(schema.items);
67-
}
68-
let message = "**Possible values:** ";
69-
let qualifierGroups = [];
70-
if (schema.items && schema.items.enum) {
71-
if (schema.items.enum) {
72-
qualifierGroups.push(`[${schema.items.enum.map((e) => `\`${e}\``).join(", ")}]`);
73-
}
74-
}
75-
if (schema.minLength || schema.maxLength) {
76-
let lengthQualifier = "";
77-
let minLength;
78-
let maxLength;
79-
if (schema.minLength && schema.minLength > 1) {
80-
minLength = `\`>= ${schema.minLength} characters\``;
81-
}
82-
if (schema.minLength && schema.minLength === 1) {
83-
minLength = `\`non-empty\``;
84-
}
85-
if (schema.maxLength) {
86-
maxLength = `\`<= ${schema.maxLength} characters\``;
87-
}
88-
if (minLength && !maxLength) {
89-
lengthQualifier += minLength;
90-
}
91-
if (maxLength && !minLength) {
92-
lengthQualifier += maxLength;
93-
}
94-
if (minLength && maxLength) {
95-
lengthQualifier += `${minLength} and ${maxLength}`;
96-
}
97-
qualifierGroups.push(lengthQualifier);
98-
}
99-
if (schema.minimum != null ||
100-
schema.maximum != null ||
101-
typeof schema.exclusiveMinimum === "number" ||
102-
typeof schema.exclusiveMaximum === "number") {
103-
let minmaxQualifier = "";
104-
let minimum;
105-
let maximum;
106-
if (typeof schema.exclusiveMinimum === "number") {
107-
minimum = `\`> ${schema.exclusiveMinimum}\``;
108-
}
109-
else if (schema.minimum != null && !schema.exclusiveMinimum) {
110-
minimum = `\`>= ${schema.minimum}\``;
111-
}
112-
else if (schema.minimum != null && schema.exclusiveMinimum === true) {
113-
minimum = `\`> ${schema.minimum}\``;
114-
}
115-
if (typeof schema.exclusiveMaximum === "number") {
116-
maximum = `\`< ${schema.exclusiveMaximum}\``;
117-
}
118-
else if (schema.maximum != null && !schema.exclusiveMaximum) {
119-
maximum = `\`<= ${schema.maximum}\``;
120-
}
121-
else if (schema.maximum != null && schema.exclusiveMaximum === true) {
122-
maximum = `\`< ${schema.maximum}\``;
123-
}
124-
if (minimum && !maximum) {
125-
minmaxQualifier += minimum;
126-
}
127-
if (maximum && !minimum) {
128-
minmaxQualifier += maximum;
129-
}
130-
if (minimum && maximum) {
131-
minmaxQualifier += `${minimum} and ${maximum}`;
132-
}
133-
qualifierGroups.push(minmaxQualifier);
134-
}
135-
if (schema.pattern) {
136-
qualifierGroups.push(`Value must match regular expression \`${schema.pattern}\``);
137-
}
138-
// Check if discriminator mapping
139-
const discriminator = schema;
140-
if (discriminator.mapping) {
141-
const values = Object.keys(discriminator.mapping);
142-
qualifierGroups.push(`[${values.map((e) => `\`${e}\``).join(", ")}]`);
143-
}
144-
if (schema.enum) {
145-
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
146-
}
147-
if (schema.minItems) {
148-
qualifierGroups.push(`\`>= ${schema.minItems}\``);
149-
}
150-
if (schema.maxItems) {
151-
qualifierGroups.push(`\`<= ${schema.maxItems}\``);
152-
}
153-
if (qualifierGroups.length === 0) {
154-
return undefined;
155-
}
156-
return message + qualifierGroups.join(", ");
157-
}

packages/docusaurus-plugin-openapi-docs/lib/markdown/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function create(tag, props, options = {}) {
1515
const { children, ...rest } = props;
1616
let propString = "";
1717
for (const [key, value] of Object.entries(rest)) {
18-
propString += `\n ${key}={${JSON.stringify(value)}}`;
18+
if (value !== undefined) {
19+
propString += `\n ${key}={${JSON.stringify(value)}}`;
20+
}
1921
}
2022
let indentedChildren = render(children).replace(/^/gm, " ");
2123
if (options.inline) {

packages/docusaurus-plugin-openapi-docs/lib/openapi/utils/utils/openapi.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export declare function getSerializedValue(field: any, example: any): any;
1919
export declare function langFromMime(contentType: string): string;
2020
export declare function isNamedDefinition(pointer?: string): boolean;
2121
export declare function getDefinitionName(pointer?: string): string | undefined;
22-
export declare function humanizeNumberRange(schema: OpenAPISchema): string | undefined;
23-
export declare function humanizeConstraints(schema: OpenAPISchema): string[];
2422
export declare function sortByRequired(fields: any[], order?: string[]): any[];
2523
export declare function sortByField(fields: any[], param: "name" | "description" | "kind"): any[];
2624
export declare function mergeParams(parser: OpenAPIParser, pathParams?: Array<Referenced<OpenAPIParameter>>, operationParams?: Array<Referenced<OpenAPIParameter>>): Array<Referenced<OpenAPIParameter>>;

packages/docusaurus-plugin-openapi-docs/lib/openapi/utils/utils/openapi.js

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ exports.getSerializedValue = getSerializedValue;
2222
exports.langFromMime = langFromMime;
2323
exports.isNamedDefinition = isNamedDefinition;
2424
exports.getDefinitionName = getDefinitionName;
25-
exports.humanizeNumberRange = humanizeNumberRange;
26-
exports.humanizeConstraints = humanizeConstraints;
2725
exports.sortByRequired = sortByRequired;
2826
exports.sortByField = sortByField;
2927
exports.mergeParams = mergeParams;
@@ -366,86 +364,6 @@ function getDefinitionName(pointer) {
366364
const [name] = ((_a = pointer === null || pointer === void 0 ? void 0 : pointer.match(DEFINITION_NAME_REGEX)) === null || _a === void 0 ? void 0 : _a.reverse()) || [];
367365
return name;
368366
}
369-
function humanizeMultipleOfConstraint(multipleOf) {
370-
if (multipleOf === undefined) {
371-
return;
372-
}
373-
const strigifiedMultipleOf = multipleOf.toString(10);
374-
if (!/^0\.0*1$/.test(strigifiedMultipleOf)) {
375-
return `multiple of ${strigifiedMultipleOf}`;
376-
}
377-
return `decimal places <= ${strigifiedMultipleOf.split(".")[1].length}`;
378-
}
379-
function humanizeRangeConstraint(description, min, max) {
380-
let stringRange;
381-
if (min !== undefined && max !== undefined) {
382-
if (min === max) {
383-
stringRange = `= ${min} ${description}`;
384-
}
385-
else {
386-
stringRange = `[ ${min} .. ${max} ] ${description}`;
387-
}
388-
}
389-
else if (max !== undefined) {
390-
stringRange = `<= ${max} ${description}`;
391-
}
392-
else if (min !== undefined) {
393-
if (min === 1) {
394-
stringRange = "non-empty";
395-
}
396-
else {
397-
stringRange = `>= ${min} ${description}`;
398-
}
399-
}
400-
return stringRange;
401-
}
402-
function humanizeNumberRange(schema) {
403-
var _a, _b;
404-
const minimum = typeof schema.exclusiveMinimum === "number"
405-
? Math.min(schema.exclusiveMinimum, (_a = schema.minimum) !== null && _a !== void 0 ? _a : Infinity)
406-
: schema.minimum;
407-
const maximum = typeof schema.exclusiveMaximum === "number"
408-
? Math.max(schema.exclusiveMaximum, (_b = schema.maximum) !== null && _b !== void 0 ? _b : -Infinity)
409-
: schema.maximum;
410-
const exclusiveMinimum = typeof schema.exclusiveMinimum === "number" || schema.exclusiveMinimum;
411-
const exclusiveMaximum = typeof schema.exclusiveMaximum === "number" || schema.exclusiveMaximum;
412-
if (minimum !== undefined && maximum !== undefined) {
413-
return `${exclusiveMinimum ? "( " : "[ "}${minimum} .. ${maximum}${exclusiveMaximum ? " )" : " ]"}`;
414-
}
415-
else if (maximum !== undefined) {
416-
return `${exclusiveMaximum ? "< " : "<= "}${maximum}`;
417-
}
418-
else if (minimum !== undefined) {
419-
return `${exclusiveMinimum ? "> " : ">= "}${minimum}`;
420-
}
421-
}
422-
function humanizeConstraints(schema) {
423-
const res = [];
424-
const stringRange = humanizeRangeConstraint("characters", schema.minLength, schema.maxLength);
425-
if (stringRange !== undefined) {
426-
res.push(stringRange);
427-
}
428-
const arrayRange = humanizeRangeConstraint("items", schema.minItems, schema.maxItems);
429-
if (arrayRange !== undefined) {
430-
res.push(arrayRange);
431-
}
432-
const propertiesRange = humanizeRangeConstraint("properties", schema.minProperties, schema.maxProperties);
433-
if (propertiesRange !== undefined) {
434-
res.push(propertiesRange);
435-
}
436-
const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf);
437-
if (multipleOfConstraint !== undefined) {
438-
res.push(multipleOfConstraint);
439-
}
440-
const numberRange = humanizeNumberRange(schema);
441-
if (numberRange !== undefined) {
442-
res.push(numberRange);
443-
}
444-
if (schema.uniqueItems) {
445-
res.push("unique");
446-
}
447-
return res;
448-
}
449367
function sortByRequired(fields, order = []) {
450368
const unrequiredFields = [];
451369
const orderedFields = [];

packages/docusaurus-theme-openapi-docs/lib/markdown/schema.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,25 @@ function getQualifierMessage(schema) {
7777
let minLength;
7878
let maxLength;
7979
if (schema.minLength && schema.minLength > 1) {
80-
minLength = `\`>= ${schema.minLength} characters\``;
80+
const charactersMessage = (0, Translate_1.translate)({
81+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.CHARACTERS,
82+
message: "characters",
83+
});
84+
minLength = `\`>= ${schema.minLength} ${charactersMessage}\``;
8185
}
8286
if (schema.minLength && schema.minLength === 1) {
83-
minLength = `\`non-empty\``;
87+
const nonEmptyMessage = (0, Translate_1.translate)({
88+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.NON_EMPTY,
89+
message: "non-empty",
90+
});
91+
minLength = `\`${nonEmptyMessage}\``;
8492
}
8593
if (schema.maxLength) {
86-
maxLength = `\`<= ${schema.maxLength} characters\``;
94+
const charactersMessage = (0, Translate_1.translate)({
95+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.CHARACTERS,
96+
message: "characters",
97+
});
98+
maxLength = `\`<= ${schema.maxLength} ${charactersMessage}\``;
8799
}
88100
if (minLength && !maxLength) {
89101
lengthQualifier += minLength;
@@ -133,7 +145,11 @@ function getQualifierMessage(schema) {
133145
qualifierGroups.push(minmaxQualifier);
134146
}
135147
if (schema.pattern) {
136-
qualifierGroups.push(`Value must match regular expression \`${schema.pattern}\``);
148+
const expressionMessage = (0, Translate_1.translate)({
149+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXPRESSION,
150+
message: "Value must match regular expression",
151+
});
152+
qualifierGroups.push(`${expressionMessage} \`${schema.pattern}\``);
137153
}
138154
// Check if discriminator mapping
139155
const discriminator = schema;

packages/docusaurus-theme-openapi-docs/lib/theme/RequestSchema/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ var __importDefault =
1212
};
1313
Object.defineProperty(exports, "__esModule", { value: true });
1414
const react_1 = __importDefault(require("react"));
15-
const Translate_1 = require("@docusaurus/Translate");
16-
const translationIds_1 = require("@theme/translationIds");
1715
const BrowserOnly_1 = __importDefault(require("@docusaurus/BrowserOnly"));
16+
const Translate_1 = require("@docusaurus/Translate");
1817
const Details_1 = __importDefault(require("@theme/Details"));
1918
const Markdown_1 = __importDefault(require("@theme/Markdown"));
2019
const MimeTabs_1 = __importDefault(require("@theme/MimeTabs")); // Assume these components exist
2120
const Schema_1 = __importDefault(require("@theme/Schema"));
2221
const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
2322
const TabItem_1 = __importDefault(require("@theme/TabItem"));
23+
const translationIds_1 = require("@theme/translationIds");
2424
const RequestSchemaComponent = ({ title, body, style }) => {
2525
if (
2626
body === undefined ||

0 commit comments

Comments
 (0)