Skip to content

Commit d518b44

Browse files
committed
update
Signed-off-by: Kirill Mokevnin <[email protected]>
1 parent d35b51c commit d518b44

File tree

15 files changed

+389
-107
lines changed

15 files changed

+389
-107
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ types-to-openapi:
2323
npx tsp compile .
2424

2525
types-to-typebox:
26-
npx openapi-box ./tsp-output/@typespec/openapi3/openapi.json
26+
npx openapi-box ./tsp-output/@typespec/openapi3/openapi.v1.json
2727

2828
types: types-to-openapi types-to-typebox
2929

lib/data.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function buildUser(params = {}) {
3333
*/
3434
export function buildCourse(params = {}) {
3535
const user = {
36+
creatorId: null,
3637
name: faker.lorem.sentence(),
3738
description: faker.lorem.paragraph(),
3839
}
@@ -45,6 +46,7 @@ export function buildCourse(params = {}) {
4546
*/
4647
export function buildCourseLesson(params = {}) {
4748
const lesson = {
49+
courseId: null,
4850
name: faker.lorem.sentence(),
4951
body: faker.lorem.paragraph(),
5052
}

main.tsp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import "@typespec/http";
22
import "@typespec/rest";
3+
import "@typespec/versioning";
34
import "@typespec/openapi3";
45
import "@typespec/json-schema";
56

7+
using TypeSpec.Versioning;
68
using TypeSpec.Http;
9+
using TypeSpec.Rest;
710
using TypeSpec.JsonSchema;
811

912
@service({
1013
title: "Fastify Rest Api Example",
1114
})
1215
@server("https://code-basics.com", "Single server endpoint")
1316
@jsonSchema
17+
@versioned(Versions)
1418
namespace FastifyRestApiExample;
1519

20+
enum Versions {
21+
v1,
22+
}
23+
1624
/**
1725
* https://www.rfc-editor.org/rfc/rfc9457.html
1826
*/
@@ -32,6 +40,18 @@ model NotFoundError {
3240
...ProblemDetails;
3341
}
3442

43+
@error
44+
model UnauthorizedError {
45+
@statusCode _: 401;
46+
...ProblemDetails;
47+
}
48+
49+
@error
50+
model ForbiddenError {
51+
@statusCode _: 403;
52+
...ProblemDetails;
53+
}
54+
3555
@error
3656
model UnprocessableEntityError {
3757
@statusCode _: 422;
@@ -94,6 +114,7 @@ model CourseLessonCreateDTO {
94114
}
95115

96116
@route("/users")
117+
@useAuth(BearerAuth)
97118
namespace users {
98119
@get
99120
op index(@query page?: numeric = 1): {
@@ -139,20 +160,23 @@ namespace courses {
139160
} | NotFoundError;
140161

141162
@post
163+
@useAuth(BearerAuth)
142164
op create(@body course: CourseCreateDTO): {
143165
@body course: Course;
144166
@statusCode statusCode: 201;
145167
} | UnprocessableEntityError;
146168

147169
@patch
170+
@useAuth(BearerAuth)
148171
op update(@path id: numeric, @body course: CourseEditDTO): {
149172
@body course: Course;
150-
} | NotFoundError | UnprocessableEntityError;
173+
} | NotFoundError | UnprocessableEntityError | UnauthorizedError;
151174

152175
@delete
176+
@useAuth(BearerAuth)
153177
op destroy(@path id: numeric): {
154178
@statusCode statusCode: 204;
155-
} | NotFoundError;
179+
} | NotFoundError | UnauthorizedError;
156180
}
157181

158182
@route("/courses/{courseId}/lessons")
@@ -170,8 +194,9 @@ namespace courses_lessons {
170194
} | NotFoundError;
171195

172196
@post
197+
@useAuth(BearerAuth)
173198
op create(@path courseId: numeric, @body course: CourseLessonCreateDTO): {
174199
@body lesson: CourseLesson;
175200
@statusCode statusCode: 201;
176-
} | UnprocessableEntityError;
201+
} | UnprocessableEntityError | UnauthorizedError;
177202
}

package-lock.json

Lines changed: 78 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)