UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

20 lines (19 loc) 879 B
import { normalizeMimeTypeObject, getObjectKeys } from "@scalar/oas-utils/helpers"; function hasMediaTypeContent(mediaType) { if (!mediaType) { return false; } const hasSchema = Boolean(mediaType.schema); const hasExample = "example" in mediaType && mediaType.example !== null; const hasExamples = Boolean(mediaType.examples); return hasSchema || hasExample || hasExamples; } function hasResponseContent(response) { const normalizedContent = normalizeMimeTypeObject(response?.content); const keys = getObjectKeys(normalizedContent ?? {}); const mediaType = normalizedContent?.["application/json"] ?? normalizedContent?.["application/xml"] ?? normalizedContent?.["text/plain"] ?? normalizedContent?.["text/html"] ?? normalizedContent?.["*/*"] ?? normalizedContent?.[keys[0] ?? ""]; return hasMediaTypeContent(mediaType); } export { hasResponseContent };