@@ -5,6 +5,8 @@ import Inflector from './inflector'
55
66type ApiSchema = {
77 version : string
8+ /** Every API version the catalogue knows about (sorted, oldest→newest). Empty for legacy payloads. */
9+ supportedVersions : readonly string [ ]
810 resources : Record < string , Resource >
911 components : ComponentMap
1012}
@@ -157,18 +159,14 @@ type PublicResource = {
157159 filters ?: Record < string , unknown >
158160 parent_resource ?: string
159161 /**
160- * API versions the resource lives in. Synonymous with `meta.api_versions`
161- * (same array, always identical). The parser reads `meta.api_versions`
162- * canonically. Unified schema only .
162+ * API versions the resource lives in. The parser reads this as the
163+ * canonical source of a resource's version info. Unified schema only —
164+ * absent in the legacy payload .
163165 */
164166 versions ?: string [ ]
165- /** Legacy schema only — replaced by `meta.api_versions ` in the unified shape. */
167+ /** Legacy schema only — superseded by `versions ` in the unified shape. */
166168 deprecated ?: boolean
167169 }
168- /** Unified schema only — absent in the legacy payload. */
169- meta ?: {
170- api_versions ?: string [ ]
171- }
172170}
173171
174172type PublicResourcesDoc = {
@@ -665,12 +663,12 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
665663 const raw = readFileSync ( path , { encoding : 'utf-8' } )
666664 const doc = JSON . parse ( raw ) as PublicResourcesDoc
667665
668- // Shape detection. Unified payloads carry `meta.api_versions ` on every
669- // resource; legacy payloads (e.g. production today) don't have a per-resource
670- // `meta` block at all. Lenient rule: any resource with the field flips us
671- // into unified mode. In a hypothetical mixed payload, resources without
672- // the field are treated as version-agnostic (always included).
673- const isUnified = doc . data . some ( ( r ) => r . meta ?. api_versions != null )
666+ // Shape detection. Unified payloads carry `attributes.versions ` on every
667+ // resource; legacy payloads (e.g. production today) omit it entirely.
668+ // Lenient rule: any resource with the field flips us into unified mode. In
669+ // a hypothetical mixed payload, resources without the field are treated as
670+ // version-agnostic (always included).
671+ const isUnified = doc . data . some ( ( r ) => r . attributes . versions != null )
674672 console . log ( `Schema shape: ${ isUnified ? 'unified' : 'legacy' } ` )
675673 if ( doc . meta ?. version ) console . log ( `Schema release: ${ doc . meta . version } ` )
676674
@@ -681,11 +679,11 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
681679 )
682680 }
683681
684- // Union of every resource's api_versions , sorted; first/last entries
682+ // Union of every resource's `versions` , sorted; first/last entries
685683 // are the oldest/newest API versions the catalogue knows about. Empty
686684 // when the payload is legacy.
687685 const supportedVersions : readonly string [ ] = isUnified
688- ? Array . from ( new Set ( doc . data . flatMap ( ( r ) => r . meta ?. api_versions ?? [ ] ) ) ) . sort ( )
686+ ? Array . from ( new Set ( doc . data . flatMap ( ( r ) => r . attributes . versions ?? [ ] ) ) ) . sort ( )
689687 : [ ]
690688
691689 let targetVersion : string
@@ -714,7 +712,7 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
714712 // marker so callers keep getting type imports.
715713 const resourceClassifications = new Map < string , Classification > ( )
716714 for ( const res of doc . data ) {
717- const versioned = classifyVersions ( res . meta ?. api_versions , targetVersion )
715+ const versioned = classifyVersions ( res . attributes . versions , targetVersion )
718716 if ( versioned === 'deprecated' || versioned === 'exclude' ) {
719717 resourceClassifications . set ( res . id , versioned )
720718 } else if ( res . attributes . deprecated === true ) {
@@ -763,7 +761,7 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
763761 if ( operations . update )
764762 resComponents [ `${ cam } Update` ] = buildComponent ( ctx , 'update' , targetVersion , oldestSupported , excludedClassNames )
765763
766- const apiVersions = res . meta ?. api_versions
764+ const apiVersions = res . attributes . versions
767765 // If this resource is an STI parent (other resources declare it as
768766 // `parent_resource`), collect the children whose own modules will be
769767 // generated. Drop:
@@ -800,7 +798,7 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
800798
801799 console . log ( 'Public resources schema correctly parsed.' )
802800
803- return { version : targetVersion , resources, components }
801+ return { version : targetVersion , supportedVersions , resources, components }
804802}
805803
806804export default {
0 commit comments