Skip to content

Commit 9ab9080

Browse files
committed
chore: use versions instead of renamed api_versions on public resources
1 parent 2d00f2f commit 9ab9080

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

gen/schema.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,14 @@ type PublicResource = {
159159
filters?: Record<string, unknown>
160160
parent_resource?: string
161161
/**
162-
* API versions the resource lives in. Synonymous with `meta.api_versions`
163-
* (same array, always identical). The parser reads `meta.api_versions`
164-
* 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.
165165
*/
166166
versions?: string[]
167-
/** Legacy schema only — replaced by `meta.api_versions` in the unified shape. */
167+
/** Legacy schema only — superseded by `versions` in the unified shape. */
168168
deprecated?: boolean
169169
}
170-
/** Unified schema only — absent in the legacy payload. */
171-
meta?: {
172-
api_versions?: string[]
173-
}
174170
}
175171

176172
type PublicResourcesDoc = {
@@ -667,12 +663,12 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
667663
const raw = readFileSync(path, { encoding: 'utf-8' })
668664
const doc = JSON.parse(raw) as PublicResourcesDoc
669665

670-
// Shape detection. Unified payloads carry `meta.api_versions` on every
671-
// resource; legacy payloads (e.g. production today) don't have a per-resource
672-
// `meta` block at all. Lenient rule: any resource with the field flips us
673-
// into unified mode. In a hypothetical mixed payload, resources without
674-
// the field are treated as version-agnostic (always included).
675-
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)
676672
console.log(`Schema shape: ${isUnified ? 'unified' : 'legacy'}`)
677673
if (doc.meta?.version) console.log(`Schema release: ${doc.meta.version}`)
678674

@@ -683,11 +679,11 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
683679
)
684680
}
685681

686-
// Union of every resource's api_versions, sorted; first/last entries
682+
// Union of every resource's `versions`, sorted; first/last entries
687683
// are the oldest/newest API versions the catalogue knows about. Empty
688684
// when the payload is legacy.
689685
const supportedVersions: readonly string[] = isUnified
690-
? 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()
691687
: []
692688

693689
let targetVersion: string
@@ -716,7 +712,7 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
716712
// marker so callers keep getting type imports.
717713
const resourceClassifications = new Map<string, Classification>()
718714
for (const res of doc.data) {
719-
const versioned = classifyVersions(res.meta?.api_versions, targetVersion)
715+
const versioned = classifyVersions(res.attributes.versions, targetVersion)
720716
if (versioned === 'deprecated' || versioned === 'exclude') {
721717
resourceClassifications.set(res.id, versioned)
722718
} else if (res.attributes.deprecated === true) {
@@ -765,7 +761,7 @@ const parseSchema = (path: string, opts: GeneratorOptions = {}): ApiSchema => {
765761
if (operations.update)
766762
resComponents[`${cam}Update`] = buildComponent(ctx, 'update', targetVersion, oldestSupported, excludedClassNames)
767763

768-
const apiVersions = res.meta?.api_versions
764+
const apiVersions = res.attributes.versions
769765
// If this resource is an STI parent (other resources declare it as
770766
// `parent_resource`), collect the children whose own modules will be
771767
// generated. Drop:

0 commit comments

Comments
 (0)