UNPKG

@tsed/schema

Version:
61 lines (60 loc) 1.72 kB
import { execMapper } from "../registries/JsonSchemaMapperContainer.js"; import { JsonMap } from "./JsonMap.js"; import { formatParameterType } from "./JsonParameterTypes.js"; import { JsonSchema } from "./JsonSchema.js"; export class JsonParameter extends JsonMap { constructor(obj = {}) { super(obj); this.$kind = "operationInParameter"; if (!this.has("schema")) { this.set("schema", new JsonSchema()); } } getName() { const name = this.get("name"); if (this.get("in") === "files") { return name.split(".")[0]; } return name; } name(name) { this.set("name", name); return this; } examples(examples) { super.set("examples", examples); return this; } description(description) { this.set("description", description); return this; } in(inType, expression = "") { this.set("in", formatParameterType(inType)); this.expression = expression; return this; } required(required) { this.set("required", required); return this; } schema(schema) { if (schema) { this.set("schema", schema); return this; } return this.get("schema"); } itemSchema(schema) { if (this.schema().isCollection) { schema && this.schema().itemSchema(schema); return this.schema().itemSchema(); } schema && this.schema(schema); // non-collection: delegate to the main schema return this.schema(); } toJSON(options) { return execMapper("operationInParameter", [this], options); } }