@tsed/schema
Advanced tools
Comparing version 6.1.5 to 6.2.0
import { Type } from "@tsed/core"; | ||
import { JsonSchemaObject } from "../../domain"; | ||
import { JsonParameterTypes } from "../../domain/JsonParameterTypes"; | ||
@@ -26,2 +27,12 @@ export interface InChainedDecorators { | ||
Required(required?: boolean): this; | ||
/** | ||
* Add pattern constraint. Only available for OPENAPI. | ||
* @param pattern | ||
*/ | ||
Pattern(pattern: string | RegExp): this; | ||
/** | ||
* Add custom schema. | ||
* @param schema | ||
*/ | ||
Schema(schema: Partial<JsonSchemaObject>): this; | ||
} | ||
@@ -28,0 +39,0 @@ /** |
@@ -33,3 +33,3 @@ "use strict"; | ||
const jsonParameter = new domain_1.JsonParameter(); | ||
const types = {}; | ||
const schema = {}; | ||
const decorator = (target, propertyKey, index) => { | ||
@@ -44,3 +44,3 @@ const store = domain_1.JsonEntityStore.from(target, propertyKey, index); | ||
store.operation.addParameter(-1, jsonParameter); | ||
jsonParameter.schema(domain_1.JsonSchema.from({ type: types.type })); | ||
jsonParameter.schema(domain_1.JsonSchema.from(schema)); | ||
break; | ||
@@ -52,3 +52,3 @@ default: | ||
decorator.Type = (type) => { | ||
types.type = type; | ||
schema.type = type; | ||
return decorator; | ||
@@ -68,2 +68,9 @@ }; | ||
}; | ||
decorator.Pattern = (pattern) => { | ||
return decorator.Schema({ pattern: pattern.toString() }); | ||
}; | ||
decorator.Schema = (_schema) => { | ||
Object.assign(schema, _schema); | ||
return decorator; | ||
}; | ||
return decorator; | ||
@@ -70,0 +77,0 @@ } |
@@ -46,27 +46,28 @@ "use strict"; | ||
parameter.required = parameter.required || this.get("in") === "path"; | ||
if (!jsonSchema.$ref && (this.get("in") === "path" || Object.keys(jsonSchema).length === 1)) { | ||
parameter.type = jsonSchema.type; | ||
} | ||
else if (options.specType === SpecTypes_1.SpecTypes.SWAGGER && this.get("in") === "query") { | ||
if (jsonSchema.$ref) { | ||
return this.refToParameters(parameter, options, schemas); | ||
if (options.specType === SpecTypes_1.SpecTypes.SWAGGER) { | ||
if (!jsonSchema.$ref && Object.keys(jsonSchema).length === 1) { | ||
parameter.type = jsonSchema.type; | ||
return parameter; | ||
} | ||
if (jsonSchema.type === "array") { | ||
if (this.get("in") === "query") { | ||
if (jsonSchema.$ref) { | ||
return this.refToParameters(parameter, options, schemas); | ||
} | ||
if (jsonSchema.type === "array") { | ||
return { | ||
...parameter, | ||
type: "array", | ||
collectionFormat: "multi", | ||
items: { | ||
type: "string" | ||
} | ||
}; | ||
} | ||
return { | ||
...parameter, | ||
type: "array", | ||
collectionFormat: "multi", | ||
items: { | ||
type: "string" | ||
} | ||
...jsonSchema | ||
}; | ||
} | ||
return { | ||
...parameter, | ||
...jsonSchema | ||
}; | ||
} | ||
else { | ||
parameter.schema = jsonSchema; | ||
} | ||
parameter.schema = jsonSchema; | ||
return parameter; | ||
@@ -73,0 +74,0 @@ } |
{ | ||
"name": "@tsed/schema", | ||
"version": "6.1.5", | ||
"version": "6.2.0", | ||
"description": "JsonSchema module for Ts.ED Framework", | ||
@@ -18,4 +18,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@tsed/core": "6.1.5", | ||
"@tsed/openspec": "6.1.5", | ||
"@tsed/core": "6.2.0", | ||
"@tsed/openspec": "6.2.0", | ||
"change-case": "4.1.1", | ||
@@ -22,0 +22,0 @@ "tslib": "2.0.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
530632
9805
+ Added@tsed/core@6.2.0(transitive)
+ Added@tsed/openspec@6.2.0(transitive)
- Removed@tsed/core@6.1.5(transitive)
- Removed@tsed/openspec@6.1.5(transitive)
Updated@tsed/core@6.2.0
Updated@tsed/openspec@6.2.0