@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
38 lines (37 loc) • 1.04 kB
JavaScript
import { isArray, isClass } from "@tsed/core";
import { JsonMap } from "./JsonMap.js";
import { JsonSchema } from "./JsonSchema.js";
export class JsonMedia extends JsonMap {
constructor(obj = {}) {
super(obj);
this.$kind = "operationMedia";
if (!this.has("schema")) {
this.set("schema", new JsonSchema());
}
}
schema(schema) {
schema && this.set("schema", schema);
return this.get("schema");
}
examples(examples) {
examples && this.set("examples", examples);
return this;
}
type(type) {
if (type) {
if (isArray(type)) {
this.schema().oneOf(type.map((type) => ({ type })));
}
else {
if (isClass(type)) {
this.schema().type("object");
this.schema().itemSchema(type);
}
else {
this.schema().type(type);
}
}
}
return this;
}
}