Skip to content

Commit f43b8bf

Browse files
committed
Update Token API JSON + fix code accordingly
1 parent bc9c3d0 commit f43b8bf

File tree

3 files changed

+3583
-1668
lines changed

3 files changed

+3583
-1668
lines changed

website/src/layout/templates/openApi/aside.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function TemplateOpenApiAsideContent(props: ComponentProps<'div'>) {
196196
: []),
197197
...operation.potentialResponses.map((potentialResponse) => {
198198
const label = `${potentialResponse.status} ${t('global.openApi.responses.example')}`
199-
const exampleResponseText = JSON.stringify(potentialResponse.example, null, 2)
199+
const exampleResponseText = JSON.stringify(potentialResponse.example, undefined, 2) || ''
200200
return {
201201
label,
202202
content: (

website/src/openApi/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ function isParameterObject(
8383
return !('$ref' in value) && 'in' in value
8484
}
8585

86+
function isExampleObject(
87+
value: OpenAPIV3_1.ExampleObject | OpenAPIV3_1.ReferenceObject,
88+
): value is OpenAPIV3_1.ExampleObject {
89+
return typeof value === 'object' && value !== null && 'value' in value
90+
}
91+
8692
function transformParameter(parameter: OpenAPIV3_1.ParameterObject): ApiParameter {
8793
const schema = (
8894
parameter.content ? Object.values(parameter.content)[0]?.schema : parameter.schema
@@ -158,11 +164,13 @@ export function getApi(apiId: ApiId, passedDocument?: OpenAPIV3_1.Document): Api
158164
if (!('content' in response) || typeof response.content !== 'object') continue
159165
const content = response.content['application/json'] ?? response.content['text/plain']
160166
if (!content || '$ref' in content || !content.schema || '$ref' in content.schema) continue
167+
const exampleObject = content.examples ? Object.values(content.examples)[0] : undefined
168+
const example = exampleObject && isExampleObject(exampleObject) ? exampleObject.value : content.example
161169
potentialResponses.push({
162170
...response,
163171
status,
164172
schema: content.schema,
165-
example: content.example,
173+
example,
166174
})
167175
}
168176

0 commit comments

Comments
 (0)