@@ -9,14 +9,24 @@ export interface Post {
99 published : boolean ;
1010 tags : string [ ] ;
1111}
12+
13+ const PostSchema = z . object ( {
14+ id : z . string ( ) ,
15+ title : z . string ( ) ,
16+ description : z . string ( ) . nullable ( ) ,
17+ content : z . string ( ) . nullable ( ) ,
18+ published : z . boolean ( ) . nullable ( ) ,
19+ tags : z . array ( z . string ( ) ) ,
20+ } ) ;
21+
1222const c = initContract ( ) ;
1323
1424export const apiBlog = c . router ( {
1525 createPost : {
1626 method : 'POST' ,
1727 path : '/posts' ,
1828 responses : {
19- 201 : c . response < Post > ( ) ,
29+ 201 : PostSchema ,
2030 } ,
2131 body : z . object ( {
2232 title : z . string ( ) ,
@@ -29,7 +39,7 @@ export const apiBlog = c.router({
2939 updatePost : {
3040 method : 'PATCH' ,
3141 path : `/posts/:id` ,
32- responses : { 200 : c . response < Post > ( ) } ,
42+ responses : { 200 : PostSchema } ,
3343 body : z . object ( {
3444 title : z . string ( ) . optional ( ) ,
3545 content : z . string ( ) . optional ( ) ,
@@ -42,8 +52,8 @@ export const apiBlog = c.router({
4252 method : 'DELETE' ,
4353 path : `/posts/:id` ,
4454 responses : {
45- 200 : c . response < { message : string } > ( ) ,
46- 404 : c . response < { message : string } > ( ) ,
55+ 200 : z . object ( { message : z . string ( ) } ) ,
56+ 404 : z . object ( { message : z . string ( ) } ) ,
4757 } ,
4858 body : null ,
4959 summary : 'Delete a post' ,
@@ -52,8 +62,8 @@ export const apiBlog = c.router({
5262 method : 'GET' ,
5363 path : `/posts/:id` ,
5464 responses : {
55- 200 : c . response < Post > ( ) ,
56- 404 : c . response < null > ( ) ,
65+ 200 : PostSchema ,
66+ 404 : z . null ( ) ,
5767 } ,
5868 query : null ,
5969 summary : 'Get a post by id' ,
@@ -62,7 +72,7 @@ export const apiBlog = c.router({
6272 method : 'GET' ,
6373 path : '/posts' ,
6474 responses : {
65- 200 : c . response < { posts : Post [ ] ; total : number } > ( ) ,
75+ 200 : z . object ( { posts : PostSchema . array ( ) , total : z . number ( ) } ) ,
6676 } ,
6777 query : z . object ( {
6878 take : z . string ( ) . transform ( Number ) . optional ( ) ,
0 commit comments