@intentius/chant-lexicon-k8s 0.100.0 → 0.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/dist/actions/apps.d.ts +4 -4
  2. package/dist/actions/apps.d.ts.map +1 -1
  3. package/dist/actions/core.d.ts +5 -5
  4. package/dist/actions/core.d.ts.map +1 -1
  5. package/dist/actions/networking.d.ts.map +1 -1
  6. package/dist/codegen/generate-typescript.d.ts +2 -2
  7. package/dist/codegen/generate-typescript.d.ts.map +1 -1
  8. package/dist/codegen/generate.d.ts.map +1 -1
  9. package/dist/codegen/naming.d.ts.map +1 -1
  10. package/dist/codegen/versions.d.ts.map +1 -1
  11. package/dist/components/capability-plugin.d.ts.map +1 -1
  12. package/dist/composites/catalog.d.ts.map +1 -1
  13. package/dist/composites/cockroachdb-cluster.d.ts +2 -2
  14. package/dist/composites/gke-otel-collector.d.ts.map +1 -1
  15. package/dist/composites/index.d.ts +1 -0
  16. package/dist/composites/index.d.ts.map +1 -1
  17. package/dist/composites/otel-collector-agent.d.ts +24 -2
  18. package/dist/composites/otel-collector-agent.d.ts.map +1 -1
  19. package/dist/composites/otel-collector-gateway.d.ts +37 -52
  20. package/dist/composites/otel-collector-gateway.d.ts.map +1 -1
  21. package/dist/composites/otel-collector-node.d.ts +88 -0
  22. package/dist/composites/otel-collector-node.d.ts.map +1 -0
  23. package/dist/composites/otel-collector-rbac.d.ts +74 -0
  24. package/dist/composites/otel-collector-rbac.d.ts.map +1 -0
  25. package/dist/composites/otel-collector-shape.d.ts +7 -0
  26. package/dist/composites/otel-collector-shape.d.ts.map +1 -1
  27. package/dist/composites/otel-collector.d.ts +17 -21
  28. package/dist/composites/otel-collector.d.ts.map +1 -1
  29. package/dist/composites/ray-cluster.d.ts +6 -6
  30. package/dist/composites/ray-job.d.ts +5 -5
  31. package/dist/composites/ray-service.d.ts +6 -6
  32. package/dist/crd/crd-sources.d.ts.map +1 -1
  33. package/dist/crd/loader.d.ts.map +1 -1
  34. package/dist/crd/oci-chart.d.ts +50 -0
  35. package/dist/crd/oci-chart.d.ts.map +1 -0
  36. package/dist/crd/types.d.ts +5 -0
  37. package/dist/crd/types.d.ts.map +1 -1
  38. package/dist/effect-receipt-row.d.ts.map +1 -1
  39. package/dist/generated/index.d.ts +752 -729
  40. package/dist/generated/index.d.ts.map +1 -1
  41. package/dist/import/embedded.d.ts +4 -2
  42. package/dist/import/embedded.d.ts.map +1 -1
  43. package/dist/import/generator.d.ts.map +1 -1
  44. package/dist/import/live-export.d.ts +5 -0
  45. package/dist/import/live-export.d.ts.map +1 -1
  46. package/dist/import/parser.d.ts.map +1 -1
  47. package/dist/import/testdata/embedded/fixtures.d.ts +6 -0
  48. package/dist/import/testdata/embedded/fixtures.d.ts.map +1 -1
  49. package/dist/integrity.json +8 -6
  50. package/dist/lint/audit-catalog.d.ts.map +1 -1
  51. package/dist/lint/post-synth/index.d.ts.map +1 -1
  52. package/dist/lint/post-synth/otel-placement-helpers.d.ts +5 -1
  53. package/dist/lint/post-synth/otel-placement-helpers.d.ts.map +1 -1
  54. package/dist/lint/post-synth/wk8604.d.ts +19 -0
  55. package/dist/lint/post-synth/wk8604.d.ts.map +1 -0
  56. package/dist/lint/post-synth/wk8605.d.ts +23 -0
  57. package/dist/lint/post-synth/wk8605.d.ts.map +1 -0
  58. package/dist/manifest.json +1 -1
  59. package/dist/meta.json +156 -17
  60. package/dist/okf/index.md +5 -0
  61. package/dist/okf/rules/WK8604.md +11 -0
  62. package/dist/okf/rules/WK8605.md +11 -0
  63. package/dist/okf/types/APIGroup.md +3 -3
  64. package/dist/okf/types/APIGroupList.md +1 -1
  65. package/dist/okf/types/APIResourceList.md +1 -1
  66. package/dist/okf/types/APIService.md +1 -1
  67. package/dist/okf/types/APIServiceList.md +2 -2
  68. package/dist/okf/types/APIVersions.md +1 -1
  69. package/dist/okf/types/BatchJob.md +1 -1
  70. package/dist/okf/types/CSIDriver.md +1 -1
  71. package/dist/okf/types/CSIDriverList.md +2 -2
  72. package/dist/okf/types/CSINode.md +1 -1
  73. package/dist/okf/types/CSINodeList.md +2 -2
  74. package/dist/okf/types/CSIStorageCapacity.md +2 -2
  75. package/dist/okf/types/CSIStorageCapacityList.md +2 -2
  76. package/dist/okf/types/CertificateSigningRequest.md +1 -1
  77. package/dist/okf/types/CertificateSigningRequestList.md +2 -2
  78. package/dist/okf/types/ClusterRole.md +1 -1
  79. package/dist/okf/types/ClusterRoleBindingList.md +2 -2
  80. package/dist/okf/types/ClusterRoleList.md +2 -2
  81. package/dist/okf/types/ClusterTrustBundle.md +1 -1
  82. package/dist/okf/types/ClusterTrustBundleList.md +2 -2
  83. package/dist/okf/types/ComponentStatus.md +1 -1
  84. package/dist/okf/types/ComponentStatusList.md +2 -2
  85. package/dist/okf/types/ConfigMapList.md +2 -2
  86. package/dist/okf/types/ControllerRevisionList.md +2 -2
  87. package/dist/okf/types/CoreEventList.md +2 -2
  88. package/dist/okf/types/CronJob.md +1 -1
  89. package/dist/okf/types/CronJobList.md +2 -2
  90. package/dist/okf/types/CustomResourceDefinition.md +1 -1
  91. package/dist/okf/types/CustomResourceDefinitionList.md +2 -2
  92. package/dist/okf/types/DaemonSet.md +1 -1
  93. package/dist/okf/types/DaemonSetList.md +2 -2
  94. package/dist/okf/types/DeleteOptions.md +1 -1
  95. package/dist/okf/types/Deploy.md +1 -1
  96. package/dist/okf/types/DeploymentList.md +2 -2
  97. package/dist/okf/types/DeviceClass.md +1 -1
  98. package/dist/okf/types/DeviceClassList.md +2 -2
  99. package/dist/okf/types/DeviceTaintRule.md +1 -1
  100. package/dist/okf/types/DeviceTaintRuleList.md +2 -2
  101. package/dist/okf/types/EndpointSlice.md +2 -2
  102. package/dist/okf/types/EndpointSliceList.md +2 -2
  103. package/dist/okf/types/Endpoints.md +1 -1
  104. package/dist/okf/types/EndpointsList.md +2 -2
  105. package/dist/okf/types/Event.md +2 -2
  106. package/dist/okf/types/EventsEvent.md +2 -2
  107. package/dist/okf/types/EventsEventList.md +2 -2
  108. package/dist/okf/types/Eviction.md +1 -1
  109. package/dist/okf/types/FlowSchema.md +1 -1
  110. package/dist/okf/types/FlowSchemaList.md +2 -2
  111. package/dist/okf/types/GrafanaDashboard.md +14 -0
  112. package/dist/okf/types/GrafanaDatasource.md +14 -0
  113. package/dist/okf/types/GrafanaFolder.md +14 -0
  114. package/dist/okf/types/HorizontalPodAutoscaler.md +1 -1
  115. package/dist/okf/types/HorizontalPodAutoscalerList.md +2 -2
  116. package/dist/okf/types/IPAddress.md +1 -1
  117. package/dist/okf/types/IPAddressList.md +2 -2
  118. package/dist/okf/types/Ing.md +1 -1
  119. package/dist/okf/types/IngressClass.md +1 -1
  120. package/dist/okf/types/IngressClassList.md +2 -2
  121. package/dist/okf/types/IngressList.md +2 -2
  122. package/dist/okf/types/JobList.md +2 -2
  123. package/dist/okf/types/Lease.md +1 -1
  124. package/dist/okf/types/LeaseCandidate.md +1 -1
  125. package/dist/okf/types/LeaseCandidateList.md +2 -2
  126. package/dist/okf/types/LeaseList.md +2 -2
  127. package/dist/okf/types/LimitRange.md +1 -1
  128. package/dist/okf/types/LimitRangeList.md +2 -2
  129. package/dist/okf/types/LocalSubjectAccessReview.md +1 -1
  130. package/dist/okf/types/MutatingAdmissionPolicy.md +1 -1
  131. package/dist/okf/types/MutatingAdmissionPolicyBinding.md +1 -1
  132. package/dist/okf/types/MutatingAdmissionPolicyBindingList.md +2 -2
  133. package/dist/okf/types/MutatingAdmissionPolicyList.md +2 -2
  134. package/dist/okf/types/MutatingWebhookConfiguration.md +1 -1
  135. package/dist/okf/types/MutatingWebhookConfigurationList.md +2 -2
  136. package/dist/okf/types/Namespace.md +1 -1
  137. package/dist/okf/types/NamespaceList.md +2 -2
  138. package/dist/okf/types/NetPol.md +1 -1
  139. package/dist/okf/types/NetworkPolicyList.md +2 -2
  140. package/dist/okf/types/Node.md +1 -1
  141. package/dist/okf/types/NodeList.md +2 -2
  142. package/dist/okf/types/PersistentVolume.md +1 -1
  143. package/dist/okf/types/PersistentVolumeClaimList.md +2 -2
  144. package/dist/okf/types/PersistentVolumeList.md +2 -2
  145. package/dist/okf/types/PodCertificateRequest.md +1 -1
  146. package/dist/okf/types/PodCertificateRequestList.md +2 -2
  147. package/dist/okf/types/PodDisruptionBudgetList.md +2 -2
  148. package/dist/okf/types/PodList.md +2 -2
  149. package/dist/okf/types/PodTemplateList.md +2 -2
  150. package/dist/okf/types/PriorityClassList.md +2 -2
  151. package/dist/okf/types/PriorityLevelConfiguration.md +1 -1
  152. package/dist/okf/types/PriorityLevelConfigurationList.md +2 -2
  153. package/dist/okf/types/ReplicaSet.md +1 -1
  154. package/dist/okf/types/ReplicaSetList.md +2 -2
  155. package/dist/okf/types/ReplicationController.md +1 -1
  156. package/dist/okf/types/ReplicationControllerList.md +2 -2
  157. package/dist/okf/types/ResourceClaim.md +1 -1
  158. package/dist/okf/types/ResourceClaimList.md +2 -2
  159. package/dist/okf/types/ResourceClaimTemplate.md +1 -1
  160. package/dist/okf/types/ResourceClaimTemplateList.md +2 -2
  161. package/dist/okf/types/ResourceQuota.md +1 -1
  162. package/dist/okf/types/ResourceQuotaList.md +2 -2
  163. package/dist/okf/types/ResourceSlice.md +1 -1
  164. package/dist/okf/types/ResourceSliceList.md +2 -2
  165. package/dist/okf/types/RoleBindingList.md +2 -2
  166. package/dist/okf/types/RoleList.md +2 -2
  167. package/dist/okf/types/RuntimeClass.md +2 -2
  168. package/dist/okf/types/RuntimeClassList.md +2 -2
  169. package/dist/okf/types/Scale.md +1 -1
  170. package/dist/okf/types/SecretList.md +2 -2
  171. package/dist/okf/types/SelfSubjectAccessReview.md +1 -1
  172. package/dist/okf/types/SelfSubjectRulesReview.md +1 -1
  173. package/dist/okf/types/Service.md +1 -1
  174. package/dist/okf/types/ServiceAccountList.md +2 -2
  175. package/dist/okf/types/ServiceCIDR.md +1 -1
  176. package/dist/okf/types/ServiceCIDRList.md +2 -2
  177. package/dist/okf/types/ServiceList.md +2 -2
  178. package/dist/okf/types/StatefulSet.md +1 -1
  179. package/dist/okf/types/StatefulSetList.md +2 -2
  180. package/dist/okf/types/Status.md +2 -2
  181. package/dist/okf/types/StorageClass.md +1 -1
  182. package/dist/okf/types/StorageClassList.md +2 -2
  183. package/dist/okf/types/StorageVersionMigration.md +1 -1
  184. package/dist/okf/types/StorageVersionMigrationList.md +2 -2
  185. package/dist/okf/types/SubjectAccessReview.md +1 -1
  186. package/dist/okf/types/TokenRequest.md +1 -1
  187. package/dist/okf/types/TokenReview.md +1 -1
  188. package/dist/okf/types/ValidatingAdmissionPolicy.md +1 -1
  189. package/dist/okf/types/ValidatingAdmissionPolicyBinding.md +1 -1
  190. package/dist/okf/types/ValidatingAdmissionPolicyBindingList.md +2 -2
  191. package/dist/okf/types/ValidatingAdmissionPolicyList.md +2 -2
  192. package/dist/okf/types/ValidatingWebhookConfiguration.md +1 -1
  193. package/dist/okf/types/ValidatingWebhookConfigurationList.md +2 -2
  194. package/dist/okf/types/VolumeAttachment.md +1 -1
  195. package/dist/okf/types/VolumeAttachmentList.md +2 -2
  196. package/dist/okf/types/VolumeAttributesClassList.md +2 -2
  197. package/dist/op/activities/argo.d.ts.map +1 -1
  198. package/dist/op/activities/index.d.ts +3 -3
  199. package/dist/op/activities/index.d.ts.map +1 -1
  200. package/dist/op/activities/wait-for-ready.d.ts.map +1 -1
  201. package/dist/op/builders.d.ts.map +1 -1
  202. package/dist/rules/otel-placement-helpers.ts +7 -11
  203. package/dist/rules/wk8604.ts +29 -0
  204. package/dist/rules/wk8605.ts +131 -0
  205. package/dist/skills/chant-k8s.md +1 -1
  206. package/dist/spec/parse.d.ts +27 -0
  207. package/dist/spec/parse.d.ts.map +1 -1
  208. package/dist/types/index.d.ts +5360 -972
  209. package/dist/variables.d.ts.map +1 -1
  210. package/package.json +4 -4
  211. package/src/codegen/declarations.test.ts +118 -0
  212. package/src/codegen/generate-typescript.ts +69 -4
  213. package/src/codegen/generate.ts +15 -6
  214. package/src/composites/__snapshots__/gke-otel-collector.snapshot.test.ts.snap +2 -68
  215. package/src/composites/catalog.ts +12 -0
  216. package/src/composites/gke-otel-collector.snapshot.test.ts +3 -1
  217. package/src/composites/gke-otel-collector.ts +13 -2
  218. package/src/composites/index.ts +1 -0
  219. package/src/composites/otel-collector-agent.ts +45 -11
  220. package/src/composites/otel-collector-gateway.test.ts +102 -5
  221. package/src/composites/otel-collector-gateway.ts +96 -18
  222. package/src/composites/otel-collector-node.test.ts +174 -0
  223. package/src/composites/otel-collector-node.ts +213 -0
  224. package/src/composites/otel-collector-rbac.test.ts +114 -0
  225. package/src/composites/otel-collector-rbac.ts +144 -0
  226. package/src/composites/otel-collector-shape.ts +19 -0
  227. package/src/composites/otel-collector.ts +40 -35
  228. package/src/crd/crd-sources.ts +26 -0
  229. package/src/crd/loader.test.ts +9 -1
  230. package/src/crd/loader.ts +26 -3
  231. package/src/crd/oci-chart.test.ts +149 -0
  232. package/src/crd/oci-chart.ts +178 -0
  233. package/src/crd/types.ts +5 -0
  234. package/src/generated/index.d.ts +5360 -972
  235. package/src/generated/index.ts +23 -0
  236. package/src/generated/lexicon-k8s.json +156 -17
  237. package/src/generated/operations.json +48 -0
  238. package/src/import/embedded-live.test.ts +180 -0
  239. package/src/import/embedded-roundtrip.test.ts +73 -7
  240. package/src/import/embedded-types.e2e.test.ts +3 -1
  241. package/src/import/embedded.test.ts +64 -0
  242. package/src/import/embedded.ts +31 -2
  243. package/src/import/generator.test.ts +19 -0
  244. package/src/import/generator.ts +20 -2
  245. package/src/import/live-export.ts +10 -2
  246. package/src/import/testdata/embedded/README.md +4 -1
  247. package/src/import/testdata/embedded/alertmanager-configmap.yaml +91 -0
  248. package/src/import/testdata/embedded/fixtures.ts +18 -0
  249. package/src/import/testdata/embedded/grafana-operator-dashboard.yaml +363 -0
  250. package/src/import/testdata/embedded/grafana-v2-dashboard-configmap.yaml +851 -0
  251. package/src/lint/audit-catalog.ts +2 -0
  252. package/src/lint/post-synth/index.ts +4 -0
  253. package/src/lint/post-synth/otel-placement-helpers.ts +7 -11
  254. package/src/lint/post-synth/otel-placement.test.ts +35 -0
  255. package/src/lint/post-synth/post-synth.test.ts +3 -3
  256. package/src/lint/post-synth/wk8604.ts +29 -0
  257. package/src/lint/post-synth/wk8605.test.ts +141 -0
  258. package/src/lint/post-synth/wk8605.ts +131 -0
  259. package/src/skills/chant-k8s.md +1 -1
  260. package/src/spec/parse.test.ts +118 -0
  261. package/src/spec/parse.ts +250 -29
package/src/spec/parse.ts CHANGED
@@ -39,6 +39,29 @@ export interface ParsedPropertyType {
39
39
  properties: ParsedProperty[];
40
40
  }
41
41
 
42
+ /**
43
+ * A named OpenAPI object definition emitted as a declaration-only interface
44
+ * in the `.d.ts` (chant #3093): `DeploymentSpec`, `ServiceSpec`, `JobSpec`
45
+ * and every other object definition a resource reaches. Unlike the
46
+ * {@link PROPERTY_TYPE_DEFS} property types it has no runtime constructor and
47
+ * no registry entry; authors write it as an object literal.
48
+ */
49
+ export interface ParsedDefinitionType {
50
+ /** TypeScript name, e.g. `DeploymentSpec` or `FlowcontrolSubject`. */
51
+ name: string;
52
+ /** The definition key, e.g. `io.k8s.api.apps.v1.DeploymentSpec`. */
53
+ defKey: string;
54
+ description?: string;
55
+ properties: ParsedProperty[];
56
+ }
57
+
58
+ /** Everything one swagger document yields: resources and property types, plus the declaration-only interfaces. */
59
+ export interface K8sSwaggerParse {
60
+ results: K8sParseResult[];
61
+ /** Sorted by name. */
62
+ definitionTypes: ParsedDefinitionType[];
63
+ }
64
+
42
65
  export interface ParsedEnum {
43
66
  name: string;
44
67
  values: string[];
@@ -237,12 +260,22 @@ const PROPERTY_TYPE_DEFS: Record<string, { typeName: string; description: string
237
260
  * Returns one result per top-level resource identified by x-kubernetes-group-version-kind.
238
261
  */
239
262
  export function parseK8sSwagger(data: string | Buffer): K8sParseResult[] {
263
+ return parseK8sSwaggerTypes(data).results;
264
+ }
265
+
266
+ /**
267
+ * Parse the swagger document into resource and property-type results, and the
268
+ * declaration-only interfaces for every other object definition a resource
269
+ * reaches (chant #3093).
270
+ */
271
+ export function parseK8sSwaggerTypes(data: string | Buffer): K8sSwaggerParse {
240
272
  const spec: SwaggerSpec = JSON.parse(typeof data === "string" ? data : data.toString("utf-8"));
241
273
  const definitions = spec.definitions ?? {};
242
274
  const results: K8sParseResult[] = [];
243
275
  const operations = parseOperations(spec.paths);
244
276
 
245
- // Phase 1: Extract top-level resources (definitions with GVK)
277
+ // Which definitions become resources: those with a GVK, preferred version only.
278
+ const resourceDefs: Array<{ defKey: string; def: SwaggerDefinition; gvk: GroupVersionKind }> = [];
246
279
  for (const [defKey, def] of Object.entries(definitions)) {
247
280
  const gvks = def["x-kubernetes-group-version-kind"];
248
281
  if (!gvks || gvks.length === 0) continue;
@@ -252,9 +285,22 @@ export function parseK8sSwagger(data: string | Buffer): K8sParseResult[] {
252
285
 
253
286
  // Skip internal/legacy API versions — only take the preferred version
254
287
  if (!isPreferredVersion(defKey, gvk, definitions)) continue;
288
+ resourceDefs.push({ defKey, def, gvk });
289
+ }
255
290
 
291
+ // Name every object definition a resource reaches before any property is
292
+ // typed, so a `$ref` resolves to its interface instead of a Record.
293
+ const reachable = reachableDefinitions(resourceDefs.map((r) => r.def), definitions);
294
+ const ctx: TypeContext = {
295
+ definitions,
296
+ names: nameDefinitions(reachable, definitions),
297
+ resources: new Set(resourceDefs.map((r) => r.defKey)),
298
+ };
299
+
300
+ // Phase 1: Extract top-level resources (definitions with GVK)
301
+ for (const { defKey, def, gvk } of resourceDefs) {
256
302
  const typeName = gvkToTypeName(gvk);
257
- const result = extractResource(defKey, def, typeName, gvk, definitions);
303
+ const result = extractResource(defKey, def, typeName, gvk, ctx);
258
304
  if (result) {
259
305
  const operation = operations.get(gvkKey(gvk));
260
306
  if (operation) result.operation = operation;
@@ -267,11 +313,189 @@ export function parseK8sSwagger(data: string | Buffer): K8sParseResult[] {
267
313
  const def = definitions[defKey];
268
314
  if (!def) continue;
269
315
 
270
- const result = extractPropertyType(defKey, def, config.typeName, config.description, definitions);
316
+ const result = extractPropertyType(defKey, def, config.typeName, config.description, ctx);
271
317
  if (result) results.push(result);
272
318
  }
273
319
 
274
- return results;
320
+ // Phase 3: Every other reachable object definition, as an interface.
321
+ const definitionTypes: ParsedDefinitionType[] = [];
322
+ for (const defKey of reachable) {
323
+ if (PROPERTY_TYPE_DEFS[defKey]) continue;
324
+ const def = definitions[defKey];
325
+ definitionTypes.push({
326
+ name: ctx.names.get(defKey)!,
327
+ defKey,
328
+ description: def.description,
329
+ properties: parseProperties(def.properties ?? {}, new Set(def.required ?? []), ctx),
330
+ });
331
+ }
332
+ definitionTypes.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
333
+
334
+ return { results, definitionTypes };
335
+ }
336
+
337
+ // ── Definition interfaces (chant #3093) ────────────────────────────
338
+
339
+ /**
340
+ * Definitions that stay open however they are reached: `RawExtension` holds an
341
+ * arbitrary embedded object, and the rest are scalars on the wire. A Quantity
342
+ * is a string in the schema, but the API server also decodes a number
343
+ * (`cpu: 1`), and manifests write it both ways.
344
+ */
345
+ const OPEN_OR_SCALAR_DEFS: Record<string, string> = {
346
+ "io.k8s.apimachinery.pkg.util.intstr.IntOrString": "string | number",
347
+ "io.k8s.apimachinery.pkg.api.resource.Quantity": "string | number",
348
+ "io.k8s.apimachinery.pkg.apis.meta.v1.Time": "string",
349
+ "io.k8s.apimachinery.pkg.apis.meta.v1.MicroTime": "string",
350
+ "io.k8s.apimachinery.pkg.runtime.RawExtension": "Record<string, any>",
351
+ };
352
+
353
+ interface TypeContext {
354
+ definitions: Record<string, SwaggerDefinition>;
355
+ /** Definition key → TypeScript name, for every definition typed as a class or interface. */
356
+ names: Map<string, string>;
357
+ /** Emitted resource definitions, by key. */
358
+ resources: Set<string>;
359
+ /** Resource definitions being inlined, to stop a cycle. */
360
+ inlining?: Set<string>;
361
+ }
362
+
363
+ /**
364
+ * A resource embedded in another object (`StatefulSetSpec.volumeClaimTemplates`
365
+ * holds PersistentVolumeClaims, a List holds its items) is typed inline with
366
+ * the props its class takes. A name would have to avoid the class's own.
367
+ */
368
+ function inlineResourceType(defKey: string, ctx: TypeContext): string {
369
+ const inlining = ctx.inlining ?? new Set<string>();
370
+ if (inlining.has(defKey)) return "Record<string, any>";
371
+ const def = ctx.definitions[defKey];
372
+ const inner: TypeContext = { ...ctx, inlining: new Set([...inlining, defKey]) };
373
+ const required = new Set(def.required ?? []);
374
+ const members = Object.entries(def.properties ?? {})
375
+ .filter(([name]) => name !== "apiVersion" && name !== "kind" && name !== "status")
376
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
377
+ .map(([name, prop]) => `${name}${required.has(name) ? "" : "?"}: ${resolvePropertyType(prop, inner)}`);
378
+ return members.length === 0 ? "Record<string, any>" : `{ ${members.join("; ")} }`;
379
+ }
380
+
381
+ /**
382
+ * Whether a definition becomes a named type: an object with properties that
383
+ * is not itself a resource. A `$ref` to a resource is typed inline instead
384
+ * ({@link inlineResourceType}).
385
+ */
386
+ function isNamedObjectDef(defKey: string, def: SwaggerDefinition | undefined): def is SwaggerDefinition {
387
+ if (!def?.properties || defKey in OPEN_OR_SCALAR_DEFS) return false;
388
+ return !def["x-kubernetes-group-version-kind"]?.length;
389
+ }
390
+
391
+ /**
392
+ * The object definitions reachable from the resources' authored properties
393
+ * (everything but `apiVersion`, `kind` and `status`), plus the well-known
394
+ * property types. Sorted by key. A recursive definition such as
395
+ * `JSONSchemaProps` is visited once and refers to itself by name, so no depth
396
+ * bound is needed.
397
+ */
398
+ function reachableDefinitions(
399
+ resources: SwaggerDefinition[],
400
+ definitions: Record<string, SwaggerDefinition>,
401
+ ): string[] {
402
+ const seen = new Set<string>();
403
+ const queue: string[] = [];
404
+ const visitRef = (defKey: string) => {
405
+ if (seen.has(defKey) || !isNamedObjectDef(defKey, definitions[defKey])) return;
406
+ seen.add(defKey);
407
+ queue.push(defKey);
408
+ };
409
+ const walk = (prop: SwaggerProperty | undefined) => {
410
+ if (!prop) return;
411
+ if (prop.$ref) {
412
+ if (prop.$ref.startsWith("#/definitions/")) visitRef(prop.$ref.slice("#/definitions/".length));
413
+ return;
414
+ }
415
+ walk(prop.items);
416
+ if (prop.additionalProperties && typeof prop.additionalProperties === "object") walk(prop.additionalProperties);
417
+ };
418
+
419
+ for (const def of resources) {
420
+ for (const [name, prop] of Object.entries(def.properties ?? {})) {
421
+ if (name !== "apiVersion" && name !== "kind" && name !== "status") walk(prop);
422
+ }
423
+ }
424
+ for (const defKey of Object.keys(PROPERTY_TYPE_DEFS)) visitRef(defKey);
425
+ while (queue.length > 0) {
426
+ const def = definitions[queue.shift()!];
427
+ for (const prop of Object.values(def.properties ?? {})) walk(prop);
428
+ }
429
+ return [...seen].sort();
430
+ }
431
+
432
+ const VERSION_SEGMENT = /^v\d+((alpha|beta)\d+)?$/;
433
+
434
+ /** `io.k8s.api.flowcontrol.v1.Subject` → `{ group: "Flowcontrol", version: "V1", kind: "Subject" }`. */
435
+ function definitionKeyParts(defKey: string): { group: string; version: string; kind: string } {
436
+ const parts = defKey.split(".");
437
+ const kind = parts[parts.length - 1];
438
+ const vIdx = parts.length - 2;
439
+ const version = VERSION_SEGMENT.test(parts[vIdx] ?? "") ? parts[vIdx] : "";
440
+ const group = (version ? parts[vIdx - 1] : parts[vIdx]) ?? "";
441
+ const pascal = (s: string) => s.split(/[^A-Za-z0-9]+/).map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
442
+ return { group: pascal(group), version: pascal(version), kind };
443
+ }
444
+
445
+ /**
446
+ * Give every reachable definition a TypeScript name.
447
+ *
448
+ * The well-known property types keep their friendly names. Every other
449
+ * definition takes the last segment of its key (`DeploymentSpec`) when no
450
+ * other reachable definition shares that segment and no resource kind or
451
+ * friendly name already uses it. Otherwise each contender is qualified by its
452
+ * API group (`FlowcontrolSubject`, `CoreResourceClaim`), and by group and
453
+ * version when one group has several (`ResourceV1beta2Device`). The rule
454
+ * reads only the set of keys, so the result does not depend on the order of
455
+ * the document.
456
+ */
457
+ function nameDefinitions(reachable: string[], definitions: Record<string, SwaggerDefinition>): Map<string, string> {
458
+ const names = new Map<string, string>();
459
+ const taken = new Set<string>();
460
+ for (const def of Object.values(definitions)) {
461
+ for (const gvk of def["x-kubernetes-group-version-kind"] ?? []) taken.add(gvk.kind);
462
+ }
463
+ for (const [defKey, config] of Object.entries(PROPERTY_TYPE_DEFS)) {
464
+ const name = k8sShortName(config.typeName);
465
+ names.set(defKey, name);
466
+ taken.add(name);
467
+ }
468
+
469
+ const byKind = new Map<string, string[]>();
470
+ for (const defKey of reachable) {
471
+ if (names.has(defKey)) continue;
472
+ const { kind } = definitionKeyParts(defKey);
473
+ byKind.set(kind, [...(byKind.get(kind) ?? []), defKey]);
474
+ }
475
+
476
+ for (const [kind, keys] of byKind) {
477
+ if (keys.length === 1 && !taken.has(kind)) {
478
+ names.set(keys[0], kind);
479
+ continue;
480
+ }
481
+ const groupCount = new Map<string, number>();
482
+ for (const k of keys) {
483
+ const { group } = definitionKeyParts(k);
484
+ groupCount.set(group, (groupCount.get(group) ?? 0) + 1);
485
+ }
486
+ for (const k of keys) {
487
+ const { group, version } = definitionKeyParts(k);
488
+ names.set(k, groupCount.get(group)! > 1 ? `${group}${version}${kind}` : `${group}${kind}`);
489
+ }
490
+ }
491
+
492
+ const owner = new Map<string, string>();
493
+ for (const [defKey, name] of names) {
494
+ const prev = owner.get(name);
495
+ if (prev) throw new Error(`k8s codegen: definitions ${prev} and ${defKey} both map to the type name ${name}`);
496
+ owner.set(name, defKey);
497
+ }
498
+ return names;
275
499
  }
276
500
 
277
501
  /** Stable key for a GVK, used to join the `paths` pass onto the `definitions` pass. */
@@ -429,7 +653,7 @@ function extractResource(
429
653
  def: SwaggerDefinition,
430
654
  typeName: string,
431
655
  gvk: GroupVersionKind,
432
- definitions: Record<string, SwaggerDefinition>,
656
+ ctx: TypeContext,
433
657
  ): K8sParseResult | null {
434
658
  if (!def.properties) return null;
435
659
 
@@ -445,7 +669,7 @@ function extractResource(
445
669
  }
446
670
  }
447
671
 
448
- const properties = parseProperties(filteredProps, requiredSet, definitions);
672
+ const properties = parseProperties(filteredProps, requiredSet, ctx);
449
673
 
450
674
  return {
451
675
  resource: {
@@ -473,12 +697,12 @@ function extractPropertyType(
473
697
  def: SwaggerDefinition,
474
698
  typeName: string,
475
699
  description: string,
476
- definitions: Record<string, SwaggerDefinition>,
700
+ ctx: TypeContext,
477
701
  ): K8sParseResult | null {
478
702
  if (!def.properties) return null;
479
703
 
480
704
  const requiredSet = new Set<string>(def.required ?? []);
481
- const properties = parseProperties(def.properties, requiredSet, definitions);
705
+ const properties = parseProperties(def.properties, requiredSet, ctx);
482
706
 
483
707
  const gvkParts = typeName.split("::");
484
708
  return {
@@ -502,12 +726,12 @@ function extractPropertyType(
502
726
  function parseProperties(
503
727
  properties: Record<string, SwaggerProperty>,
504
728
  requiredSet: Set<string>,
505
- definitions: Record<string, SwaggerDefinition>,
729
+ ctx: TypeContext,
506
730
  ): ParsedProperty[] {
507
731
  const result: ParsedProperty[] = [];
508
732
 
509
733
  for (const [name, prop] of Object.entries(properties)) {
510
- const tsType = resolvePropertyType(prop, definitions);
734
+ const tsType = resolvePropertyType(prop, ctx);
511
735
  const parsed: ParsedProperty = {
512
736
  name,
513
737
  tsType,
@@ -532,12 +756,12 @@ function parseProperties(
532
756
  /**
533
757
  * Resolve a swagger property to its TypeScript type string.
534
758
  */
535
- function resolvePropertyType(prop: SwaggerProperty, definitions: Record<string, SwaggerDefinition>): string {
759
+ function resolvePropertyType(prop: SwaggerProperty, ctx: TypeContext): string {
536
760
  if (!prop) return "any";
537
761
 
538
762
  // Handle $ref
539
763
  if (prop.$ref) {
540
- return resolveRefType(prop.$ref, definitions);
764
+ return resolveRefType(prop.$ref, ctx);
541
765
  }
542
766
 
543
767
  // x-kubernetes-int-or-string
@@ -561,14 +785,14 @@ function resolvePropertyType(prop: SwaggerProperty, definitions: Record<string,
561
785
  return "boolean";
562
786
  case "array":
563
787
  if (prop.items) {
564
- const itemType = resolvePropertyType(prop.items, definitions);
788
+ const itemType = resolvePropertyType(prop.items, ctx);
565
789
  if (itemType.includes(" | ")) return `(${itemType})[]`;
566
790
  return `${itemType}[]`;
567
791
  }
568
792
  return "any[]";
569
793
  case "object":
570
794
  if (prop.additionalProperties && typeof prop.additionalProperties === "object") {
571
- const valueType = resolvePropertyType(prop.additionalProperties, definitions);
795
+ const valueType = resolvePropertyType(prop.additionalProperties, ctx);
572
796
  return `Record<string, ${valueType}>`;
573
797
  }
574
798
  return "Record<string, any>";
@@ -580,27 +804,23 @@ function resolvePropertyType(prop: SwaggerProperty, definitions: Record<string,
580
804
  /**
581
805
  * Resolve a $ref to a TypeScript type.
582
806
  */
583
- function resolveRefType(ref: string, definitions: Record<string, SwaggerDefinition>): string {
807
+ function resolveRefType(ref: string, ctx: TypeContext): string {
584
808
  const prefix = "#/definitions/";
585
809
  if (!ref.startsWith(prefix)) return "any";
586
810
 
587
811
  const defKey = ref.slice(prefix.length);
588
812
 
589
- // Well-known special types
590
- if (defKey === "io.k8s.apimachinery.pkg.util.intstr.IntOrString") return "string | number";
591
- if (defKey === "io.k8s.apimachinery.pkg.api.resource.Quantity") return "string";
592
- if (defKey === "io.k8s.apimachinery.pkg.apis.meta.v1.Time") return "string";
593
- if (defKey === "io.k8s.apimachinery.pkg.apis.meta.v1.MicroTime") return "string";
594
- if (defKey === "io.k8s.apimachinery.pkg.runtime.RawExtension") return "Record<string, any>";
595
-
596
- // Check if it's a known property type
597
- const ptConfig = PROPERTY_TYPE_DEFS[defKey];
598
- if (ptConfig) {
599
- return k8sShortName(ptConfig.typeName);
600
- }
813
+ // Well-known scalars, and RawExtension, which stays open.
814
+ const fixed = OPEN_OR_SCALAR_DEFS[defKey];
815
+ if (fixed) return fixed;
816
+
817
+ // A property class or a definition interface (chant #3093).
818
+ const named = ctx.names.get(defKey);
819
+ if (named) return named;
820
+ if (ctx.resources.has(defKey)) return inlineResourceType(defKey, ctx);
601
821
 
602
822
  // Resolve the definition
603
- const def = definitions[defKey];
823
+ const def = ctx.definitions[defKey];
604
824
  if (!def) return "any";
605
825
 
606
826
  // Enum
@@ -620,7 +840,8 @@ function resolveRefType(ref: string, definitions: Record<string, SwaggerDefiniti
620
840
  }
621
841
  }
622
842
 
623
- // Object with properties — use Record
843
+ // An object this pass does not name: a resource of a non-preferred
844
+ // version, or a definition with no properties (`JSON`, `FieldsV1`).
624
845
  if (def.properties) return "Record<string, any>";
625
846
 
626
847
  return "any";