@@ -120,35 +120,46 @@ async function formatRestData(operations: Operation[]): Promise<OperationsByCate
120120
121121// Every time we update the REST data files, we'll want to make sure the
122122// config.json file is updated with the latest api versions.
123+ // This function rebuilds each version's date array from the schemas that were
124+ // actually synced, so deprecated calendar-date versions are automatically
125+ // removed. Only version keys that appear in the incoming schemas are touched —
126+ // keys absent from this sync run (e.g. during a partial --versions run) are
127+ // left unchanged. We never remove an entire version key (e.g. "ghes-3.14");
128+ // that is handled separately by the GHES deprecation process.
123129async function updateRestConfigData ( schemas : string [ ] ) : Promise < void > {
124130 const restConfigFilename = 'src/rest/lib/config.json'
125131 const restConfigData = JSON . parse ( await readFile ( restConfigFilename , 'utf8' ) ) as Record <
126132 string ,
127133 any
128134 >
129135 const restApiVersionData = restConfigData [ 'api-versions' ] || { }
130- // If the version isn't one of the OpenAPI version,
131- // then it's an api-versioned schema
136+
137+ // Phase 1: Collect the dates present in the incoming schemas, keyed by
138+ // OpenAPI version name. Only calendar-date schemas contribute — those that
139+ // don't exactly match a base OPENAPI_VERSION_NAMES entry but do start with one.
140+ const incomingDates : Record < string , Set < string > > = { }
141+
132142 for ( const schema of schemas ) {
133143 const schemaBaseName = path . basename ( schema , '.json' )
134144 if ( ! OPENAPI_VERSION_NAMES . includes ( schemaBaseName ) ) {
135- const openApiVer = OPENAPI_VERSION_NAMES . find ( ( ver ) => schemaBaseName . startsWith ( ver ) )
145+ const openApiVer = OPENAPI_VERSION_NAMES . find ( ( ver ) => schemaBaseName . startsWith ( ` ${ ver } -` ) )
136146 if ( ! openApiVer ) {
137147 throw new Error ( `Could not find the OpenAPI version for schema ${ schemaBaseName } ` )
138148 }
139- const date = schemaBaseName . split ( `${ openApiVer } -` ) [ 1 ]
140-
141- if ( ! restApiVersionData [ openApiVer ] ) {
142- restApiVersionData [ openApiVer ] = [ ]
143- }
144- if ( ! restApiVersionData [ openApiVer ] . includes ( date ) ) {
145- const dates = restApiVersionData [ openApiVer ]
146- dates . push ( date )
147- restApiVersionData [ openApiVer ] = dates
148- }
149+ const date = schemaBaseName . slice ( openApiVer . length + 1 )
150+ if ( ! incomingDates [ openApiVer ] ) incomingDates [ openApiVer ] = new Set ( )
151+ incomingDates [ openApiVer ] . add ( date )
149152 }
150- restConfigData [ 'api-versions' ] = restApiVersionData
151153 }
154+
155+ // Phase 2: For each version key that appeared in this sync run, replace its
156+ // date array with exactly what was synced. This removes any deprecated dates
157+ // that are no longer present in the upstream schemas.
158+ for ( const [ openApiVer , dates ] of Object . entries ( incomingDates ) ) {
159+ restApiVersionData [ openApiVer ] = [ ...dates ] . sort ( )
160+ }
161+
162+ restConfigData [ 'api-versions' ] = restApiVersionData
152163 await writeFile ( restConfigFilename , JSON . stringify ( restConfigData , null , 2 ) )
153164}
154165
0 commit comments