@gitbook/react-openapi 1.5.4 → 1.5.6
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.
- package/CHANGELOG.md +13 -0
- package/dist/InteractiveSection.js +52 -30
- package/dist/Markdown.js +5 -1
- package/dist/OpenAPICodeSample.js +45 -9
- package/dist/OpenAPICodeSampleInteractive.js +41 -15
- package/dist/OpenAPICodeSampleSelector.js +34 -14
- package/dist/OpenAPICopyButton.js +21 -15
- package/dist/OpenAPIDisclosure.js +18 -10
- package/dist/OpenAPIDisclosureGroup.js +56 -30
- package/dist/OpenAPIExample.js +6 -4
- package/dist/OpenAPIMediaType.js +38 -17
- package/dist/OpenAPIOperation.d.ts +2 -2
- package/dist/OpenAPIOperation.js +26 -12
- package/dist/OpenAPIOperationContext.d.ts +2 -2
- package/dist/OpenAPIOperationContext.js +5 -3
- package/dist/OpenAPIPath.js +14 -5
- package/dist/OpenAPIPathItem.js +26 -12
- package/dist/OpenAPIPathMultipleServers.js +29 -12
- package/dist/OpenAPIPrefillContextProvider.d.ts +2 -1
- package/dist/OpenAPIPrefillContextProvider.js +5 -3
- package/dist/OpenAPIRequestBody.js +20 -10
- package/dist/OpenAPIRequestBodyHeaderType.js +5 -3
- package/dist/OpenAPIRequiredScopes.js +41 -26
- package/dist/OpenAPIResponse.js +34 -19
- package/dist/OpenAPIResponseExample.js +25 -8
- package/dist/OpenAPIResponseExampleContent.js +39 -18
- package/dist/OpenAPIResponses.js +40 -17
- package/dist/OpenAPISchema.js +212 -88
- package/dist/OpenAPISchemaName.js +44 -24
- package/dist/OpenAPISchemaServer.js +10 -2
- package/dist/OpenAPISecurities.js +125 -57
- package/dist/OpenAPISelect.js +27 -18
- package/dist/OpenAPISpec.js +27 -12
- package/dist/OpenAPITooltip.js +14 -6
- package/dist/OpenAPIWebhook.d.ts +2 -2
- package/dist/OpenAPIWebhook.js +23 -11
- package/dist/OpenAPIWebhookExample.js +18 -8
- package/dist/ScalarApiButton.js +50 -29
- package/dist/StaticSection.js +49 -15
- package/dist/common/OpenAPIColumnSpec.js +21 -9
- package/dist/common/OpenAPIOperationDescription.js +12 -6
- package/dist/common/OpenAPIStability.js +6 -3
- package/dist/common/OpenAPISummary.js +23 -12
- package/dist/formatPath.js +7 -4
- package/dist/schemas/OpenAPISchemaItem.js +18 -11
- package/dist/schemas/OpenAPISchemas.d.ts +2 -2
- package/dist/schemas/OpenAPISchemas.js +55 -31
- package/dist/translate.js +4 -6
- package/dist/util/example.js +6 -1
- package/package.json +3 -3
|
@@ -5,6 +5,7 @@ import { getOpenAPIClientContext } from "./context.js";
|
|
|
5
5
|
import { getExampleFromReference, getExamples } from "./util/example.js";
|
|
6
6
|
import { OpenAPIMediaTypeContent } from "./OpenAPIMediaType.js";
|
|
7
7
|
import { OpenAPIResponseExampleContent } from "./OpenAPIResponseExampleContent.js";
|
|
8
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
9
|
|
|
9
10
|
//#region src/OpenAPIResponseExample.tsx
|
|
10
11
|
/**
|
|
@@ -23,28 +24,39 @@ function OpenAPIResponseExample(props) {
|
|
|
23
24
|
});
|
|
24
25
|
const tabs = responses.filter(([_, responseObject]) => responseObject && typeof responseObject === "object" && !responseObject["x-hideSample"]).map(([key, responseObject]) => {
|
|
25
26
|
const description = resolveDescription(responseObject);
|
|
26
|
-
const label = description ?
|
|
27
|
+
const label = description ? /* @__PURE__ */ jsx(Markdown, { source: description }, `response-description-${key}`) : getStatusCodeDefaultLabel(key, context);
|
|
27
28
|
if (checkIsReference(responseObject)) return {
|
|
28
29
|
key,
|
|
29
30
|
label,
|
|
30
31
|
statusCode: key,
|
|
31
|
-
body:
|
|
32
|
+
body: /* @__PURE__ */ jsx(OpenAPIExample, {
|
|
33
|
+
example: getExampleFromReference(responseObject, context),
|
|
34
|
+
context,
|
|
35
|
+
syntax: "json"
|
|
36
|
+
})
|
|
32
37
|
};
|
|
33
38
|
if (!responseObject.content || Object.keys(responseObject.content).length === 0) return {
|
|
34
39
|
key,
|
|
35
40
|
label,
|
|
36
41
|
statusCode: key,
|
|
37
|
-
body:
|
|
42
|
+
body: /* @__PURE__ */ jsx(OpenAPIEmptyExample, { context })
|
|
38
43
|
};
|
|
39
44
|
return {
|
|
40
45
|
key,
|
|
41
46
|
label,
|
|
42
47
|
statusCode: key,
|
|
43
|
-
body:
|
|
48
|
+
body: /* @__PURE__ */ jsx(OpenAPIResponse, {
|
|
49
|
+
context,
|
|
50
|
+
content: responseObject.content
|
|
51
|
+
})
|
|
44
52
|
};
|
|
45
53
|
});
|
|
46
54
|
if (tabs.length === 0) return null;
|
|
47
|
-
return
|
|
55
|
+
return /* @__PURE__ */ jsx(OpenAPIResponseExampleContent, {
|
|
56
|
+
selectIcon: context.icons.chevronDown,
|
|
57
|
+
blockKey: context.blockKey,
|
|
58
|
+
items: tabs
|
|
59
|
+
});
|
|
48
60
|
}
|
|
49
61
|
function OpenAPIResponse(props) {
|
|
50
62
|
const { context, content } = props;
|
|
@@ -55,12 +67,12 @@ function OpenAPIResponse(props) {
|
|
|
55
67
|
if (!mediaTypeObject) return {
|
|
56
68
|
key: mediaType,
|
|
57
69
|
label: mediaType,
|
|
58
|
-
body:
|
|
70
|
+
body: /* @__PURE__ */ jsx(OpenAPIEmptyExample, { context })
|
|
59
71
|
};
|
|
60
72
|
return {
|
|
61
73
|
key: mediaType,
|
|
62
74
|
label: mediaType,
|
|
63
|
-
body:
|
|
75
|
+
body: /* @__PURE__ */ jsx(Fragment, {}),
|
|
64
76
|
examples: getExamples({
|
|
65
77
|
mediaTypeObject,
|
|
66
78
|
mediaType,
|
|
@@ -68,7 +80,12 @@ function OpenAPIResponse(props) {
|
|
|
68
80
|
})
|
|
69
81
|
};
|
|
70
82
|
});
|
|
71
|
-
return
|
|
83
|
+
return /* @__PURE__ */ jsx(OpenAPIMediaTypeContent, {
|
|
84
|
+
selectIcon: context.icons.chevronDown,
|
|
85
|
+
stateKey: createStateKey("response-media-types", context.blockKey),
|
|
86
|
+
items: tabs,
|
|
87
|
+
context: getOpenAPIClientContext(context)
|
|
88
|
+
});
|
|
72
89
|
}
|
|
73
90
|
|
|
74
91
|
//#endregion
|
|
@@ -5,6 +5,7 @@ import { createStateKey, getStatusCodeClassName } from "./utils.js";
|
|
|
5
5
|
import { StaticSection } from "./StaticSection.js";
|
|
6
6
|
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from "./OpenAPISelect.js";
|
|
7
7
|
import clsx from "classnames";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
|
|
9
10
|
//#region src/OpenAPIResponseExampleContent.tsx
|
|
10
11
|
/**
|
|
@@ -15,40 +16,60 @@ function useResponseExamplesState(blockKey, initialKey = "default") {
|
|
|
15
16
|
}
|
|
16
17
|
function OpenAPIResponseExampleContent(props) {
|
|
17
18
|
const { blockKey, items, selectIcon } = props;
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
return /* @__PURE__ */ jsx(StaticSection, {
|
|
20
|
+
header: /* @__PURE__ */ jsx(OpenAPIResponseExampleHeader, {
|
|
21
|
+
selectIcon,
|
|
22
|
+
blockKey,
|
|
23
|
+
items
|
|
24
|
+
}),
|
|
25
|
+
className: "openapi-response-examples",
|
|
26
|
+
children: /* @__PURE__ */ jsx(OpenAPIResponseExampleBody, {
|
|
27
|
+
blockKey,
|
|
28
|
+
items
|
|
29
|
+
})
|
|
30
|
+
});
|
|
21
31
|
}
|
|
22
32
|
function OpenAPIResponseExampleHeader(props) {
|
|
23
33
|
const { items, blockKey, selectIcon } = props;
|
|
24
34
|
if (items.length === 1) {
|
|
25
35
|
const item = items[0];
|
|
26
36
|
if (!item) return null;
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
return /* @__PURE__ */ jsx("span", {
|
|
38
|
+
className: "openapi-response-examples-statuscode-title",
|
|
39
|
+
children: /* @__PURE__ */ jsx(OpenAPIResponseExampleItem, { item })
|
|
40
|
+
});
|
|
30
41
|
}
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
return /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
43
|
+
items,
|
|
44
|
+
icon: selectIcon,
|
|
45
|
+
stateKey: getResponseExampleStateKey(blockKey),
|
|
46
|
+
placement: "bottom start",
|
|
47
|
+
children: items.map((item) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
48
|
+
id: item.key,
|
|
49
|
+
value: item,
|
|
50
|
+
children: /* @__PURE__ */ jsx(OpenAPIResponseExampleItem, { item })
|
|
51
|
+
}, item.key))
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
function OpenAPIResponseExampleItem(props) {
|
|
38
55
|
const { item } = props;
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
57
|
+
className: clsx("openapi-statuscode", `openapi-statuscode-${getStatusCodeClassName(item.statusCode)}`, "openapi-response-examples-statuscode"),
|
|
58
|
+
children: item.statusCode
|
|
59
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
60
|
+
className: "openapi-response-examples-statuscode-label",
|
|
61
|
+
children: item.label
|
|
62
|
+
})] });
|
|
45
63
|
}
|
|
46
64
|
function OpenAPIResponseExampleBody(props) {
|
|
47
65
|
const { blockKey, items } = props;
|
|
48
66
|
const state = useResponseExamplesState(blockKey, items[0]?.key);
|
|
49
67
|
const selectedItem = items.find((item) => item.key === state.key) ?? items[0];
|
|
50
68
|
if (!selectedItem) return null;
|
|
51
|
-
return
|
|
69
|
+
return /* @__PURE__ */ jsx("div", {
|
|
70
|
+
className: "openapi-response-examples-panel",
|
|
71
|
+
children: selectedItem.body
|
|
72
|
+
});
|
|
52
73
|
}
|
|
53
74
|
/**
|
|
54
75
|
* Return the state key for the response examples.
|
package/dist/OpenAPIResponses.js
CHANGED
|
@@ -9,6 +9,7 @@ import { useResponseExamplesState } from "./OpenAPIResponseExampleContent.js";
|
|
|
9
9
|
import { OpenAPIDisclosureGroup } from "./OpenAPIDisclosureGroup.js";
|
|
10
10
|
import { OpenAPIResponse } from "./OpenAPIResponse.js";
|
|
11
11
|
import clsx from "classnames";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
13
|
|
|
13
14
|
//#region src/OpenAPIResponses.tsx
|
|
14
15
|
/**
|
|
@@ -21,40 +22,62 @@ function OpenAPIResponses(props) {
|
|
|
21
22
|
if ((!response.content || !Object.keys(response.content).length) && response.headers && Object.keys(response.headers).length) return [{
|
|
22
23
|
key: "default",
|
|
23
24
|
label: "",
|
|
24
|
-
body:
|
|
25
|
+
body: /* @__PURE__ */ jsx(OpenAPIResponse, {
|
|
26
|
+
response,
|
|
27
|
+
mediaType: {},
|
|
28
|
+
context
|
|
29
|
+
})
|
|
25
30
|
}];
|
|
26
31
|
if (!response.content) return [{
|
|
27
32
|
key: "default",
|
|
28
33
|
label: "",
|
|
29
|
-
body:
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
body: /* @__PURE__ */ jsx("pre", {
|
|
35
|
+
className: "openapi-example-empty",
|
|
36
|
+
children: /* @__PURE__ */ jsx("p", { children: t(context.translation, "no_content") })
|
|
37
|
+
})
|
|
32
38
|
}];
|
|
33
39
|
return Object.entries(response.content ?? {}).map(([contentType, mediaType]) => ({
|
|
34
40
|
key: contentType,
|
|
35
41
|
label: contentType,
|
|
36
|
-
body:
|
|
42
|
+
body: /* @__PURE__ */ jsx(OpenAPIResponse, {
|
|
43
|
+
response,
|
|
44
|
+
mediaType,
|
|
45
|
+
context
|
|
46
|
+
})
|
|
37
47
|
}));
|
|
38
48
|
})();
|
|
39
49
|
const description = resolveDescription(response);
|
|
40
50
|
return {
|
|
41
51
|
key: statusCode,
|
|
42
|
-
label:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
label: /* @__PURE__ */ jsxs("div", {
|
|
53
|
+
className: "openapi-response-tab-content",
|
|
54
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
55
|
+
className: clsx("openapi-statuscode", `openapi-statuscode-${getStatusCodeClassName(statusCode)}`),
|
|
56
|
+
children: statusCode
|
|
57
|
+
}), description ? /* @__PURE__ */ jsx(Markdown, {
|
|
58
|
+
source: description,
|
|
59
|
+
className: "openapi-response-description"
|
|
60
|
+
}) : getStatusCodeDefaultLabel(statusCode, context)]
|
|
61
|
+
}),
|
|
48
62
|
tabs
|
|
49
63
|
};
|
|
50
64
|
});
|
|
51
65
|
const state = useResponseExamplesState(context.blockKey, groups[0]?.key);
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
return /* @__PURE__ */ jsx(StaticSection, {
|
|
67
|
+
header: t(context.translation, "responses"),
|
|
68
|
+
className: "openapi-responses",
|
|
69
|
+
children: /* @__PURE__ */ jsx(OpenAPIDisclosureGroup, {
|
|
70
|
+
icon: context.icons.chevronRight,
|
|
71
|
+
expandedKeys: state.key ? new Set([state.key]) : /* @__PURE__ */ new Set(),
|
|
72
|
+
onExpandedChange: (keys) => {
|
|
73
|
+
const key = keys.values().next().value ?? null;
|
|
74
|
+
state.setKey(key);
|
|
75
|
+
},
|
|
76
|
+
groups,
|
|
77
|
+
selectIcon: context.icons.chevronDown,
|
|
78
|
+
selectStateKey: createStateKey("response-media-types", context.blockKey)
|
|
79
|
+
})
|
|
80
|
+
});
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
//#endregion
|
package/dist/OpenAPISchema.js
CHANGED
|
@@ -12,6 +12,7 @@ import { getDisclosureLabel } from "./getDisclosureLabel.js";
|
|
|
12
12
|
import { checkIsReference, getSchemaTitle, resolveDescription, resolveFirstExample } from "./utils.js";
|
|
13
13
|
import clsx from "classnames";
|
|
14
14
|
import { useId } from "react";
|
|
15
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
15
16
|
|
|
16
17
|
//#region src/OpenAPISchema.tsx
|
|
17
18
|
/**
|
|
@@ -22,42 +23,77 @@ function OpenAPISchemaProperty(props) {
|
|
|
22
23
|
const { schema } = property;
|
|
23
24
|
const id = useId();
|
|
24
25
|
const circularRefId = parentCircularRefs.get(schema);
|
|
25
|
-
if (circularRefId) return
|
|
26
|
+
if (circularRefId) return /* @__PURE__ */ jsx(OpenAPISchemaPresentation, {
|
|
27
|
+
context,
|
|
28
|
+
property,
|
|
29
|
+
circularRefId
|
|
30
|
+
});
|
|
26
31
|
const circularRefs = new Map(parentCircularRefs);
|
|
27
32
|
circularRefs.set(schema, id);
|
|
28
33
|
const properties = getSchemaProperties(schema, discriminator, discriminatorValue);
|
|
29
34
|
const alternatives = getSchemaAlternatives(schema, new Set(circularRefs.keys()));
|
|
30
|
-
const header =
|
|
35
|
+
const header = /* @__PURE__ */ jsx(OpenAPISchemaPresentation, {
|
|
36
|
+
id,
|
|
37
|
+
context,
|
|
38
|
+
property
|
|
39
|
+
});
|
|
31
40
|
const content = (() => {
|
|
32
|
-
if (alternatives?.schemas) return
|
|
33
|
-
|
|
41
|
+
if (alternatives?.schemas) return /* @__PURE__ */ jsx(OpenAPISchemaAlternatives, {
|
|
42
|
+
alternatives,
|
|
43
|
+
schema,
|
|
44
|
+
circularRefs,
|
|
45
|
+
context,
|
|
46
|
+
parentDiscriminator: discriminator,
|
|
47
|
+
parentDiscriminatorValue: discriminatorValue
|
|
48
|
+
});
|
|
49
|
+
if (properties?.length) return /* @__PURE__ */ jsx(OpenAPISchemaProperties, {
|
|
50
|
+
properties,
|
|
51
|
+
circularRefs,
|
|
52
|
+
context
|
|
53
|
+
});
|
|
34
54
|
return null;
|
|
35
55
|
})();
|
|
36
|
-
if (properties?.length) return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
if (properties?.length) return /* @__PURE__ */ jsx(OpenAPIDisclosure, {
|
|
57
|
+
icon: context.icons.plus,
|
|
58
|
+
header,
|
|
59
|
+
label: (isExpanded) => getDisclosureLabel({
|
|
60
|
+
schema,
|
|
61
|
+
isExpanded,
|
|
62
|
+
context
|
|
63
|
+
}),
|
|
64
|
+
children: content
|
|
65
|
+
});
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
67
|
+
id,
|
|
68
|
+
...rest,
|
|
69
|
+
className: clsx("openapi-schema", className),
|
|
70
|
+
children: [header, content]
|
|
71
|
+
});
|
|
47
72
|
}
|
|
48
73
|
/**
|
|
49
74
|
* Render a set of properties of an OpenAPI schema.
|
|
50
75
|
*/
|
|
51
76
|
function OpenAPISchemaProperties(props) {
|
|
52
77
|
const { id, properties, circularRefs = /* @__PURE__ */ new Map(), context } = props;
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
return /* @__PURE__ */ jsx("div", {
|
|
79
|
+
id,
|
|
80
|
+
className: "openapi-schema-properties",
|
|
81
|
+
children: properties.map((property, index) => {
|
|
82
|
+
return /* @__PURE__ */ jsx(OpenAPISchemaProperty, {
|
|
83
|
+
circularRefs,
|
|
84
|
+
property,
|
|
85
|
+
context,
|
|
86
|
+
style: { animationDelay: `${index * .02}s` }
|
|
87
|
+
}, index);
|
|
88
|
+
})
|
|
89
|
+
});
|
|
58
90
|
}
|
|
59
91
|
function OpenAPISchemaPropertiesFromServer(props) {
|
|
60
|
-
return
|
|
92
|
+
return /* @__PURE__ */ jsx(OpenAPISchemaProperties, {
|
|
93
|
+
id: props.id,
|
|
94
|
+
properties: JSON.parse(props.properties, retrocycle()),
|
|
95
|
+
context: props.context
|
|
96
|
+
});
|
|
61
97
|
}
|
|
62
98
|
/**
|
|
63
99
|
* Render a root schema (such as the request body or response body).
|
|
@@ -70,18 +106,35 @@ function OpenAPIRootSchema(props) {
|
|
|
70
106
|
const alternatives = getSchemaAlternatives(schema, new Set(parentCircularRefs.keys()));
|
|
71
107
|
const circularRefs = new Map(parentCircularRefs);
|
|
72
108
|
circularRefs.set(schema, id);
|
|
73
|
-
if (alternatives?.schemas) return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
109
|
+
if (alternatives?.schemas) return /* @__PURE__ */ jsxs(Fragment$1, { children: [description ? /* @__PURE__ */ jsx(Markdown, {
|
|
110
|
+
source: description,
|
|
111
|
+
className: "openapi-schema-root-description"
|
|
112
|
+
}) : null, /* @__PURE__ */ jsx(OpenAPISchemaAlternatives, {
|
|
113
|
+
alternatives,
|
|
114
|
+
schema,
|
|
115
|
+
circularRefs,
|
|
116
|
+
context
|
|
117
|
+
})] });
|
|
118
|
+
if (properties?.length) return /* @__PURE__ */ jsxs(Fragment$1, { children: [description ? /* @__PURE__ */ jsx(Markdown, {
|
|
119
|
+
source: description,
|
|
120
|
+
className: "openapi-schema-root-description"
|
|
121
|
+
}) : null, /* @__PURE__ */ jsx(OpenAPISchemaProperties, {
|
|
122
|
+
properties,
|
|
123
|
+
circularRefs,
|
|
124
|
+
context
|
|
125
|
+
})] });
|
|
126
|
+
return /* @__PURE__ */ jsx(OpenAPISchemaProperty, {
|
|
127
|
+
className: "openapi-schema-root",
|
|
128
|
+
property: { schema },
|
|
129
|
+
context,
|
|
130
|
+
circularRefs: parentCircularRefs
|
|
131
|
+
});
|
|
82
132
|
}
|
|
83
133
|
function OpenAPIRootSchemaFromServer(props) {
|
|
84
|
-
return
|
|
134
|
+
return /* @__PURE__ */ jsx(OpenAPIRootSchema, {
|
|
135
|
+
schema: JSON.parse(props.schema, retrocycle()),
|
|
136
|
+
context: props.context
|
|
137
|
+
});
|
|
85
138
|
}
|
|
86
139
|
/**
|
|
87
140
|
* Get the discriminator value for a schema.
|
|
@@ -109,16 +162,24 @@ function OpenAPISchemaAlternatives(props) {
|
|
|
109
162
|
const { alternatives, schema, circularRefs, context, parentDiscriminator, parentDiscriminatorValue } = props;
|
|
110
163
|
if (!alternatives?.schemas) return null;
|
|
111
164
|
const { schemas, discriminator: alternativeDiscriminator, type } = alternatives;
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
165
|
+
return /* @__PURE__ */ jsx("div", {
|
|
166
|
+
className: "openapi-schema-alternatives",
|
|
167
|
+
children: schemas.map((alternativeSchema, index) => {
|
|
168
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
169
|
+
className: "openapi-schema-alternative",
|
|
170
|
+
children: [/* @__PURE__ */ jsx(OpenAPISchemaAlternative, {
|
|
171
|
+
schema: alternativeSchema,
|
|
172
|
+
discriminator: alternativeDiscriminator || (type === "allOf" ? parentDiscriminator : void 0),
|
|
173
|
+
discriminatorValue: !alternativeDiscriminator && type === "allOf" ? parentDiscriminatorValue : void 0,
|
|
174
|
+
circularRefs,
|
|
175
|
+
context
|
|
176
|
+
}), index < schemas.length - 1 ? /* @__PURE__ */ jsx(OpenAPISchemaAlternativeSeparator, {
|
|
177
|
+
schema,
|
|
178
|
+
context
|
|
179
|
+
}) : null]
|
|
180
|
+
}, index);
|
|
181
|
+
})
|
|
182
|
+
});
|
|
122
183
|
}
|
|
123
184
|
/**
|
|
124
185
|
* Render a tab for an alternative schema.
|
|
@@ -129,13 +190,29 @@ function OpenAPISchemaAlternative(props) {
|
|
|
129
190
|
const { schema, discriminator, circularRefs, context } = props;
|
|
130
191
|
const discriminatorValue = props.discriminatorValue || getDiscriminatorValue(schema, discriminator);
|
|
131
192
|
const properties = getSchemaProperties(schema, discriminator, discriminatorValue);
|
|
132
|
-
return properties?.length ?
|
|
133
|
-
|
|
134
|
-
|
|
193
|
+
return properties?.length ? /* @__PURE__ */ jsx(OpenAPIDisclosure, {
|
|
194
|
+
icon: context.icons.plus,
|
|
195
|
+
header: /* @__PURE__ */ jsx(OpenAPISchemaPresentation, {
|
|
196
|
+
property: { schema },
|
|
197
|
+
context
|
|
198
|
+
}),
|
|
199
|
+
label: (isExpanded) => getDisclosureLabel({
|
|
200
|
+
schema,
|
|
201
|
+
isExpanded,
|
|
202
|
+
context
|
|
203
|
+
}),
|
|
204
|
+
children: /* @__PURE__ */ jsx(OpenAPISchemaProperties, {
|
|
205
|
+
properties,
|
|
206
|
+
circularRefs,
|
|
207
|
+
context
|
|
208
|
+
})
|
|
209
|
+
}) : /* @__PURE__ */ jsx(OpenAPISchemaProperty, {
|
|
210
|
+
property: { schema },
|
|
211
|
+
discriminator,
|
|
212
|
+
discriminatorValue,
|
|
213
|
+
circularRefs,
|
|
135
214
|
context
|
|
136
|
-
})
|
|
137
|
-
<OpenAPISchemaProperties properties={properties} circularRefs={circularRefs} context={context} />
|
|
138
|
-
</OpenAPIDisclosure> : <OpenAPISchemaProperty property={{ schema }} discriminator={discriminator} discriminatorValue={discriminatorValue} circularRefs={circularRefs} context={context} />;
|
|
215
|
+
});
|
|
139
216
|
}
|
|
140
217
|
function OpenAPISchemaAlternativeSeparator(props) {
|
|
141
218
|
const { schema, context } = props;
|
|
@@ -143,20 +220,31 @@ function OpenAPISchemaAlternativeSeparator(props) {
|
|
|
143
220
|
const oneOf = schema.oneOf || schema.items?.oneOf;
|
|
144
221
|
const allOf = schema.allOf || schema.items?.allOf;
|
|
145
222
|
if (!anyOf && !oneOf && !allOf) return null;
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
223
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
224
|
+
className: "openapi-schema-alternative-separator",
|
|
225
|
+
children: [(anyOf || oneOf) && tString(context.translation, "or"), allOf && tString(context.translation, "and")]
|
|
226
|
+
});
|
|
150
227
|
}
|
|
151
228
|
/**
|
|
152
229
|
* Render a circular reference to a schema.
|
|
153
230
|
*/
|
|
154
231
|
function OpenAPISchemaCircularRef(props) {
|
|
155
232
|
const { id, schema } = props;
|
|
156
|
-
return
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
233
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
234
|
+
className: "openapi-schema-circular",
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsx("span", {
|
|
237
|
+
className: "openapi-schema-circular-glyph",
|
|
238
|
+
children: "⤷"
|
|
239
|
+
}),
|
|
240
|
+
"Circular reference to ",
|
|
241
|
+
/* @__PURE__ */ jsx("a", {
|
|
242
|
+
href: `#${id}`,
|
|
243
|
+
children: getSchemaTitle(schema)
|
|
244
|
+
}),
|
|
245
|
+
" "
|
|
246
|
+
]
|
|
247
|
+
});
|
|
160
248
|
}
|
|
161
249
|
/**
|
|
162
250
|
* Render the enum value for a schema.
|
|
@@ -184,14 +272,24 @@ function OpenAPISchemaEnum(props) {
|
|
|
184
272
|
});
|
|
185
273
|
})();
|
|
186
274
|
if (!enumValues?.length) return null;
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
275
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
276
|
+
className: "openapi-schema-enum",
|
|
277
|
+
children: [
|
|
278
|
+
tString(context.translation, "possible_values"),
|
|
279
|
+
":",
|
|
280
|
+
" ",
|
|
281
|
+
enumValues.map((item, index) => /* @__PURE__ */ jsx("span", {
|
|
282
|
+
className: "openapi-schema-enum-value",
|
|
283
|
+
children: /* @__PURE__ */ jsx(OpenAPICopyButton, {
|
|
284
|
+
value: item.value,
|
|
285
|
+
label: item.description,
|
|
286
|
+
withTooltip: !!item.description,
|
|
287
|
+
context,
|
|
288
|
+
children: /* @__PURE__ */ jsx("code", { children: `${item.value}` })
|
|
289
|
+
})
|
|
290
|
+
}, index))
|
|
291
|
+
]
|
|
292
|
+
});
|
|
195
293
|
}
|
|
196
294
|
/**
|
|
197
295
|
* Render the top row of a schema. e.g: name, type, and required status.
|
|
@@ -200,31 +298,57 @@ function OpenAPISchemaPresentation(props) {
|
|
|
200
298
|
const { id, property: { schema, propertyName, required, isDiscriminatorProperty }, circularRefId, context } = props;
|
|
201
299
|
const description = resolveDescription(schema);
|
|
202
300
|
const example = resolveFirstExample(schema);
|
|
203
|
-
return
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
301
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
302
|
+
id,
|
|
303
|
+
className: "openapi-schema-presentation",
|
|
304
|
+
children: [/* @__PURE__ */ jsx(OpenAPISchemaName, {
|
|
305
|
+
schema,
|
|
306
|
+
type: getSchemaTitle(schema, { ignoreAlternatives: !propertyName }),
|
|
307
|
+
propertyName,
|
|
308
|
+
isDiscriminatorProperty,
|
|
309
|
+
required,
|
|
310
|
+
context
|
|
311
|
+
}), circularRefId ? /* @__PURE__ */ jsx(OpenAPISchemaCircularRef, {
|
|
312
|
+
id: circularRefId,
|
|
313
|
+
schema
|
|
314
|
+
}) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
315
|
+
typeof schema["x-deprecated-sunset"] === "string" ? /* @__PURE__ */ jsxs("div", {
|
|
316
|
+
className: "openapi-deprecated-sunset openapi-schema-description openapi-markdown",
|
|
317
|
+
children: [
|
|
318
|
+
"Sunset date:",
|
|
319
|
+
" ",
|
|
320
|
+
/* @__PURE__ */ jsx("span", {
|
|
321
|
+
className: "openapi-deprecated-sunset-date",
|
|
322
|
+
children: schema["x-deprecated-sunset"]
|
|
323
|
+
})
|
|
324
|
+
]
|
|
325
|
+
}) : null,
|
|
326
|
+
description ? /* @__PURE__ */ jsx(Markdown, {
|
|
327
|
+
source: description,
|
|
328
|
+
className: "openapi-schema-description"
|
|
329
|
+
}) : null,
|
|
330
|
+
schema.default !== void 0 ? /* @__PURE__ */ jsxs("span", {
|
|
331
|
+
className: "openapi-schema-default",
|
|
332
|
+
children: [
|
|
333
|
+
"Default:",
|
|
334
|
+
" ",
|
|
335
|
+
/* @__PURE__ */ jsx("code", { children: typeof schema.default === "string" && schema.default ? schema.default : stringifyOpenAPI(schema.default) })
|
|
336
|
+
]
|
|
337
|
+
}) : null,
|
|
338
|
+
typeof example === "string" ? /* @__PURE__ */ jsxs("span", {
|
|
339
|
+
className: "openapi-schema-example",
|
|
340
|
+
children: ["Example: ", /* @__PURE__ */ jsx("code", { children: example })]
|
|
341
|
+
}) : null,
|
|
342
|
+
schema.pattern ? /* @__PURE__ */ jsxs("span", {
|
|
343
|
+
className: "openapi-schema-pattern",
|
|
344
|
+
children: ["Pattern: ", /* @__PURE__ */ jsx("code", { children: schema.pattern })]
|
|
345
|
+
}) : null,
|
|
346
|
+
/* @__PURE__ */ jsx(OpenAPISchemaEnum, {
|
|
347
|
+
schema,
|
|
348
|
+
context
|
|
349
|
+
})
|
|
350
|
+
] })]
|
|
351
|
+
});
|
|
228
352
|
}
|
|
229
353
|
/**
|
|
230
354
|
* Process properties from a schema object into property entries.
|