request-typer
Advanced tools
Comparing version 1.3.6 to 1.3.7
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const Parameter_1 = require("../Parameter"); | ||
const schema_1 = require("../schema"); | ||
const __1 = require(".."); | ||
describe("Parameter", () => { | ||
describe("Parameter.Query", () => { | ||
it("should return QueryParamter object", () => { | ||
const parameter = Parameter_1.Parameter.Query(schema_1.Schema.Number()); | ||
const parameter = __1.Parameter.Query(__1.Schema.Number()); | ||
(0, chai_1.expect)(parameter.type).to.be.eq("query"); | ||
@@ -16,3 +15,3 @@ (0, chai_1.expect)(parameter.schema.type).to.be.eq("number"); | ||
it("should return PathParameter object", () => { | ||
const parameter = Parameter_1.Parameter.Path(schema_1.Schema.String()); | ||
const parameter = __1.Parameter.Path(__1.Schema.String()); | ||
(0, chai_1.expect)(parameter.type).to.be.eq("path"); | ||
@@ -24,5 +23,5 @@ (0, chai_1.expect)(parameter.schema.type).to.be.eq("string"); | ||
it("should return RequestBody object", () => { | ||
const parameter = Parameter_1.Parameter.Body(schema_1.Schema.Object({ | ||
a: schema_1.Schema.Number(), | ||
b: schema_1.Schema.Boolean(), | ||
const parameter = __1.Parameter.Body(__1.Schema.Object({ | ||
a: __1.Schema.Number(), | ||
b: __1.Schema.Boolean(), | ||
})); | ||
@@ -29,0 +28,0 @@ (0, chai_1.expect)(parameter.type).to.be.eq("body"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const schema_1 = require("../schema"); | ||
const __1 = require(".."); | ||
describe("Schema", () => { | ||
describe("Schema.Number", () => { | ||
it("should return NumberSchema object", () => { | ||
const schema = schema_1.Schema.Number(); | ||
const schema = __1.Schema.Number(); | ||
(0, chai_1.expect)(schema.type).to.be.eq("number"); | ||
@@ -14,3 +14,3 @@ }); | ||
it("should return StringSchema object", () => { | ||
const schema = schema_1.Schema.String(); | ||
const schema = __1.Schema.String(); | ||
(0, chai_1.expect)(schema.type).to.be.eq("string"); | ||
@@ -21,3 +21,3 @@ }); | ||
it("should return BooleanSchema object", () => { | ||
const schema = schema_1.Schema.Boolean(); | ||
const schema = __1.Schema.Boolean(); | ||
(0, chai_1.expect)(schema.type).to.be.eq("boolean"); | ||
@@ -28,3 +28,3 @@ }); | ||
it("should return EnumSchema object", () => { | ||
const schema = schema_1.Schema.Enum([1, 2, "a", "b"]); | ||
const schema = __1.Schema.Enum([1, 2, "a", "b"]); | ||
(0, chai_1.expect)(schema.type).to.be.eq("enum"); | ||
@@ -43,3 +43,3 @@ (0, chai_1.expect)(schema.keys).to.be.deep.eq([ | ||
it("should return ArraySchema<NumberSchema> object", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.Number()); | ||
const schema = __1.Schema.Array(__1.Schema.Number()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("array"); | ||
@@ -52,3 +52,3 @@ (0, chai_1.expect)(schema.itemSchema.type).to.be.eq("number"); | ||
it("should return ArraySchema<StringSchema> object", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.String()); | ||
const schema = __1.Schema.Array(__1.Schema.String()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("array"); | ||
@@ -61,3 +61,3 @@ (0, chai_1.expect)(schema.itemSchema.type).to.be.eq("string"); | ||
it("should return ArraySchema<BooleanSchema> object", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.Boolean()); | ||
const schema = __1.Schema.Array(__1.Schema.Boolean()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("array"); | ||
@@ -70,3 +70,3 @@ (0, chai_1.expect)(schema.itemSchema.type).to.be.eq("boolean"); | ||
it("should return ArraySchema<ObjectSchema> object", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.Object({})); | ||
const schema = __1.Schema.Array(__1.Schema.Object({})); | ||
(0, chai_1.expect)(schema.type).to.be.eq("array"); | ||
@@ -79,3 +79,3 @@ (0, chai_1.expect)(schema.itemSchema.type).to.be.eq("object"); | ||
it("should return ArraySchema<UnionSchema> object", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.Union([schema_1.Schema.Number(), schema_1.Schema.String()])); | ||
const schema = __1.Schema.Array(__1.Schema.Union([__1.Schema.Number(), __1.Schema.String()])); | ||
(0, chai_1.expect)(schema.type).to.be.eq("array"); | ||
@@ -89,14 +89,14 @@ (0, chai_1.expect)(schema.itemSchema.type).to.be.eq("union"); | ||
it("should return ObjectSchema object", () => { | ||
const schema = schema_1.Schema.Object({ | ||
number: schema_1.Schema.Number(), | ||
string: schema_1.Schema.String(), | ||
boolean: schema_1.Schema.Boolean(), | ||
array: schema_1.Schema.Array(schema_1.Schema.Number()), | ||
object: schema_1.Schema.Object({}), | ||
union: schema_1.Schema.Union([ | ||
schema_1.Schema.Number(), | ||
schema_1.Schema.String(), | ||
schema_1.Schema.Union([schema_1.Schema.Number(), schema_1.Schema.String(), schema_1.Schema.Boolean()]), | ||
const schema = __1.Schema.Object({ | ||
number: __1.Schema.Number(), | ||
string: __1.Schema.String(), | ||
boolean: __1.Schema.Boolean(), | ||
array: __1.Schema.Array(__1.Schema.Number()), | ||
object: __1.Schema.Object({}), | ||
union: __1.Schema.Union([ | ||
__1.Schema.Number(), | ||
__1.Schema.String(), | ||
__1.Schema.Union([__1.Schema.Number(), __1.Schema.String(), __1.Schema.Boolean()]), | ||
]), | ||
optional: schema_1.Schema.Optional(schema_1.Schema.Number()), | ||
optional: __1.Schema.Optional(__1.Schema.Number()), | ||
}); | ||
@@ -124,3 +124,3 @@ (0, chai_1.expect)(schema.type).to.be.eq("object"); | ||
it("should return DictSchema object", () => { | ||
const schema = schema_1.Schema.Dict(schema_1.Schema.String()); | ||
const schema = __1.Schema.Dict(__1.Schema.String()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("dict"); | ||
@@ -133,3 +133,3 @@ (0, chai_1.expect)(schema.valueSchema.type).to.be.eq("string"); | ||
it("should set Schema.optional option to true", () => { | ||
const schema = schema_1.Schema.Optional(schema_1.Schema.Number()); | ||
const schema = __1.Schema.Optional(__1.Schema.Number()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("number"); | ||
@@ -141,3 +141,3 @@ (0, chai_1.expect)(schema.options.optional).to.be.true; | ||
it("should set Schema.nullable option to true", () => { | ||
const schema = schema_1.Schema.Nullable(schema_1.Schema.Number()); | ||
const schema = __1.Schema.Nullable(__1.Schema.Number()); | ||
(0, chai_1.expect)(schema.type).to.be.eq("number"); | ||
@@ -149,10 +149,10 @@ (0, chai_1.expect)(schema.options.nullable).to.be.true; | ||
it("should return UnionSchema object", () => { | ||
const schema = schema_1.Schema.Union([ | ||
schema_1.Schema.Number(), | ||
schema_1.Schema.String(), | ||
schema_1.Schema.Union([schema_1.Schema.Number(), schema_1.Schema.String(), schema_1.Schema.Boolean()]), | ||
schema_1.Schema.Object({ a: schema_1.Schema.String() }), | ||
schema_1.Schema.Object({ a: schema_1.Schema.Number() }), | ||
schema_1.Schema.Object({ a: schema_1.Schema.Number() }), | ||
schema_1.Schema.Object({ a: schema_1.Schema.Boolean() }), | ||
const schema = __1.Schema.Union([ | ||
__1.Schema.Number(), | ||
__1.Schema.String(), | ||
__1.Schema.Union([__1.Schema.Number(), __1.Schema.String(), __1.Schema.Boolean()]), | ||
__1.Schema.Object({ a: __1.Schema.String() }), | ||
__1.Schema.Object({ a: __1.Schema.Number() }), | ||
__1.Schema.Object({ a: __1.Schema.Number() }), | ||
__1.Schema.Object({ a: __1.Schema.Boolean() }), | ||
]); | ||
@@ -159,0 +159,0 @@ (0, chai_1.expect)(schema.type).to.be.eq("union"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const validator_1 = require("../validator"); | ||
const schema_1 = require("../schema"); | ||
const __1 = require(".."); | ||
describe("Validator", () => { | ||
describe("Validator.validate", () => { | ||
context("when NumberSchema is passed", () => { | ||
const schema = schema_1.Schema.Number(); | ||
const schema = __1.Schema.Number(); | ||
it("should return success result if value is evaluated as number", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, 1234).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, 1234).success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as number", () => { | ||
const result = validator_1.Validator.validate(schema, "1234"); | ||
const result = __1.Validator.validate(schema, "1234"); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -20,8 +19,8 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be number"); | ||
context("when StringSchema is passed", () => { | ||
const schema = schema_1.Schema.String(); | ||
const schema = __1.Schema.String(); | ||
it("should return success result if value is evaluated as string", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, "1234").success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, "1234").success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as string", () => { | ||
const result = validator_1.Validator.validate(schema, 1234); | ||
const result = __1.Validator.validate(schema, 1234); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -32,9 +31,9 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be string"); | ||
context("when BooleanSchema is passed", () => { | ||
const schema = schema_1.Schema.Boolean(); | ||
const schema = __1.Schema.Boolean(); | ||
it("should return success result if value is evaluated as boolean", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, true).success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, false).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, true).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, false).success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as boolean", () => { | ||
const result = validator_1.Validator.validate(schema, 1); | ||
const result = __1.Validator.validate(schema, 1); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -45,10 +44,10 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be boolean"); | ||
context("when EnumSchema is passed", () => { | ||
const schema = schema_1.Schema.Enum(["a", "b", "c"]); | ||
const schema = __1.Schema.Enum(["a", "b", "c"]); | ||
it("should return success result if value is evaluated as enum", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, "a").success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, "b").success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, "c").success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, "a").success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, "b").success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, "c").success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as enum", () => { | ||
const result = validator_1.Validator.validate(schema, "d"); | ||
const result = __1.Validator.validate(schema, "d"); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -59,8 +58,8 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq(`should be one of "a" | "b" | "c"`); | ||
context("when ArraySchema is passed", () => { | ||
const schema = schema_1.Schema.Array(schema_1.Schema.Number()); | ||
const schema = __1.Schema.Array(__1.Schema.Number()); | ||
it("should return success result if value is evaluated as array", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, [1, 2, 3, 4]).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, [1, 2, 3, 4]).success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as array", () => { | ||
const result = validator_1.Validator.validate(schema, ["1", "2", "3", 4, 5]); | ||
const result = __1.Validator.validate(schema, ["1", "2", "3", 4, 5]); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -71,9 +70,9 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be Array<number>"); | ||
context("when UnionSchema is passed", () => { | ||
const schema = schema_1.Schema.Union([schema_1.Schema.Number(), schema_1.Schema.String()]); | ||
const schema = __1.Schema.Union([__1.Schema.Number(), __1.Schema.String()]); | ||
it("should return success result if value is evaluated as union", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, 1234).success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, "1234").success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, 1234).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, "1234").success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as union", () => { | ||
const result = validator_1.Validator.validate(schema, true); | ||
const result = __1.Validator.validate(schema, true); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -84,14 +83,14 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be number | string"); | ||
context("when ObjectSchema is passed", () => { | ||
const schema = schema_1.Schema.Object({ number: schema_1.Schema.Number(), optional: schema_1.Schema.Optional(schema_1.Schema.String()) }); | ||
const schema = __1.Schema.Object({ number: __1.Schema.Number(), optional: __1.Schema.Optional(__1.Schema.String()) }); | ||
it("should return success result if value is evaluated as union", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, { number: 1234 }).success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, { number: 1234, optional: "1234" }).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, { number: 1234 }).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, { number: 1234, optional: "1234" }).success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as union", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, {}).success).to.be.false; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, []).success).to.be.false; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, null).success).to.be.false; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, { number: "1234" }).success).to.be.false; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, { number: 1234, optional: 1234 }).success).to.be.false; | ||
const result = validator_1.Validator.validate(schema, { optional: true }); | ||
(0, chai_1.expect)(__1.Validator.validate(schema, {}).success).to.be.false; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, []).success).to.be.false; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, null).success).to.be.false; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, { number: "1234" }).success).to.be.false; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, { number: 1234, optional: 1234 }).success).to.be.false; | ||
const result = __1.Validator.validate(schema, { optional: true }); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -102,9 +101,9 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("property [number]: should be provided, property [optional]: should be string"); | ||
context("when DictSchema is passed", () => { | ||
const schema = schema_1.Schema.Dict(schema_1.Schema.String()); | ||
const schema = __1.Schema.Dict(__1.Schema.String()); | ||
it("should return success result if value is evaluated as dict", () => { | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, { a: "1234", b: "1234" }).success).to.be.true; | ||
(0, chai_1.expect)(validator_1.Validator.validate(schema, {}).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, { a: "1234", b: "1234" }).success).to.be.true; | ||
(0, chai_1.expect)(__1.Validator.validate(schema, {}).success).to.be.true; | ||
}); | ||
it("should return failed result if value isn't evaluated as dict", () => { | ||
const result = validator_1.Validator.validate(schema, { a: 1234, b: "1234" }); | ||
const result = __1.Validator.validate(schema, { a: 1234, b: "1234" }); | ||
(0, chai_1.expect)(result.success).to.be.false; | ||
@@ -111,0 +110,0 @@ (0, chai_1.expect)(result.success === false && result.error.description).to.be.eq("should be { [key: string]: string }"); |
import { OpenAPIV3 } from "openapi-types"; | ||
import { HTTPRequest, Method, Parameters, ResponseBody } from "./http"; | ||
import { HTTPRequest, Method, Parameters, ResponseBody } from "."; | ||
export declare class OASBuilder { | ||
@@ -4,0 +4,0 @@ private readonly info; |
@@ -1,2 +0,2 @@ | ||
import { AllSchema } from "./schema"; | ||
import { AllSchema } from "."; | ||
declare type QueryParameter<T extends AllSchema> = { | ||
@@ -3,0 +3,0 @@ type: "query"; |
@@ -1,2 +0,2 @@ | ||
import { AllSchema } from "./schema"; | ||
import { AllSchema } from "."; | ||
export declare class ValidationError { | ||
@@ -3,0 +3,0 @@ readonly description: string; |
{ | ||
"name": "request-typer", | ||
"version": "1.3.6", | ||
"version": "1.3.7", | ||
"description": "Make typed request schema and build OpenAPI Specification", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -94,5 +94,5 @@ # request-typer | ||
// response json schema | ||
{ | ||
user: Schema.Object({ id: Schema.String() }), | ||
} | ||
Schema.Object({ | ||
id: Schema.String(), | ||
}), | ||
); | ||
@@ -111,5 +111,5 @@ ``` | ||
}, | ||
{ | ||
Schema.Object({ | ||
success: Schema.Boolean(), | ||
} | ||
}), | ||
); | ||
@@ -135,3 +135,3 @@ | ||
const Responses = { | ||
User: { | ||
User: Schema.Object({ | ||
id: Schema.String(), | ||
@@ -141,3 +141,3 @@ name: Schema.String(), | ||
email: Schema.Optional(Schema.String()), | ||
}, | ||
}), | ||
}; | ||
@@ -153,3 +153,3 @@ | ||
}, | ||
Responses.User | ||
Responses.User, | ||
), | ||
@@ -156,0 +156,0 @@ ]; |
55728
1055