raiton 5.4.0-beta.2 → 5.5.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Raiton détecte automatiquement l'environnement d'exécution et adapte son serve
|
|
|
94
94
|
|
|
95
95
|
Example
|
|
96
96
|
```typescript
|
|
97
|
-
import { Controllable, Get, ApiOkResponse, ApiResponse } from '
|
|
97
|
+
import { Controllable, Get, ApiOkResponse, ApiResponse } from 'raiton/framework';
|
|
98
98
|
|
|
99
99
|
@Controllable('/users')
|
|
100
100
|
export class UserController {
|
|
@@ -125,6 +125,23 @@ Example
|
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
+
```typescript
|
|
129
|
+
import { Controllable, Get, ApiQuery } from "raiton/framework";
|
|
130
|
+
|
|
131
|
+
@Controllable("/users")
|
|
132
|
+
export class UserController {
|
|
133
|
+
@Get()
|
|
134
|
+
@ApiQuery("name", { description: "Filter by name", required: false, type:
|
|
135
|
+
String })
|
|
136
|
+
@ApiQuery("limit", { description: "Max results", required: false, type:
|
|
137
|
+
Number })
|
|
138
|
+
async getUsers(ctx) {
|
|
139
|
+
const { name, limit } = ctx.query;
|
|
140
|
+
// …
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
128
145
|
## Licence
|
|
129
146
|
|
|
130
147
|
Ce projet est sous licence MIT. Voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
package/build/bin/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ export interface ApiResponseOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* HTTP status code
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
status: number;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Description of the response
|
|
@@ -49,7 +49,7 @@ export function ApiResponse(options: ApiResponseOptions) {
|
|
|
49
49
|
*/
|
|
50
50
|
export function ApiOkResponse(description?: string, type?: any, isArray?: boolean) {
|
|
51
51
|
return ApiResponse({
|
|
52
|
-
|
|
52
|
+
status: 200,
|
|
53
53
|
description,
|
|
54
54
|
type,
|
|
55
55
|
isArray
|
|
@@ -64,7 +64,7 @@ export function ApiOkResponse(description?: string, type?: any, isArray?: boolea
|
|
|
64
64
|
*/
|
|
65
65
|
export function ApiCreatedResponse(description?: string, type?: any, isArray?: boolean) {
|
|
66
66
|
return ApiResponse({
|
|
67
|
-
|
|
67
|
+
status: 201,
|
|
68
68
|
description,
|
|
69
69
|
type,
|
|
70
70
|
isArray
|
|
@@ -77,7 +77,7 @@ export function ApiCreatedResponse(description?: string, type?: any, isArray?: b
|
|
|
77
77
|
*/
|
|
78
78
|
export function ApiBadRequestResponse(description?: string) {
|
|
79
79
|
return ApiResponse({
|
|
80
|
-
|
|
80
|
+
status: 400,
|
|
81
81
|
description
|
|
82
82
|
});
|
|
83
83
|
}
|
|
@@ -88,7 +88,7 @@ export function ApiBadRequestResponse(description?: string) {
|
|
|
88
88
|
*/
|
|
89
89
|
export function ApiUnauthorizedResponse(description?: string) {
|
|
90
90
|
return ApiResponse({
|
|
91
|
-
|
|
91
|
+
status: 401,
|
|
92
92
|
description
|
|
93
93
|
});
|
|
94
94
|
}
|
|
@@ -99,7 +99,7 @@ export function ApiUnauthorizedResponse(description?: string) {
|
|
|
99
99
|
*/
|
|
100
100
|
export function ApiForbiddenResponse(description?: string) {
|
|
101
101
|
return ApiResponse({
|
|
102
|
-
|
|
102
|
+
status: 403,
|
|
103
103
|
description
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -110,7 +110,7 @@ export function ApiForbiddenResponse(description?: string) {
|
|
|
110
110
|
*/
|
|
111
111
|
export function ApiNotFoundResponse(description?: string) {
|
|
112
112
|
return ApiResponse({
|
|
113
|
-
|
|
113
|
+
status: 404,
|
|
114
114
|
description
|
|
115
115
|
});
|
|
116
116
|
}
|
|
@@ -121,7 +121,7 @@ export function ApiNotFoundResponse(description?: string) {
|
|
|
121
121
|
*/
|
|
122
122
|
export function ApiInternalServerErrorResponse(description?: string) {
|
|
123
123
|
return ApiResponse({
|
|
124
|
-
|
|
124
|
+
status: 500,
|
|
125
125
|
description
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -182,4 +182,38 @@ export function ApiParam(name: string, options: {
|
|
|
182
182
|
params[propertyKey].push({name, ...options});
|
|
183
183
|
Reflect.defineMetadata(METADATA_KEYS.API_PARAMETERS, params, target, propertyKey);
|
|
184
184
|
};
|
|
185
|
-
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Decorator to add query parameter metadata (shortcut for ApiParam with in: 'query')
|
|
188
|
+
* @param name Parameter name
|
|
189
|
+
* @param options Parameter options (description, required, type, default, deprecated)
|
|
190
|
+
*/
|
|
191
|
+
export function ApiQuery(name: string, options: {
|
|
192
|
+
/**
|
|
193
|
+
* Parameter description
|
|
194
|
+
*/
|
|
195
|
+
description?: string;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Whether the parameter is required
|
|
199
|
+
*/
|
|
200
|
+
required?: boolean;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Parameter type (for schema generation)
|
|
204
|
+
*/
|
|
205
|
+
type?: any;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Default value (optional)
|
|
209
|
+
*/
|
|
210
|
+
default?: any;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Whether this parameter should be excluded from documentation (deprecated)
|
|
214
|
+
* @deprecated
|
|
215
|
+
*/
|
|
216
|
+
deprecated?: boolean;
|
|
217
|
+
}) {
|
|
218
|
+
return ApiParam(name, {...options, in: 'query'});
|
|
219
|
+
}
|