@@ -95,4 +95,180 @@ describe("openapi", () => {
9595 expect ( schemaItems [ 0 ] . id ) . toBe ( "without-tags" ) ;
9696 } ) ;
9797 } ) ;
98+
99+ describe ( "path template and custom verb handling" , ( ) => {
100+ it ( "binds postman requests for OpenAPI templates and path verbs" , async ( ) => {
101+ const openapiData = {
102+ openapi : "3.0.0" ,
103+ info : {
104+ title : "Path Template API" ,
105+ version : "1.0.0" ,
106+ } ,
107+ paths : {
108+ "/api/resource:customVerb" : {
109+ post : {
110+ summary : "Custom verb endpoint" ,
111+ operationId : "customVerbOperation" ,
112+ responses : {
113+ "200" : {
114+ description : "OK" ,
115+ } ,
116+ } ,
117+ } ,
118+ } ,
119+ "/api/users/{id}" : {
120+ get : {
121+ summary : "Get user by ID" ,
122+ operationId : "getUserById" ,
123+ parameters : [
124+ {
125+ name : "id" ,
126+ in : "path" ,
127+ required : true ,
128+ schema : {
129+ type : "string" ,
130+ } ,
131+ } ,
132+ ] ,
133+ responses : {
134+ "200" : {
135+ description : "OK" ,
136+ } ,
137+ } ,
138+ } ,
139+ } ,
140+ "/api/users/{userId}/posts/{postId}" : {
141+ get : {
142+ summary : "Get user post" ,
143+ operationId : "getUserPost" ,
144+ parameters : [
145+ {
146+ name : "userId" ,
147+ in : "path" ,
148+ required : true ,
149+ schema : {
150+ type : "string" ,
151+ } ,
152+ } ,
153+ {
154+ name : "postId" ,
155+ in : "path" ,
156+ required : true ,
157+ schema : {
158+ type : "string" ,
159+ } ,
160+ } ,
161+ ] ,
162+ responses : {
163+ "200" : {
164+ description : "OK" ,
165+ } ,
166+ } ,
167+ } ,
168+ } ,
169+ "/files/{name}.{ext}" : {
170+ get : {
171+ summary : "Get file by name and extension" ,
172+ operationId : "getFileByNameAndExt" ,
173+ parameters : [
174+ {
175+ name : "name" ,
176+ in : "path" ,
177+ required : true ,
178+ schema : {
179+ type : "string" ,
180+ } ,
181+ } ,
182+ {
183+ name : "ext" ,
184+ in : "path" ,
185+ required : true ,
186+ schema : {
187+ type : "string" ,
188+ } ,
189+ } ,
190+ ] ,
191+ responses : {
192+ "200" : {
193+ description : "OK" ,
194+ } ,
195+ } ,
196+ } ,
197+ } ,
198+ "/jobs/{id}:cancel" : {
199+ post : {
200+ summary : "Cancel job" ,
201+ operationId : "cancelJob" ,
202+ parameters : [
203+ {
204+ name : "id" ,
205+ in : "path" ,
206+ required : true ,
207+ schema : {
208+ type : "string" ,
209+ } ,
210+ } ,
211+ ] ,
212+ responses : {
213+ "200" : {
214+ description : "OK" ,
215+ } ,
216+ } ,
217+ } ,
218+ } ,
219+ } ,
220+ } ;
221+
222+ const options : APIOptions = {
223+ specPath : "dummy" ,
224+ outputDir : "build" ,
225+ } ;
226+ const sidebarOptions = { } as SidebarOptions ;
227+ const [ items ] = await processOpenapiFile (
228+ openapiData as any ,
229+ options ,
230+ sidebarOptions
231+ ) ;
232+
233+ const apiItems = items . filter ( ( item ) => item . type === "api" ) ;
234+ expect ( apiItems ) . toHaveLength ( 5 ) ;
235+
236+ const customVerbItem = apiItems . find (
237+ ( item ) => item . type === "api" && item . id === "custom-verb-operation"
238+ ) as any ;
239+ expect ( customVerbItem . api . path ) . toBe ( "/api/resource:customVerb" ) ;
240+ expect ( customVerbItem . api . method ) . toBe ( "post" ) ;
241+ expect ( customVerbItem . api . postman ) . toBeDefined ( ) ;
242+
243+ const standardItem = apiItems . find (
244+ ( item ) => item . type === "api" && item . id === "get-user-by-id"
245+ ) as any ;
246+ expect ( standardItem . api . path ) . toBe ( "/api/users/{id}" ) ;
247+ expect ( standardItem . api . method ) . toBe ( "get" ) ;
248+ expect ( standardItem . api . postman ) . toBeDefined ( ) ;
249+
250+ const multiParamItem = apiItems . find (
251+ ( item ) => item . type === "api" && item . id === "get-user-post"
252+ ) as any ;
253+ expect ( multiParamItem . api . path ) . toBe (
254+ "/api/users/{userId}/posts/{postId}"
255+ ) ;
256+ expect ( multiParamItem . api . method ) . toBe ( "get" ) ;
257+ expect ( multiParamItem . api . postman ) . toBeDefined ( ) ;
258+
259+ const sameSegmentItem = apiItems . find (
260+ ( item ) => item . type === "api" && item . id === "get-file-by-name-and-ext"
261+ ) as any ;
262+ expect ( sameSegmentItem . api . path ) . toBe ( "/files/{name}.{ext}" ) ;
263+ expect ( sameSegmentItem . api . method ) . toBe ( "get" ) ;
264+ expect ( sameSegmentItem . api . postman ) . toBeDefined ( ) ;
265+
266+ const templatedVerbItem = apiItems . find (
267+ ( item ) => item . type === "api" && item . id === "cancel-job"
268+ ) as any ;
269+ expect ( templatedVerbItem . api . path ) . toBe ( "/jobs/{id}:cancel" ) ;
270+ expect ( templatedVerbItem . api . method ) . toBe ( "post" ) ;
271+ expect ( templatedVerbItem . api . postman ) . toBeDefined ( ) ;
272+ } ) ;
273+ } ) ;
98274} ) ;
0 commit comments