@@ -5,18 +5,18 @@ import walk from 'walk-sync'
55import { isPlainObject , difference } from 'lodash-es'
66
77import { isApiVersioned , allVersions } from '@/versions/lib/all-versions'
8- import getRest , { getRestCategories } from '../lib/index'
8+ import getRest , { getRestCategories , type RestOperationCategory } from '../lib/index'
99import readFrontmatter from '@/frame/lib/read-frontmatter'
1010import frontmatter from '@/frame/lib/frontmatter'
1111import getApplicableVersions from '../../versions/lib/get-applicable-versions'
1212import { getAutomatedMarkdownFiles } from '../scripts/test-open-api-schema'
1313import { nonAutomatedRestPaths } from '../lib/config'
14+ import type { Operation } from '@/rest/components/types'
1415
1516const schemasPath = 'src/rest/data'
1617
17- // Operations have dynamic structure from OpenAPI schema - using any to avoid complex type definitions
18- async function getFlatListOfOperations ( version : string ) : Promise < any [ ] > {
19- const flatList = [ ]
18+ async function getFlatListOfOperations ( version : string ) : Promise < Operation [ ] > {
19+ const flatList : Operation [ ] = [ ]
2020
2121 if ( isApiVersioned ( version ) ) {
2222 for ( const apiVersion of allVersions [ version ] . apiVersions ) {
@@ -38,16 +38,17 @@ async function getFlatListOfOperations(version: string): Promise<any[]> {
3838describe ( 'markdown for each rest version' , ( ) => {
3939 // Unique set of all categories across all versions of the OpenAPI schema
4040 const allCategories = new Set < string > ( )
41- // Entire schema including categories and subcategories - using any due to dynamic OpenAPI structure
42- const openApiSchema : Record < string , any > = { }
41+ // Entire schema including categories and subcategories, keyed by version then category
42+ const openApiSchema : Record < string , Record < string , RestOperationCategory > > = { }
4343 // All applicable version of categories based on frontmatter in the categories index.md file
44- const categoryApplicableVersions : Record < string , any > = { }
44+ const categoryApplicableVersions : Record < string , string [ ] > = { }
4545
4646 function getApplicableVersionFromFile ( file : string ) {
4747 const currentFile = fs . readFileSync ( file , 'utf8' )
48- // Frontmatter data structure is dynamic based on file content
49- const { data } = frontmatter ( currentFile ) as { data : any }
50- return getApplicableVersions ( data . versions , file )
48+ const fm = frontmatter ( currentFile ) as unknown as {
49+ data ?: { versions ?: string | Record < string , string | string [ ] > }
50+ }
51+ return getApplicableVersions ( fm . data ?. versions , file )
5152 }
5253
5354 function getCategorySubcategory ( file : string ) {
@@ -127,12 +128,15 @@ describe('markdown for each rest version', () => {
127128describe ( 'rest file structure' , ( ) => {
128129 test ( 'children of content/rest/index.md are in alphabetical order' , async ( ) => {
129130 const indexContent = fs . readFileSync ( 'content/rest/index.md' , 'utf8' )
130- // Frontmatter data structure is dynamic based on file content
131- const { data } = readFrontmatter ( indexContent ) as { data : any }
131+ const fm = readFrontmatter ( indexContent ) as unknown as {
132+ data ?: { children ?: string [ ] }
133+ }
134+ const children = fm . data ?. children
135+ expect ( Array . isArray ( children ) ) . toBe ( true )
132136 const nonAutomatedChildren = nonAutomatedRestPaths . map ( ( child : string ) =>
133137 child . replace ( '/rest' , '' ) ,
134138 )
135- const sortableChildren = data . children . filter (
139+ const sortableChildren = ( children as string [ ] ) . filter (
136140 ( child : string ) => ! nonAutomatedChildren . includes ( child ) ,
137141 )
138142 expect ( sortableChildren ) . toStrictEqual ( [ ...sortableChildren ] . sort ( ) )
@@ -203,11 +207,12 @@ describe('code examples are defined', () => {
203207 }
204208
205209 const operation = await findOperation ( version , 'GET' , '/repos/{owner}/{repo}' )
210+ expect ( operation ) . toBeDefined ( )
211+ if ( ! operation ) continue
206212 expect ( operation . serverUrl ) . toBe ( domain )
207213 expect ( isPlainObject ( operation ) ) . toBe ( true )
208214 expect ( operation . codeExamples ) . toBeDefined ( )
209- // Code examples have dynamic structure from OpenAPI schema
210- for ( const example of operation . codeExamples as any [ ] ) {
215+ for ( const example of operation . codeExamples ) {
211216 expect ( isPlainObject ( example . request ) ) . toBe ( true )
212217 expect ( isPlainObject ( example . response ) ) . toBe ( true )
213218 }
0 commit comments