@scalar/openapi-to-markdown 1.5.3 → 1.5.4
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 +7 -0
- package/dist/document-anchors.d.ts.map +1 -1
- package/dist/document-anchors.js +4 -2
- package/dist/document-examples.d.ts.map +1 -1
- package/dist/document-examples.js +10 -5
- package/dist/get-markdown-examples.d.ts.map +1 -1
- package/dist/get-markdown-examples.js +48 -24
- package/dist/load-document.d.ts.map +1 -1
- package/dist/load-document.js +16 -10
- package/dist/parse-description.d.ts.map +1 -1
- package/dist/parse-description.js +36 -18
- package/dist/render-document.d.ts.map +1 -1
- package/dist/render-document.js +48 -24
- package/dist/render-examples.d.ts.map +1 -1
- package/dist/render-examples.js +8 -4
- package/dist/render-operation-details.d.ts.map +1 -1
- package/dist/render-operation-details.js +28 -14
- package/dist/render-operation.d.ts.map +1 -1
- package/dist/render-operation.js +60 -31
- package/dist/render-schema.d.ts.map +1 -1
- package/dist/render-schema.js +145 -77
- package/dist/render-security.d.ts.map +1 -1
- package/dist/render-security.js +12 -6
- package/dist/restore-boolean-schemas.d.ts.map +1 -1
- package/dist/restore-boolean-schemas.js +22 -11
- package/dist/select-document.d.ts.map +1 -1
- package/dist/select-document.js +5 -1
- package/package.json +8 -8
package/dist/render-examples.js
CHANGED
|
@@ -10,11 +10,13 @@ schemaOpenapiVersion = openapiVersion, { linked = false, quiet = linked, example
|
|
|
10
10
|
const nodes = [];
|
|
11
11
|
const values = (examples?.get ?? getMarkdownExamples)(source, mediaType, mode, openapiVersion, schemaOpenapiVersion, linked);
|
|
12
12
|
for (const example of values) {
|
|
13
|
-
if ('omitted' in example && quiet)
|
|
13
|
+
if ('omitted' in example && quiet) {
|
|
14
14
|
continue;
|
|
15
|
+
}
|
|
15
16
|
const start = nodes.length;
|
|
16
17
|
const generated = examples && example.generated;
|
|
17
|
-
|
|
18
|
+
const exampleLabel = example.name ? `Example: ${example.name}` : 'Example:';
|
|
19
|
+
nodes.push(paragraph(strong(text(generated ? 'Generated example:' : exampleLabel))));
|
|
18
20
|
const addCode = (code) => {
|
|
19
21
|
if (generated) {
|
|
20
22
|
const scope = JSON.stringify([mediaType, mode, openapiVersion, schemaOpenapiVersion, code.lang]);
|
|
@@ -31,8 +33,9 @@ schemaOpenapiVersion = openapiVersion, { linked = false, quiet = linked, example
|
|
|
31
33
|
nodes.push(paragraph(emphasis(text('Generated example omitted because it is too large.'))));
|
|
32
34
|
continue;
|
|
33
35
|
}
|
|
34
|
-
if (example.summary)
|
|
36
|
+
if (example.summary) {
|
|
35
37
|
nodes.push(paragraph(text(example.summary)));
|
|
38
|
+
}
|
|
36
39
|
nodes.push(...(await description(example.description)));
|
|
37
40
|
if ('error' in example) {
|
|
38
41
|
nodes.push(paragraph(text(example.error)));
|
|
@@ -43,9 +46,10 @@ schemaOpenapiVersion = openapiVersion, { linked = false, quiet = linked, example
|
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
48
|
if ('serializedValue' in example) {
|
|
49
|
+
const textLanguage = mediaType.includes('json') ? 'json' : 'text';
|
|
46
50
|
addCode({
|
|
47
51
|
type: 'code',
|
|
48
|
-
lang: isXmlMediaType(mediaType) ? 'xml' :
|
|
52
|
+
lang: isXmlMediaType(mediaType) ? 'xml' : textLanguage,
|
|
49
53
|
value: example.serializedValue,
|
|
50
54
|
});
|
|
51
55
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-operation-details.d.ts","sourceRoot":"","sources":["../src/render-operation-details.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8DAA8D,CAAA;AAClH,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,wFAAwF;AACxF,eAAO,MAAM,aAAa,GACxB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,aAAa,iBAAiB,EAC9B,SAAS,cAAc,EACvB,gBAAgB,MAAM,EACtB,6BAAqC,EACrC,WAAW,gBAAgB,KAC1B,OAAO,CAAC,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"render-operation-details.d.ts","sourceRoot":"","sources":["../src/render-operation-details.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8DAA8D,CAAA;AAClH,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD,wFAAwF;AACxF,eAAO,MAAM,aAAa,GACxB,SAAS,cAAc,CAAC,SAAS,CAAC,EAClC,aAAa,iBAAiB,EAC9B,SAAS,cAAc,EACvB,gBAAgB,MAAM,EACtB,6BAAqC,EACrC,WAAW,gBAAgB,KAC1B,OAAO,CAAC,WAAW,EAAE,CA8CvB,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,SAAS,EACpD,WAAW,MAAM,EACjB,aAAa,iBAAiB,EAC9B,SAAS,cAAc,EACvB,gBAAgB,MAAM,EACtB,6BAAqC,EACrC,WAAW,gBAAgB,KAC1B,OAAO,CAAC,WAAW,EAAE,CAqCvB,CAAA;AAID,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,cAAc,CAAC,OAAO,CAAC,EAC9B,aAAa,iBAAiB,KAC7B,OAAO,CAAC,WAAW,EAAE,CAoCvB,CAAA"}
|
|
@@ -6,24 +6,28 @@ export const renderHeaders = async (headers, description, schemas, openapiVersio
|
|
|
6
6
|
const entries = [];
|
|
7
7
|
for (const [name, reference] of Object.entries(headers ?? {})) {
|
|
8
8
|
// OpenAPI reserves Content-Type for the media type map / encoding field.
|
|
9
|
-
if (name.toLowerCase() === 'content-type')
|
|
9
|
+
if (name.toLowerCase() === 'content-type') {
|
|
10
10
|
continue;
|
|
11
|
-
|
|
11
|
+
}
|
|
12
|
+
if (!getResolvedRef(reference)) {
|
|
12
13
|
continue;
|
|
14
|
+
}
|
|
13
15
|
const header = getResolvedRef(reference, mergeSiblingReferences);
|
|
14
16
|
const blocks = [
|
|
15
17
|
paragraph(strong(inlineCode(name)), text(header.required ? ' (required)' : '')),
|
|
16
18
|
...(await description(header.description)),
|
|
17
19
|
];
|
|
18
|
-
if ('schema' in header && header.schema !== undefined)
|
|
20
|
+
if ('schema' in header && header.schema !== undefined) {
|
|
19
21
|
blocks.push(...schemas.render(header.schema));
|
|
22
|
+
}
|
|
20
23
|
if ('example' in header || 'examples' in header) {
|
|
21
24
|
blocks.push(...(await renderExamples({ example: header.example, examples: header.examples }, description, 'application/json', undefined, openapiVersion, schemaOpenapiVersion, { linked: schemas.linked, examples })));
|
|
22
25
|
}
|
|
23
26
|
for (const [mediaType, content] of Object.entries('content' in header ? (header.content ?? {}) : {})) {
|
|
24
27
|
blocks.push(paragraph(strong(text('Content-Type:')), text(` ${mediaType}`)));
|
|
25
|
-
if (content.schema !== undefined)
|
|
28
|
+
if (content.schema !== undefined) {
|
|
26
29
|
blocks.push(...schemas.render(content.schema));
|
|
30
|
+
}
|
|
27
31
|
blocks.push(...(await renderExamples(content, description, mediaType, undefined, openapiVersion, schemaOpenapiVersion, {
|
|
28
32
|
linked: schemas.linked,
|
|
29
33
|
examples,
|
|
@@ -36,8 +40,9 @@ export const renderHeaders = async (headers, description, schemas, openapiVersio
|
|
|
36
40
|
/** Preserve explicit encoding settings, including false flags and part headers. */
|
|
37
41
|
export const renderEncoding = async (encoding, mediaType, description, schemas, openapiVersion, schemaOpenapiVersion = openapiVersion, examples) => {
|
|
38
42
|
const multipart = mediaType.startsWith('multipart/');
|
|
39
|
-
if (!multipart && mediaType !== 'application/x-www-form-urlencoded')
|
|
43
|
+
if (!multipart && mediaType !== 'application/x-www-form-urlencoded') {
|
|
40
44
|
return [];
|
|
45
|
+
}
|
|
41
46
|
const entries = [];
|
|
42
47
|
for (const [name, entry] of Object.entries(encoding ?? {})) {
|
|
43
48
|
const fields = [];
|
|
@@ -47,14 +52,17 @@ export const renderEncoding = async (encoding, mediaType, description, schemas,
|
|
|
47
52
|
['explode', 'Explode'],
|
|
48
53
|
['allowReserved', 'Allow reserved'],
|
|
49
54
|
]) {
|
|
50
|
-
if (entry[key] !== undefined)
|
|
55
|
+
if (entry[key] !== undefined) {
|
|
51
56
|
fields.push(item(paragraph(text(`${label}: `), inlineCode(entry[key]))));
|
|
57
|
+
}
|
|
52
58
|
}
|
|
53
59
|
const blocks = [paragraph(strong(inlineCode(name)))];
|
|
54
|
-
if (fields.length)
|
|
60
|
+
if (fields.length) {
|
|
55
61
|
blocks.push(list(fields));
|
|
56
|
-
|
|
62
|
+
}
|
|
63
|
+
if (multipart) {
|
|
57
64
|
blocks.push(...(await renderHeaders(entry.headers, description, schemas, openapiVersion, schemaOpenapiVersion, examples)));
|
|
65
|
+
}
|
|
58
66
|
entries.push(item(...blocks));
|
|
59
67
|
}
|
|
60
68
|
return entries.length ? [paragraph(strong(text('Encoding:'))), list(entries)] : [];
|
|
@@ -64,24 +72,30 @@ const formatValue = (value) => (typeof value === 'string' ? value : (JSON.string
|
|
|
64
72
|
export const renderResponseLinks = async (links, description) => {
|
|
65
73
|
const entries = [];
|
|
66
74
|
for (const [name, reference] of Object.entries(links ?? {})) {
|
|
67
|
-
if (!getResolvedRef(reference))
|
|
75
|
+
if (!getResolvedRef(reference)) {
|
|
68
76
|
continue;
|
|
77
|
+
}
|
|
69
78
|
const link = getResolvedRef(reference, mergeSiblingReferences);
|
|
70
79
|
const blocks = [
|
|
71
80
|
paragraph(strong(text(name))),
|
|
72
81
|
...(await description(link.description)),
|
|
73
82
|
];
|
|
74
|
-
if (link.operationId)
|
|
83
|
+
if (link.operationId) {
|
|
75
84
|
blocks.push(paragraph(strong(text('Operation ID:')), text(' '), inlineCode(link.operationId)));
|
|
76
|
-
|
|
85
|
+
}
|
|
86
|
+
if (link.operationRef) {
|
|
77
87
|
blocks.push(paragraph(strong(text('Operation reference:')), text(' '), inlineCode(link.operationRef)));
|
|
88
|
+
}
|
|
78
89
|
const parameters = Object.entries(link.parameters ?? {});
|
|
79
|
-
if (parameters.length)
|
|
90
|
+
if (parameters.length) {
|
|
80
91
|
blocks.push(list(parameters.map(([name, value]) => item(paragraph(strong(text(`${name}:`)), text(' '), inlineCode(formatValue(value)))))));
|
|
81
|
-
|
|
92
|
+
}
|
|
93
|
+
if (link.requestBody !== undefined) {
|
|
82
94
|
blocks.push(paragraph(strong(text('Request body:')), text(' '), inlineCode(formatValue(link.requestBody))));
|
|
83
|
-
|
|
95
|
+
}
|
|
96
|
+
if (link.server) {
|
|
84
97
|
blocks.push(paragraph(strong(text('Server:')), text(' '), inlineCode(link.server.url)));
|
|
98
|
+
}
|
|
85
99
|
entries.push(item(...blocks));
|
|
86
100
|
}
|
|
87
101
|
return entries.length ? [paragraph(strong(text('Links:'))), list(entries)] : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-operation.d.ts","sourceRoot":"","sources":["../src/render-operation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAEf,cAAc,EAGf,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAsC,WAAW,EAAE,MAAM,OAAO,CAAA;AAE5E,OAAO,EAAU,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAA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,CAAA;IACjC,wFAAwF;IACxF,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,qEAAqE;AACrE,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAA;IACjD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACrC,CAAA;AA8CD,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,KAAG,MACkC,CAAA;AAEzF,iFAAiF;AACjF,eAAO,MAAM,eAAe,GAC1B,UAAU,eAAe,EACzB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,UAAU,cAAc,EACxB,WAAW,eAAe,EAC1B,SAAS,OAAO,EAChB,4DAAgE,aAAa,KAC5E,OAAO,CAAC,WAAW,EAAE,CAwMvB,CAAA"}
|
package/dist/render-operation.js
CHANGED
|
@@ -21,22 +21,27 @@ const contentType = (mediaType) => paragraph(strong(text('Content type:')), text
|
|
|
21
21
|
* return the same error schema, share one key. Anything else a response declares keeps it separate.
|
|
22
22
|
*/
|
|
23
23
|
const getResponseKey = (response, ids) => {
|
|
24
|
-
if (Object.keys(response.headers ?? {}).length || Object.keys(response.links ?? {}).length)
|
|
24
|
+
if (Object.keys(response.headers ?? {}).length || Object.keys(response.links ?? {}).length) {
|
|
25
25
|
return undefined;
|
|
26
|
+
}
|
|
26
27
|
const content = Object.entries(response.content ?? {});
|
|
27
|
-
if (!content.length)
|
|
28
|
+
if (!content.length) {
|
|
28
29
|
return undefined;
|
|
30
|
+
}
|
|
29
31
|
const parts = [];
|
|
30
32
|
for (const [mediaType, media] of content) {
|
|
31
33
|
const schema = getResolvedRef(media.schema);
|
|
32
|
-
if (!isObject(schema) || media.example !== undefined || media.examples || media.encoding)
|
|
34
|
+
if (!isObject(schema) || media.example !== undefined || media.examples || media.encoding) {
|
|
33
35
|
return undefined;
|
|
34
|
-
|
|
36
|
+
}
|
|
37
|
+
if (!ids.has(schema)) {
|
|
35
38
|
ids.set(schema, ids.size);
|
|
39
|
+
}
|
|
36
40
|
// Reference siblings change the schema, so only a plain reference shares its target's identity.
|
|
37
41
|
const siblings = isObject(media.schema) ? Object.keys(media.schema).filter((key) => !key.startsWith('$')) : [];
|
|
38
|
-
if (siblings.length)
|
|
42
|
+
if (siblings.length) {
|
|
39
43
|
return undefined;
|
|
44
|
+
}
|
|
40
45
|
parts.push(mediaType, ids.get(schema));
|
|
41
46
|
}
|
|
42
47
|
return JSON.stringify(parts);
|
|
@@ -49,15 +54,18 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
49
54
|
const displayMethod = formatOperationMethod(method);
|
|
50
55
|
const openapiVersion = document['x-original-oas-version'] ?? document.openapi;
|
|
51
56
|
const stability = operation['x-scalar-stability'];
|
|
52
|
-
const
|
|
53
|
-
|
|
57
|
+
const deprecatedLabel = operation.deprecated ? ' ⚠️ Deprecated' : '';
|
|
58
|
+
const title = (operation.summary || `${displayMethod} ${path}`) + (stability ? ` (${stability})` : deprecatedLabel);
|
|
54
59
|
const metadata = [field('Method', inlineCode(displayMethod)), field(webhook ? 'Webhook' : 'Path', inlineCode(path))];
|
|
55
|
-
if (operation.operationId)
|
|
60
|
+
if (operation.operationId) {
|
|
56
61
|
metadata.push(field('Operation ID', inlineCode(operation.operationId)));
|
|
57
|
-
|
|
62
|
+
}
|
|
63
|
+
if (operation.tags) {
|
|
58
64
|
metadata.push(field('Tags', text(operation.tags.join(', '))));
|
|
59
|
-
|
|
65
|
+
}
|
|
66
|
+
if (stability) {
|
|
60
67
|
metadata.push(field('Stability', text(stability)));
|
|
68
|
+
}
|
|
61
69
|
const nodes = [
|
|
62
70
|
heading(h(0), text(title)),
|
|
63
71
|
list(metadata),
|
|
@@ -67,8 +75,9 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
67
75
|
let inheritedServers;
|
|
68
76
|
let serverAnchor;
|
|
69
77
|
if (documentContext && operation.servers === undefined) {
|
|
70
|
-
if (pathItem.servers === undefined)
|
|
78
|
+
if (pathItem.servers === undefined) {
|
|
71
79
|
inheritedServers = documentContext.servers;
|
|
80
|
+
}
|
|
72
81
|
else {
|
|
73
82
|
inheritedServers = documentContext.pathServers.get(pathItem);
|
|
74
83
|
if (inheritedServers === undefined) {
|
|
@@ -81,8 +90,9 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
81
90
|
nodes.push(paragraph(strong(text('Servers:')), text(' '), link(`#${inheritedServers}`, 'Inherited servers')));
|
|
82
91
|
}
|
|
83
92
|
else if (servers !== undefined) {
|
|
84
|
-
if (serverAnchor)
|
|
93
|
+
if (serverAnchor) {
|
|
85
94
|
nodes.push(anchor(serverAnchor));
|
|
95
|
+
}
|
|
86
96
|
nodes.push(heading(h(1), text('Effective servers')));
|
|
87
97
|
const serverItems = [];
|
|
88
98
|
// An explicit empty server array overrides inherited servers with the OAS default `/`.
|
|
@@ -93,23 +103,27 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
93
103
|
...(await description(server.description)),
|
|
94
104
|
];
|
|
95
105
|
const variables = Object.entries(server.variables ?? {});
|
|
96
|
-
if (variables.length)
|
|
106
|
+
if (variables.length) {
|
|
97
107
|
blocks.push(list(await Promise.all(variables.map(async ([name, variable]) => item(paragraph(text(`${name}: `), inlineCode(variable.default), ...(variable.enum?.length
|
|
98
108
|
? [text(', possible values: '), inlineCode(variable.enum.join(', '))]
|
|
99
109
|
: [])), ...(await description(variable.description)))))));
|
|
110
|
+
}
|
|
100
111
|
serverItems.push(item(...blocks));
|
|
101
112
|
}
|
|
102
113
|
nodes.push(list(serverItems));
|
|
103
114
|
}
|
|
104
|
-
if (documentContext?.authentication && operation.security === undefined)
|
|
115
|
+
if (documentContext?.authentication && operation.security === undefined) {
|
|
105
116
|
nodes.push(paragraph(strong(text('Authentication:')), text(' '), link(`#${documentContext.authentication}`, 'Global authentication')));
|
|
106
|
-
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
107
119
|
nodes.push(...(await renderSecurity(operation.security ?? document.security, document.components?.securitySchemes, description, h(1))));
|
|
120
|
+
}
|
|
108
121
|
const parameters = new Map();
|
|
109
122
|
for (const reference of [...(pathItem.parameters ?? []), ...(operation.parameters ?? [])]) {
|
|
110
123
|
const parameter = getResolvedRef(reference, mergeSiblingReferences);
|
|
111
|
-
if (parameter)
|
|
124
|
+
if (parameter) {
|
|
112
125
|
parameters.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
126
|
+
}
|
|
113
127
|
}
|
|
114
128
|
const locations = [
|
|
115
129
|
...parameterLocations,
|
|
@@ -120,22 +134,26 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
120
134
|
for (const [location, sectionTitle] of locations) {
|
|
121
135
|
const entries = [];
|
|
122
136
|
for (const parameter of parameters.values()) {
|
|
123
|
-
if (parameter.in !== location)
|
|
137
|
+
if (parameter.in !== location) {
|
|
124
138
|
continue;
|
|
139
|
+
}
|
|
125
140
|
entries.push(await renderParameter(parameter, { description, schemas, examples, openapiVersion, document }));
|
|
126
141
|
}
|
|
127
|
-
if (entries.length)
|
|
142
|
+
if (entries.length) {
|
|
128
143
|
nodes.push(heading(h(1), text(sectionTitle)), list(entries));
|
|
144
|
+
}
|
|
129
145
|
}
|
|
130
146
|
const body = getResolvedRef(operation.requestBody, mergeSiblingReferences);
|
|
131
147
|
if (body) {
|
|
132
148
|
nodes.push(heading(h(1), text('Request body')), ...(await description(body.description)));
|
|
133
|
-
if (typeof body.required === 'boolean')
|
|
149
|
+
if (typeof body.required === 'boolean') {
|
|
134
150
|
nodes.push(paragraph(strong(text('Required:')), text(' '), inlineCode(body.required)));
|
|
151
|
+
}
|
|
135
152
|
for (const [mediaType, content] of Object.entries(body.content ?? {})) {
|
|
136
153
|
nodes.push(contentType(mediaType));
|
|
137
|
-
if (content.schema !== undefined)
|
|
154
|
+
if (content.schema !== undefined) {
|
|
138
155
|
nodes.push(...schemas.render(content.schema));
|
|
156
|
+
}
|
|
139
157
|
nodes.push(...(await renderExamples(content, description, mediaType, 'write', openapiVersion, document.openapi, {
|
|
140
158
|
linked: schemas.linked,
|
|
141
159
|
examples,
|
|
@@ -154,8 +172,9 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
154
172
|
const key = getResponseKey(entry.response, ids) ?? `status:${entry.status}`;
|
|
155
173
|
groups.set(key, [...(groups.get(key) ?? []), entry]);
|
|
156
174
|
}
|
|
157
|
-
if (responses.length)
|
|
175
|
+
if (responses.length) {
|
|
158
176
|
nodes.push(heading(h(1), text('Responses')));
|
|
177
|
+
}
|
|
159
178
|
for (const group of groups.values()) {
|
|
160
179
|
const { response } = group[0];
|
|
161
180
|
if (group.length > 1) {
|
|
@@ -168,8 +187,9 @@ export const renderOperation = async (document, path, method, pathItem, operatio
|
|
|
168
187
|
nodes.push(...(await renderHeaders(response.headers, description, schemas, openapiVersion, document.openapi, examples)), ...(await renderResponseLinks(response.links, description)));
|
|
169
188
|
for (const [mediaType, content] of Object.entries(response.content ?? {})) {
|
|
170
189
|
nodes.push(contentType(mediaType));
|
|
171
|
-
if (content.schema !== undefined)
|
|
190
|
+
if (content.schema !== undefined) {
|
|
172
191
|
nodes.push(...schemas.render(content.schema));
|
|
192
|
+
}
|
|
173
193
|
nodes.push(...(await renderExamples(content, description, mediaType, 'read', openapiVersion, document.openapi, {
|
|
174
194
|
linked: schemas.linked,
|
|
175
195
|
examples,
|
|
@@ -187,19 +207,25 @@ const renderParameter = async (parameter, { description, schemas, examples, open
|
|
|
187
207
|
const schema = 'schema' in parameter ? parameter.schema : undefined;
|
|
188
208
|
const summary = schema === undefined ? [] : schemas.summarize(schema);
|
|
189
209
|
const add = (label, value) => {
|
|
190
|
-
if (value !== undefined)
|
|
210
|
+
if (value !== undefined) {
|
|
191
211
|
summary.push(text(`${summary.length ? ', ' : ''}${label}: `), inlineCode(value));
|
|
212
|
+
}
|
|
192
213
|
};
|
|
193
|
-
if ('style' in parameter)
|
|
214
|
+
if ('style' in parameter) {
|
|
194
215
|
add('style', parameter.style);
|
|
195
|
-
|
|
216
|
+
}
|
|
217
|
+
if ('explode' in parameter && typeof parameter.explode === 'boolean') {
|
|
196
218
|
add('explode', parameter.explode);
|
|
197
|
-
|
|
219
|
+
}
|
|
220
|
+
if (parameter.allowEmptyValue) {
|
|
198
221
|
add('allowEmptyValue', true);
|
|
199
|
-
|
|
222
|
+
}
|
|
223
|
+
if ('allowReserved' in parameter && parameter.allowReserved) {
|
|
200
224
|
add('allowReserved', true);
|
|
201
|
-
|
|
225
|
+
}
|
|
226
|
+
if (summary.length) {
|
|
202
227
|
title.push(text(': '), ...summary);
|
|
228
|
+
}
|
|
203
229
|
const blocks = [
|
|
204
230
|
paragraph(...title),
|
|
205
231
|
...(await description(parameter.description)),
|
|
@@ -207,16 +233,19 @@ const renderParameter = async (parameter, { description, schemas, examples, open
|
|
|
207
233
|
if (schema !== undefined) {
|
|
208
234
|
// The schema's own description usually repeats the parameter's, so print it only when it differs.
|
|
209
235
|
const schemaDescription = schemas.view(schema).description;
|
|
210
|
-
if (schemaDescription?.trim() !== parameter.description?.trim())
|
|
236
|
+
if (schemaDescription?.trim() !== parameter.description?.trim()) {
|
|
211
237
|
blocks.push(...describe(schemaDescription));
|
|
238
|
+
}
|
|
212
239
|
blocks.push(...schemas.render(schema, 0, [], { hideDetails: true }));
|
|
213
240
|
}
|
|
214
|
-
if ('example' in parameter || 'examples' in parameter)
|
|
241
|
+
if ('example' in parameter || 'examples' in parameter) {
|
|
215
242
|
blocks.push(...(await renderExamples({ example: parameter.example, examples: parameter.examples }, description, 'application/json', 'write', openapiVersion, document.openapi, { examples })));
|
|
243
|
+
}
|
|
216
244
|
for (const [mediaType, content] of Object.entries('content' in parameter ? (parameter.content ?? {}) : {})) {
|
|
217
245
|
blocks.push(contentType(mediaType));
|
|
218
|
-
if (content.schema !== undefined)
|
|
246
|
+
if (content.schema !== undefined) {
|
|
219
247
|
blocks.push(...schemas.render(content.schema));
|
|
248
|
+
}
|
|
220
249
|
blocks.push(...(await renderExamples(content, description, mediaType, 'write', openapiVersion, document.openapi, {
|
|
221
250
|
linked: schemas.linked,
|
|
222
251
|
examples,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-schema.d.ts","sourceRoot":"","sources":["../src/render-schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAA;AAC5G,OAAO,KAAK,EAAY,eAAe,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D,uFAAuF;AACvF,KAAK,cAAc,GAAG,oBAAoB,GAAG,OAAO,CAAA;AAEpD,qGAAqG;AACrG,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;IACxB,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAA;IAC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