UNPKG

@tsed/schema

Version:
41 lines (40 loc) 1.21 kB
import { mapHeaders } from "../utils/mapHeaders.js"; import { toJsonMapCollection } from "../utils/toJsonMapCollection.js"; import { JsonMap } from "./JsonMap.js"; import { JsonMedia } from "./JsonMedia.js"; export class JsonResponse extends JsonMap { constructor(obj = {}) { super(obj); this.$kind = "operationResponse"; this.content(obj.content || {}); } description(description) { this.set("description", description); return this; } headers(headers) { this.set("headers", mapHeaders(headers)); return this; } content(content) { this.set("content", toJsonMapCollection(content, JsonMedia)); return this; } getContent() { return this.get("content"); } getMedia(mediaType, create = true) { create && this.addMedia(mediaType); return this.getContent()?.get(mediaType); } addMedia(mediaType) { const content = this.get("content"); if (!content.has(mediaType)) { content.set(mediaType, new JsonMedia()); } return this; } isBinary() { return this.getContent().has("application/octet-stream"); } }