File tree 6 files changed +64
-69
lines changed
6 files changed +64
-69
lines changed Original file line number Diff line number Diff line change
1
+ import { z , type RouteHandler } from '@hono/zod-openapi' ;
2
+ import type { Context } from 'hono' ;
3
+ import { newsTankaSchema } from '../../schema/News/newsTankaSchema.js' ;
4
+ import type { newsTankaRoute } from '../../routes/News/newsTankaRoute.js' ;
5
+ import postNews from '../../lib/postNews.js' ;
6
+
7
+ type newsTankaSchema = z . infer < typeof newsTankaSchema > ;
8
+
9
+ const newsTankaHandler : RouteHandler < typeof newsTankaRoute , { } > = async ( c : Context ) => {
10
+ const { apiKey } = await c . req . json < newsTankaSchema > ( ) ;
11
+
12
+ /* --- 色々処理 --- */
13
+
14
+ const response = await postNews ( apiKey ) ;
15
+ console . log ( response ) ;
16
+
17
+ // レスポンス
18
+ return c . json ( response , 200 ) ;
19
+ } ;
20
+
21
+ export default newsTankaHandler ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { z } from '@hono/zod-openapi' ;
2
+ import { createRoute } from '@hono/zod-openapi' ;
3
+ import { newsTankaResponseSchema , newsTankaSchema } from '../../schema/News/newsTankaSchema.js' ;
4
+ import { errorResponseSchema } from '../../middleware/errorHandler.js' ;
5
+
6
+ type newsTankaSchema = z . infer < typeof newsTankaSchema > ;
7
+
8
+ export const newsTankaRoute = createRoute ( {
9
+ method : 'post' ,
10
+ path : '/news' ,
11
+ tags : [ 'news' ] ,
12
+ request : {
13
+ body : {
14
+ required : true ,
15
+ content : {
16
+ 'application/json' : {
17
+ schema : newsTankaSchema ,
18
+ } ,
19
+ } ,
20
+ } ,
21
+ } ,
22
+ responses : {
23
+ 200 : {
24
+ content : {
25
+ 'application/json' : {
26
+ schema : newsTankaResponseSchema ,
27
+ } ,
28
+ } ,
29
+ description : 'Successful response' ,
30
+ } ,
31
+ } ,
32
+ } ) ;
33
+
34
+ export type NewsTankaRouteResponse200 = z . infer <
35
+ ( typeof newsTankaRoute . responses ) [ '200' ] [ 'content' ] [ 'application/json' ] [ 'schema' ]
36
+ > ;
37
+
38
+ export type NewsTankaRouteResponseError = z . infer < typeof errorResponseSchema > ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -29,8 +29,8 @@ import { sampleS3DownloadRoute } from './sampleS3Route.js';
29
29
import sampleS3DownloadHandler from '../controllers/sampleS3DownloadHandler.js' ;
30
30
import { sampleGeminiRoute } from './Sample/sampleGeminiRoute.js' ;
31
31
import sampleGeminiHandler from '../controllers/Sample/sampleGeminiHandler.js' ;
32
- import { sampleNewsTankaRoute } from './Sample/sampleNewsTankaRoute .js' ;
33
- import sampleNewsTankaHandler from '../controllers/Sample/sampleNewsTankaHandler .js' ;
32
+ import { newsTankaRoute } from './News/newsTankaRoute .js' ;
33
+ import newsTankaHandler from '../controllers/News/newsTankaHandler .js' ;
34
34
35
35
const router = new OpenAPIHono ( ) ;
36
36
@@ -50,5 +50,5 @@ export default router
50
50
. openapi ( sampleS3UploadRoute , sampleS3UploadHandler )
51
51
. openapi ( sampleS3DownloadRoute , sampleS3DownloadHandler )
52
52
. openapi ( sampleGeminiRoute , sampleGeminiHandler )
53
- . openapi ( sampleNewsTankaRoute , sampleNewsTankaHandler ) ;
53
+ . openapi ( newsTankaRoute , newsTankaHandler ) ;
54
54
// .openapi(helloRoute, helloWorldHandler); //こういう感じで足していく
Original file line number Diff line number Diff line change 1
1
import { z } from '@hono/zod-openapi' ;
2
2
3
- export const sampleNewsTankaSchema = z . object ( {
3
+ export const newsTankaSchema = z . object ( {
4
4
apiKey : z . string ( ) . openapi ( {
5
5
example : 'abc123' ,
6
6
description : 'APIキー' ,
7
7
} ) ,
8
8
} ) ;
9
9
10
- export const sampleNewsTankaResponseSchema = z . object ( {
10
+ export const newsTankaResponseSchema = z . object ( {
11
11
isSuccess : z . boolean ( ) . openapi ( {
12
12
example : true ,
13
13
description : '短歌の生成に成功したかどうか' ,
You can’t perform that action at this time.
0 commit comments