1
0
mirror of synced 2025-12-20 18:36:31 -05:00

REST two-pane layout (#26954)

This commit is contained in:
Rachael Sewell
2022-05-02 10:10:33 -07:00
committed by GitHub
parent 50c8da01a1
commit 5f4f858b94
35 changed files with 2021551 additions and 27106 deletions

View File

@@ -15,7 +15,35 @@ export default function getCodeSamples(operation) {
const responseExamples = getResponseExamples(operation)
const requestExamples = getRequestExamples(operation)
return mergeExamples(requestExamples, responseExamples)
const mergedExamples = mergeExamples(requestExamples, responseExamples)
// If there are multiple examples and if the request body
// has the same description, add a number to the example
if (mergedExamples.length > 1) {
const count = {}
mergedExamples.forEach((item) => {
count[item.request.description] = (count[item.request.description] || 0) + 1
})
const newMergedExamples = mergedExamples.map((example, i) => ({
...example,
request: {
...example.request,
description:
count[example.request.description] > 1
? example.request.description +
' ' +
(i + 1) +
': Status Code ' +
example.response.statusCode
: example.request.description,
},
}))
return newMergedExamples
}
return mergedExamples
}
export function mergeExamples(requestExamples, responseExamples) {
@@ -264,9 +292,9 @@ export function getResponseExamples(operation) {
responseExamples.push(example)
return
} else {
// Example for this content type doesn't exist.
// We could also check if there is a fully populated example
// directly in the response schema examples properties.
// Example for this content type doesn't exist
return
}
@@ -285,7 +313,7 @@ export function getResponseExamples(operation) {
// how we write the JSON file helps a lot, but we should revisit
// adding the response schema to ensure we have a way to view the
// prettified JSON before minimizing it.
// schema: operation.responses[statusCode].content[contentType].schema,
schema: operation.responses[statusCode].content[contentType].schema,
},
}
responseExamples.push(example)