Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema): support Examples on QueryParams model
Closes: #2633
- Loading branch information
Showing
2 changed files
with
154 additions
and
1 deletion.
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
124 changes: 124 additions & 0 deletions
124
packages/specs/schema/test/integrations/query-model-examples.spec.ts
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,124 @@ | ||
import { | ||
Default, | ||
Examples, | ||
GenericOf, | ||
Generics, | ||
getSpec, | ||
In, | ||
Maximum, | ||
Minimum, | ||
OperationPath, | ||
Path, | ||
Property, | ||
SpecTypes | ||
} from "../../src/index"; | ||
import {QueryParams} from "@tsed/platform-params"; | ||
|
||
class QueryParamModel { | ||
@Property() | ||
path: string; | ||
|
||
@Property() | ||
condition: string; | ||
|
||
@Property() | ||
value: string; | ||
} | ||
|
||
@Path("/query") | ||
class QueryModelCtrl { | ||
@OperationPath("GET", "/") | ||
async get( | ||
@QueryParams() | ||
@Examples({ | ||
example1: { | ||
description: "description1", | ||
value: { | ||
path: "path1", | ||
condition: "condition1" | ||
} | ||
}, | ||
example2: { | ||
description: "description1", | ||
value: { | ||
path: "path2", | ||
condition: "condition2" | ||
} | ||
} | ||
}) | ||
q: QueryParamModel | ||
) {} | ||
} | ||
|
||
describe("Query Model example", () => { | ||
it("should generate the spec for deep object", () => { | ||
const spec = getSpec(QueryModelCtrl, {specType: SpecTypes.OPENAPI}); | ||
|
||
expect(spec).toEqual({ | ||
paths: { | ||
"/query": { | ||
get: { | ||
operationId: "queryModelCtrlGet", | ||
parameters: [ | ||
{ | ||
in: "query", | ||
name: "path", | ||
required: false, | ||
examples: { | ||
example1: { | ||
description: "description1", | ||
value: "path1" | ||
}, | ||
example2: { | ||
description: "description1", | ||
value: "path2" | ||
} | ||
}, | ||
schema: { | ||
type: "string" | ||
} | ||
}, | ||
{ | ||
examples: { | ||
example1: { | ||
description: "description1", | ||
value: "condition1" | ||
}, | ||
example2: { | ||
description: "description1", | ||
value: "condition2" | ||
} | ||
}, | ||
in: "query", | ||
name: "condition", | ||
required: false, | ||
schema: { | ||
type: "string" | ||
} | ||
}, | ||
{ | ||
in: "query", | ||
name: "value", | ||
required: false, | ||
schema: { | ||
type: "string" | ||
} | ||
} | ||
], | ||
responses: { | ||
"200": { | ||
description: "Success" | ||
} | ||
}, | ||
tags: ["QueryModelCtrl"] | ||
} | ||
} | ||
}, | ||
tags: [ | ||
{ | ||
name: "QueryModelCtrl" | ||
} | ||
] | ||
}); | ||
}); | ||
}); |