@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
61 lines (60 loc) • 1.08 kB
JavaScript
import { JsonEntityFn } from "./jsonEntityFn.js";
/**
* Write data formatted to JsonSchema.
*
* ## Example
*
* ```typescript
* @Schema({title: "test"})
* class Model {
* @Schema({formatMinimum: "1987-10-24"})
* @Format("date")
* birthDate: Date
* }
* ```
*
* Will produce:
*
* ```json
* {
* "type": "object",
* "title": "test",
* "properties": {
* "birthdate": {
* "type": "string",
* "format": "date",
* "formatMinimum": "1987-10-24"
* }
* }
* }
* ```
*
* @param partialSchema
* @decorator
* @validation
* @swagger
* @schema
* @classDecorator
* @input
*/
export function Schema(partialSchema) {
return JsonEntityFn((entity) => {
entity.schema.assign(partialSchema);
});
}
/**
* Apply specific schema depending on the spec version
* @param specType
* @param schema
* @decorator
* @validation
* @swagger
* @schema
* @classDecorator
* @input
*/
export function For(specType, schema) {
return JsonEntityFn((entity) => {
entity.schema.set(specType, schema);
});
}