@@ -124,9 +124,9 @@ interface ClassMeta {
124124}
125125
126126const createRoutes = ( ) : Route [ ] => {
127- const paths = Object . keys ( openapi . paths )
127+ const allOpenapiPaths = Object . keys ( openapi . paths )
128128
129- const unmatchedEndpointPaths = paths
129+ const unmatchedEndpointPaths = allOpenapiPaths
130130 . filter (
131131 ( path ) =>
132132 ! routePaths . some ( ( routePath ) => isEndpointUnderRoute ( path , routePath ) ) ,
@@ -141,19 +141,63 @@ const createRoutes = (): Route[] => {
141141 )
142142 }
143143
144- return routePaths . map ( createRoute )
144+ const documentedRoutePaths = routePaths . filter (
145+ hasAtLeastOneDocumentedEndpoint ,
146+ )
147+
148+ return documentedRoutePaths . map ( ( routePath ) =>
149+ createRoute ( routePath , documentedRoutePaths ) ,
150+ )
145151}
146152
147- const createRoute = ( routePath : ( typeof routePaths ) [ number ] ) : Route => {
148- const endpointPaths = Object . keys ( openapi . paths ) . filter ( ( path ) =>
153+ const hasAtLeastOneDocumentedEndpoint = (
154+ routePath : ( typeof routePaths ) [ number ] ,
155+ ) : boolean => {
156+ const endpointsUnderRoute = Object . keys ( openapi . paths ) . filter ( ( path ) =>
149157 isEndpointUnderRoute ( path , routePath ) ,
150158 )
151159
160+ if ( endpointsUnderRoute . length === 0 ) {
161+ return false
162+ }
163+
164+ return endpointsUnderRoute . some ( ( path ) => {
165+ if ( ! isOpenapiPath ( path ) ) return false
166+
167+ const pathSchema = openapi . paths [ path ]
168+ if ( ! ( 'post' in pathSchema ) ) return false
169+
170+ return ! ( 'x-undocumented' in pathSchema . post )
171+ } )
172+ }
173+
174+ const createRoute = (
175+ routePath : ( typeof routePaths ) [ number ] ,
176+ documentedRoutePaths : ReadonlyArray < ( typeof routePaths ) [ number ] > ,
177+ ) : Route => {
178+ const endpointPaths = Object . entries ( openapi . paths )
179+ . filter ( ( [ path , pathSchema ] ) => {
180+ if ( ! isEndpointUnderRoute ( path , routePath ) ) {
181+ return false
182+ }
183+
184+ return 'post' in pathSchema && ! ( 'x-undocumented' in pathSchema . post )
185+ } )
186+ . map ( ( [ path ] ) => path )
187+
152188 const namespace = routePath . split ( '/' ) . join ( '_' ) . slice ( 1 )
153189
190+ const subresources = ( routePathSubresources [ routePath ] ?? [ ] ) . filter (
191+ ( subresource ) => {
192+ const subresourcePath = `${ routePath } /${ subresource } `
193+
194+ return documentedRoutePaths . some ( ( path ) => path === subresourcePath )
195+ } ,
196+ )
197+
154198 return {
155199 namespace,
156- subresources : routePathSubresources [ routePath ] ?? [ ] ,
200+ subresources,
157201 endpoints : endpointPaths . map ( ( endpointPath ) =>
158202 createEndpoint ( namespace , routePath , endpointPath ) ,
159203 ) ,
@@ -386,9 +430,7 @@ const renderClassMethodOptions = ({
386430 resource,
387431} : Pick < Endpoint , 'resource' > ) : string => {
388432 if ( resource === 'action_attempt' ) {
389- return `options: ${ renderClassMethodOptionsTypeDef ( {
390- resource,
391- } ) } = {},`
433+ return `options: ${ renderClassMethodOptionsTypeDef ( { resource } ) } = {},`
392434 }
393435 return ''
394436}
0 commit comments