mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 20:20:35 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a3b2dea1 | |||
| 17ee7bdebf |
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Display OpenAPI response examples in multiple languages
|
||||||
@@ -46,13 +46,10 @@ export function OpenAPIResponseExample(props: {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const key = Object.keys(responseObject.content)[0];
|
const key = Object.keys(responseObject.content)[0];
|
||||||
return (
|
return [key, key ? responseObject.content[key] : null];
|
||||||
responseObject.content['application/json'] ??
|
|
||||||
(key ? responseObject.content[key] : null)
|
|
||||||
);
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if (!mediaTypeObject) {
|
if (!mediaTypeObject || !mediaTypeObject[1]) {
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
label: key,
|
label: key,
|
||||||
@@ -63,7 +60,7 @@ export function OpenAPIResponseExample(props: {
|
|||||||
|
|
||||||
const example = handleUnresolvedReference(
|
const example = handleUnresolvedReference(
|
||||||
(() => {
|
(() => {
|
||||||
const { examples, example } = mediaTypeObject;
|
const { examples, example } = mediaTypeObject[1];
|
||||||
if (examples) {
|
if (examples) {
|
||||||
const key = Object.keys(examples)[0];
|
const key = Object.keys(examples)[0];
|
||||||
if (key) {
|
if (key) {
|
||||||
@@ -79,7 +76,7 @@ export function OpenAPIResponseExample(props: {
|
|||||||
return { value: example };
|
return { value: example };
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = mediaTypeObject.schema;
|
const schema = mediaTypeObject[1].schema;
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -99,7 +96,7 @@ export function OpenAPIResponseExample(props: {
|
|||||||
? example.value
|
? example.value
|
||||||
: stringifyOpenAPI(example.value, null, 2)
|
: stringifyOpenAPI(example.value, null, 2)
|
||||||
}
|
}
|
||||||
syntax="json"
|
syntax={fetchSyntaxFromContentType(mediaTypeObject[0])}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<OpenAPIEmptyResponseExample />
|
<OpenAPIEmptyResponseExample />
|
||||||
@@ -143,3 +140,11 @@ function handleUnresolvedReference(
|
|||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fetchSyntaxFromContentType(contentType: string) {
|
||||||
|
if (contentType.includes('json')) {
|
||||||
|
return 'json';
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentType.split('/')[1] || 'json';
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user