File tree Expand file tree Collapse file tree 2 files changed +64
-6
lines changed
Expand file tree Collapse file tree 2 files changed +64
-6
lines changed Original file line number Diff line number Diff line change @@ -228,4 +228,64 @@ describe("zod v3", () => {
228228
229229 expect ( specs ) . toMatchSnapshot ( ) ;
230230 } ) ;
231+
232+ it ( "operation id for path with underscore" , async ( ) => {
233+ const app = new Hono ( ) . get (
234+ "/api_v1/users" ,
235+ describeRoute ( {
236+ tags : [ "test" ] ,
237+ summary : "Test route" ,
238+ description : "This is a test route" ,
239+ } ) ,
240+ async ( c ) => {
241+ return c . json ( { message : "Hello" } ) ;
242+ } ,
243+ ) ;
244+
245+ const specs = await generateSpecs ( app ) ;
246+
247+ expect ( specs . paths ?. [ "/api_v1/users" ] ?. get ?. operationId ) . toBe (
248+ "getApiV1Users" ,
249+ ) ;
250+ } ) ;
251+
252+ it ( "operation id for path param with dash" , async ( ) => {
253+ const app = new Hono ( ) . get (
254+ "/users/:user-id" ,
255+ describeRoute ( {
256+ tags : [ "test" ] ,
257+ summary : "Test route" ,
258+ description : "This is a test route" ,
259+ } ) ,
260+ async ( c ) => {
261+ return c . json ( { message : "Hello" } ) ;
262+ } ,
263+ ) ;
264+
265+ const specs = await generateSpecs ( app ) ;
266+
267+ expect ( specs . paths ?. [ "/users/{user-id}" ] ?. get ?. operationId ) . toBe (
268+ "getUsersByUserId" ,
269+ ) ;
270+ } ) ;
271+
272+ it ( "operation id for multiple dashed segments" , async ( ) => {
273+ const app = new Hono ( ) . get (
274+ "/api-v1/user-profile" ,
275+ describeRoute ( {
276+ tags : [ "test" ] ,
277+ summary : "Test route" ,
278+ description : "This is a test route" ,
279+ } ) ,
280+ async ( c ) => {
281+ return c . json ( { message : "Hello" } ) ;
282+ } ,
283+ ) ;
284+
285+ const specs = await generateSpecs ( app ) ;
286+
287+ expect ( specs . paths ?. [ "/api-v1/user-profile" ] ?. get ?. operationId ) . toBe (
288+ "getApiV1UserProfile" ,
289+ ) ;
290+ } ) ;
231291} ) ;
Original file line number Diff line number Diff line change @@ -49,12 +49,10 @@ const toOpenAPIPath = (path: string) =>
4949
5050const toPascalCase = ( text : string ) =>
5151 text
52- // capitalize the first letter of each word
53- . replaceAll ( / ( \w ) ( \w * ) / g, ( _ , firstChar : string , rest : string ) => {
54- return `${ firstChar . toUpperCase ( ) } ${ rest } ` ;
55- } )
56- // replace all non-word characters except the first character
57- . replaceAll ( / (?< ! ^ ) \W / g, "" ) ;
52+ . split ( / [ \W _ ] + / )
53+ . filter ( Boolean )
54+ . map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
55+ . join ( "" ) ;
5856
5957const generateOperationId = ( route : RouterRoute ) => {
6058 let operationId = route . method . toLowerCase ( ) ;
You can’t perform that action at this time.
0 commit comments