diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx')
-rw-r--r-- | server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx b/server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx index 2fca7f158c3..19cce2011ba 100644 --- a/server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx +++ b/server/sonar-web/src/main/js/apps/web-api-v2/components/ApiResponseSchema.tsx @@ -19,31 +19,32 @@ */ import { CodeSnippet, TextMuted } from 'design-system'; import { OpenAPIV3 } from 'openapi-types'; -import React, { HtmlHTMLAttributes } from 'react'; +import React from 'react'; import { translate } from '../../../helpers/l10n'; import { ExcludeReferences } from '../types'; -import { mapOpenAPISchema } from '../utils'; +import { extractSchemaAndMediaType } from '../utils'; -interface Props extends Omit<HtmlHTMLAttributes<HTMLDivElement>, 'content'> { +interface Props { content?: Exclude<ExcludeReferences<OpenAPIV3.ResponseObject>['content'], undefined>; } export default function ApiResponseSchema(props: Readonly<Props>) { const { content, ...other } = props; - const schema = - content && - (content['application/json']?.schema || content['application/merge-patch+json']?.schema); - if (!schema) { + + const results = extractSchemaAndMediaType(content); + + if (results.length === 0) { return <TextMuted text={translate('no_data')} />; } - return ( + return results.map(({ requestMediaType, schema }) => ( <CodeSnippet + key={requestMediaType} language="json" className="sw-p-6" - snippet={JSON.stringify(mapOpenAPISchema(schema), null, 2)} + snippet={schema} wrap="words" {...other} /> - ); + )); } |