-
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsonschema): Add AllowTypes and Any decorators for jsonSchema
- Add AllowTypes and Any, - Fix Converter decorators. Now, Converter throw an error when it used without type, - AJV use JSONSchema6 instead of JSONSchema4. - Add tag documentation on decorators
- Loading branch information
Showing
29 changed files
with
172 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {JSONSchema6TypeName} from "json-schema"; | ||
import {PropertyMetadata} from "../class/PropertyMetadata"; | ||
import {PropertyRegistry} from "../registries/PropertyRegistry"; | ||
|
||
/** | ||
* Set the type of the array items. | ||
* | ||
* ```typescript | ||
* class Model { | ||
* @AllowTypes("string", "integer", "boolean", "array") | ||
* property: string[]; | ||
* } | ||
* ``` | ||
* | ||
* @returns {Function} | ||
* @decorator | ||
* @param types | ||
*/ | ||
export function AllowTypes(...types: JSONSchema6TypeName[]) { | ||
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { | ||
propertyMetadata.schema.type = types; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {JSONSchema6TypeName} from "json-schema"; | ||
import {PropertyMetadata} from "../class/PropertyMetadata"; | ||
import {PropertyRegistry} from "../registries/PropertyRegistry"; | ||
|
||
/** | ||
* Set the type of the array items. | ||
* | ||
* ```typescript | ||
* class Model { | ||
* @Any() | ||
* // eq. @AllowTypes("any") | ||
* property: any; | ||
* } | ||
* ``` | ||
* | ||
* @returns {Function} | ||
* @decorator | ||
* @param types | ||
*/ | ||
export function Any(...types: JSONSchema6TypeName[]) { | ||
return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { | ||
propertyMetadata.schema.type = "any"; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {AllowTypes} from "../../../../src/jsonschema/decorators/allowTypes"; | ||
import {PropertyRegistry} from "../../../../src/jsonschema/registries/PropertyRegistry"; | ||
import {Sinon} from "../../../tools"; | ||
|
||
describe("AllowTypes", () => { | ||
before(() => { | ||
this.decorateStub = Sinon.stub(PropertyRegistry, "decorate"); | ||
this.propertyMetadata = { | ||
schema: {} | ||
}; | ||
AllowTypes("string", "number"); | ||
this.decorateStub.getCall(0).args[0](this.propertyMetadata); | ||
}); | ||
after(() => { | ||
this.decorateStub.restore(); | ||
}); | ||
|
||
it("should store data", () => { | ||
this.propertyMetadata.schema.type.should.deep.eq(["string", "number"]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Any} from "../../../../src/jsonschema/decorators/any"; | ||
import {PropertyRegistry} from "../../../../src/jsonschema/registries/PropertyRegistry"; | ||
import {Sinon} from "../../../tools"; | ||
|
||
describe("AllowTypes", () => { | ||
before(() => { | ||
this.decorateStub = Sinon.stub(PropertyRegistry, "decorate"); | ||
this.propertyMetadata = { | ||
schema: {} | ||
}; | ||
Any(); | ||
this.decorateStub.getCall(0).args[0](this.propertyMetadata); | ||
}); | ||
after(() => { | ||
this.decorateStub.restore(); | ||
}); | ||
|
||
it("should store data", () => { | ||
this.propertyMetadata.schema.type.should.deep.eq("any"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.