@@ -306,14 +306,15 @@ export const createBlueprint = async (
306306 formatCode,
307307 }
308308
309- const resources = createResources ( openapi . components . schemas )
309+ const routes = await createRoutes ( openapi . paths , context )
310+ const resources = createResources ( openapi . components . schemas , routes )
310311
311312 return {
312313 title : openapi . info . title ,
313- routes : await createRoutes ( openapi . paths , context ) ,
314+ routes,
314315 resources,
315- events : createEvents ( openapi . components . schemas , resources ) ,
316- actionAttempts : createActionAttempts ( openapi . components . schemas ) ,
316+ events : createEvents ( openapi . components . schemas , resources , routes ) ,
317+ actionAttempts : createActionAttempts ( openapi . components . schemas , routes ) ,
317318 }
318319}
319320
@@ -788,6 +789,7 @@ const createParameter = (
788789
789790export const createResources = (
790791 schemas : Openapi [ 'components' ] [ 'schemas' ] ,
792+ routes : Route [ ] ,
791793) : Record < string , Resource > => {
792794 return Object . entries ( schemas ) . reduce < Record < string , Resource > > (
793795 ( resources , [ schemaName , schema ] ) => {
@@ -804,7 +806,7 @@ export const createResources = (
804806 }
805807 return {
806808 ...resources ,
807- [ schemaName ] : createResource ( schemaName , eventSchema ) ,
809+ [ schemaName ] : createResource ( schemaName , eventSchema , routes ) ,
808810 }
809811 }
810812
@@ -813,7 +815,7 @@ export const createResources = (
813815 if ( isValidResourceSchema ) {
814816 return {
815817 ...resources ,
816- [ schemaName ] : createResource ( schemaName , schema ) ,
818+ [ schemaName ] : createResource ( schemaName , schema , routes ) ,
817819 }
818820 }
819821
@@ -826,11 +828,9 @@ export const createResources = (
826828const createResource = (
827829 schemaName : string ,
828830 schema : OpenapiSchema ,
831+ routes : Route [ ] ,
829832) : Resource => {
830- const routePath = schema [ 'x-route-path' ]
831- if ( routePath == null || routePath . length === 0 ) {
832- throw new Error ( `Missing route path for ${ schemaName } ` )
833- }
833+ const routePath = validateRoutePath ( schema [ 'x-route-path' ] , routes )
834834
835835 return {
836836 resourceType : schemaName ,
@@ -846,6 +846,20 @@ const createResource = (
846846 }
847847}
848848
849+ const validateRoutePath = (
850+ routePath : string | undefined ,
851+ routes : Route [ ] ,
852+ ) : string => {
853+ if ( routePath == null || routePath . length === 0 ) {
854+ throw new Error ( 'Missing route path' )
855+ }
856+ if ( ! routes . some ( ( r ) => r . path === routePath ) ) {
857+ throw new Error ( `Route path ${ routePath } not found in routes` )
858+ }
859+
860+ return routePath
861+ }
862+
849863const createResponse = (
850864 operation : OpenapiOperation ,
851865 path : string ,
@@ -1095,6 +1109,7 @@ export const getPreferredMethod = (
10951109const createEvents = (
10961110 schemas : Openapi [ 'components' ] [ 'schemas' ] ,
10971111 resources : Record < string , Resource > ,
1112+ routes : Route [ ] ,
10981113) : EventResource [ ] => {
10991114 const eventSchema = schemas [ 'event' ]
11001115 if (
@@ -1121,7 +1136,7 @@ const createEvents = (
11211136 )
11221137
11231138 return {
1124- ...createResource ( 'event' , schema as OpenapiSchema ) ,
1139+ ...createResource ( 'event' , schema as OpenapiSchema , routes ) ,
11251140 eventType,
11261141 targetResourceType : targetResourceType ?? null ,
11271142 }
@@ -1131,6 +1146,7 @@ const createEvents = (
11311146
11321147const createActionAttempts = (
11331148 schemas : Openapi [ 'components' ] [ 'schemas' ] ,
1149+ routes : Route [ ] ,
11341150) : ActionAttempt [ ] => {
11351151 const actionAttemptSchema = schemas [ 'action_attempt' ]
11361152 if (
@@ -1176,6 +1192,7 @@ const createActionAttempts = (
11761192 const resource = createResource (
11771193 'action_attempt' ,
11781194 schemaWithStandardStatus ,
1195+ routes ,
11791196 )
11801197
11811198 return {
0 commit comments