Skip to content

Commit

Permalink
Merge fix-jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Lenzotti committed Jul 22, 2020
2 parents fab4320 + 0d64310 commit 7f0bcb6
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 115 deletions.
83 changes: 42 additions & 41 deletions packages/core/src/class/ProxyMap.ts
Expand Up @@ -7,6 +7,7 @@ export interface ProxyMapSettings {

/**
* @private
* @deprecated
*/
export abstract class ProxyMap<T, I> implements Map<T, I> {
readonly [Symbol.toStringTag]: "Map" = "Map";
Expand All @@ -18,6 +19,47 @@ export abstract class ProxyMap<T, I> implements Map<T, I> {
}
}

/**
* Return the size of the map.
* @returns {number}
*/
get size() {
return this.registry.size;
}

/**
*
* @param value
* @param query
* @returns {boolean}
*/
private static query(value: any, query: any): boolean {
/* istanbul ignore next */
if (!query) {
return true;
}

if (value === query) {
return true;
}

/* istanbul ignore else */
if (typeof value === "object") {
return !!Object.keys(query).find(key => {
/* istanbul ignore else */
if (value[key] && query[key]) {
return this.query(value[key], query[key]);
}

/* istanbul ignore next */
return false;
});
}

/* istanbul ignore next */
return false;
}

/**
*
* @returns {IterableIterator<[T , I]>}
Expand Down Expand Up @@ -145,45 +187,4 @@ export abstract class ProxyMap<T, I> implements Map<T, I> {

return map;
}

/**
* Return the size of the map.
* @returns {number}
*/
get size() {
return this.registry.size;
}

/**
*
* @param value
* @param query
* @returns {boolean}
*/
private static query(value: any, query: any): boolean {
/* istanbul ignore next */
if (!query) {
return true;
}

if (value === query) {
return true;
}

/* istanbul ignore else */
if (typeof value === "object") {
return !!Object.keys(query).find(key => {
/* istanbul ignore else */
if (value[key] && query[key]) {
return this.query(value[key], query[key]);
}

/* istanbul ignore next */
return false;
});
}

/* istanbul ignore next */
return false;
}
}
1 change: 1 addition & 0 deletions packages/core/src/class/ProxyRegistry.ts
Expand Up @@ -2,6 +2,7 @@ import {ProxyMap} from "./ProxyMap";
import {Registry, RegistryKey} from "./Registry";
/**
* @private
* @deprecated
*/
export abstract class ProxyRegistry<T, I> extends ProxyMap<RegistryKey, T> {
constructor(protected registry: Registry<T, I>) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/class/Storable.ts
Expand Up @@ -4,6 +4,9 @@ import {Entity} from "./Entity";
import {Metadata} from "./Metadata";
import {Store} from "./Store";

/**
* @deprecated Will be removed in v6
*/
export abstract class Storable extends Entity {
/**
* Required entity.
Expand Down
10 changes: 4 additions & 6 deletions packages/schema/src/decorators/common/example.spec.ts
Expand Up @@ -13,11 +13,11 @@ describe("@Example", () => {

// THEN
expect(getJsonSchema(Model)).to.deep.equal({
examples: {
default: {
examples: [
{
id: "id"
}
},
],
type: "object"
});
});
Expand All @@ -28,9 +28,7 @@ describe("@Example", () => {

// THEN
expect(getJsonSchema(Model)).to.deep.equal({
examples: {
name: "description"
},
examples: ["description"],
type: "object"
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/decorators/common/example.ts
@@ -1,4 +1,4 @@
import {DecoratorParameters, DecoratorTypes, getDecoratorType, UnsupportedDecoratorType} from "@tsed/core";
import {DecoratorParameters, DecoratorTypes, getDecoratorType, isObject, UnsupportedDecoratorType} from "@tsed/core";
import {JsonEntityStore} from "../../domain/JsonEntityStore";
import {JsonEntityFn} from "./jsonEntityFn";

Expand Down
74 changes: 62 additions & 12 deletions packages/schema/src/decorators/operations/returns.spec.ts
Expand Up @@ -8,7 +8,46 @@ describe("@Returns", () => {
class Controller {
@OperationPath("POST", "/")
@(Returns(200, String).Description("description"))
method() {}
method() {
}
}

// THEN
const spec = getSpec(Controller, {spec: SpecTypes.SWAGGER});

expect(spec).to.deep.equal({
definitions: {},
tags: [
{
name: "Controller"
}
],
paths: {
"/": {
post: {
operationId: "controllerMethod",
parameters: [],
responses: {
"200": {
description: "description",
schema: {
type: "string"
}
}
},
tags: ["Controller"]
}
}
}
});
});
it("should declare a return type (Status().Type())", async () => {
// WHEN
class Controller {
@OperationPath("POST", "/")
@Returns().Status(200).Type(String).Description("description")
method() {
}
}

// THEN
Expand Down Expand Up @@ -54,7 +93,8 @@ describe("@Returns", () => {
.Schema({
minLength: 3
}))
method() {}
method() {
}
}

// THEN
Expand Down Expand Up @@ -106,7 +146,8 @@ describe("@Returns", () => {
.Description("description")
.ContentType("text/json")
.Examples("Examples"))
method() {}
method() {
}
}

// THEN
Expand Down Expand Up @@ -149,10 +190,11 @@ describe("@Returns", () => {
// WHEN
class Controller {
@OperationPath("POST", "/")
@(Returns(400).Description("Bad request"))
@Returns(400).Description("Bad request")
@Returns(401)
@(Returns(200).Description("Success"))
method() {}
@Returns(200).Description("Success")
method() {
}
}

// THEN
Expand All @@ -170,11 +212,14 @@ describe("@Returns", () => {
post: {
operationId: "controllerMethod",
parameters: [],
"produces": [
"text/json"
],
responses: {
"200": {
description: "Success",
schema: {
type: "string"
type: "object"
}
},
"401": {
Expand Down Expand Up @@ -205,7 +250,8 @@ describe("@Returns", () => {
@(Returns(200, String)
.Of(Array)
.Description("description"))
method() {}
method() {
}
}
} catch (er) {
actualError = er;
Expand All @@ -222,7 +268,8 @@ describe("@Returns", () => {
@(Returns(200, Array)
.Nested(Set)
.Description("description"))
method() {}
method() {
}
}
} catch (er) {
actualError = er;
Expand All @@ -231,7 +278,8 @@ describe("@Returns", () => {
actualError.message.should.eq("Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean");
});
it("should throw an error when the decorator isn't correctly used", async () => {
class Test {}
class Test {
}

// WHEN
let actualError: any;
Expand All @@ -251,7 +299,8 @@ describe("@Returns", () => {
@(Returns(200, Array)
.Of(String)
.Description("description"))
method() {}
method() {
}
}

// THEN
Expand Down Expand Up @@ -299,7 +348,8 @@ describe("@Returns", () => {
@(Returns(200, Array)
.Of(Model)
.Description("description"))
method() {}
method() {
}
}

// THEN
Expand Down

0 comments on commit 7f0bcb6

Please sign in to comment.