From 96155d6544ec5754b99321de613100431a87b5a1 Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Sat, 12 Aug 2023 11:01:30 +0200 Subject: [PATCH] fix(generation): Handle several untyped objects Some objects were not being caught as 'open'/untyped, so the conversion layer was dropping their contents. Now they are passed thru as-is. --- generation/describe-shapes.ts | 14 +++++++------- lib/argo-cd/argoproj.io@v1alpha1/structs.ts | 9 ++------- lib/builtin/meta@v1/structs.ts | 14 ++------------ lib/vpa/autoscaling.k8s.io@v1/structs.ts | 18 ++++-------------- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/generation/describe-shapes.ts b/generation/describe-shapes.ts index 5da7163..2191f8a 100644 --- a/generation/describe-shapes.ts +++ b/generation/describe-shapes.ts @@ -68,6 +68,13 @@ export class ShapeLibrary { inner: this.readSchema(schema.additionalProperties, null), }; + } else if (schema['x-kubernetes-preserve-unknown-fields'] || localName == 'FieldsV1') { + return { + type: 'any', + reference: 'unknown', + description: schema.description ?? undefined, + }; + } else if (schema.type === 'object') { return { type: 'structure', @@ -127,13 +134,6 @@ export class ShapeLibrary { description: schema.description ?? undefined, }; - } else if (schema['x-kubernetes-preserve-unknown-fields']) { - return { - type: 'any', - reference: 'unknown', - description: schema.description ?? undefined, - }; - } else if (localName === 'JSONSchemaPropsOrBool') { return { type: 'any', diff --git a/lib/argo-cd/argoproj.io@v1alpha1/structs.ts b/lib/argo-cd/argoproj.io@v1alpha1/structs.ts index 210b540..b498d86 100644 --- a/lib/argo-cd/argoproj.io@v1alpha1/structs.ts +++ b/lib/argo-cd/argoproj.io@v1alpha1/structs.ts @@ -44,8 +44,7 @@ export interface ApplicationSource { skipCrds?: boolean | null; valueFiles?: Array | null; values?: string | null; - valuesObject?: { - } | null; + valuesObject?: c.JSONValue | null; version?: string | null; } | null; kustomize?: { @@ -118,7 +117,7 @@ export function toApplicationSource_helm(input: c.JSONValue) { skipCrds: c.readOpt(obj["skipCrds"], c.checkBool), valueFiles: c.readOpt(obj["valueFiles"], x => c.readList(x, c.checkStr)), values: c.readOpt(obj["values"], c.checkStr), - valuesObject: c.readOpt(obj["valuesObject"], toApplicationSource_helm_valuesObject), + valuesObject: c.readOpt(obj["valuesObject"], c.identity), version: c.readOpt(obj["version"], c.checkStr), }} export function toApplicationSource_kustomize(input: c.JSONValue) { @@ -163,10 +162,6 @@ export function toApplicationSource_helm_parameters(input: c.JSONValue) { name: c.readOpt(obj["name"], c.checkStr), value: c.readOpt(obj["value"], c.checkStr), }} -export function toApplicationSource_helm_valuesObject(input: c.JSONValue) { - const obj = c.checkObj(input); - return { - }} export function toApplicationSource_kustomize_replicas(input: c.JSONValue) { const obj = c.checkObj(input); return { diff --git a/lib/builtin/meta@v1/structs.ts b/lib/builtin/meta@v1/structs.ts index 0676eb7..b49371c 100644 --- a/lib/builtin/meta@v1/structs.ts +++ b/lib/builtin/meta@v1/structs.ts @@ -224,16 +224,7 @@ export function fromPreconditions(input: Preconditions): c.JSONValue { Each key is either a '.' representing the field itself, and will always map to an empty set, or a string representing a sub-field or item. The string will follow one of these four formats: 'f:', where is the name of a field in a struct, or key in a map 'v:', where is the exact json formatted value of a list item 'i:', where is position of a item in a list 'k:', where is a map of a list item's key fields to their unique values If a key maps to an empty Fields value, the field that key represents is part of the set. The exact format is defined in sigs.k8s.io/structured-merge-diff */ -export interface FieldsV1 { -} -export function toFieldsV1(input: c.JSONValue): FieldsV1 { - const obj = c.checkObj(input); - return { - }} -export function fromFieldsV1(input: FieldsV1): c.JSONValue { - return { - ...input, - }} +export type FieldsV1 = c.JSONValue; /** A label selector is a label query over a set of resources. The result of matchLabels and matchExpressions are ANDed. An empty label selector matches all objects. A null label selector matches no objects. */ export interface LabelSelector { @@ -305,7 +296,7 @@ export function toManagedFieldsEntry(input: c.JSONValue): ManagedFieldsEntry { return { apiVersion: c.readOpt(obj["apiVersion"], c.checkStr), fieldsType: c.readOpt(obj["fieldsType"], c.checkStr), - fieldsV1: c.readOpt(obj["fieldsV1"], toFieldsV1), + fieldsV1: c.readOpt(obj["fieldsV1"], c.identity), manager: c.readOpt(obj["manager"], c.checkStr), operation: c.readOpt(obj["operation"], c.checkStr), subresource: c.readOpt(obj["subresource"], c.checkStr), @@ -314,7 +305,6 @@ export function toManagedFieldsEntry(input: c.JSONValue): ManagedFieldsEntry { export function fromManagedFieldsEntry(input: ManagedFieldsEntry): c.JSONValue { return { ...input, - fieldsV1: input.fieldsV1 != null ? fromFieldsV1(input.fieldsV1) : undefined, time: input.time != null ? c.fromTime(input.time) : undefined, }} diff --git a/lib/vpa/autoscaling.k8s.io@v1/structs.ts b/lib/vpa/autoscaling.k8s.io@v1/structs.ts index 125c8fc..e7b8915 100644 --- a/lib/vpa/autoscaling.k8s.io@v1/structs.ts +++ b/lib/vpa/autoscaling.k8s.io@v1/structs.ts @@ -18,8 +18,7 @@ export interface VerticalPodAutoscalerCheckpoint { } | null; status?: { cpuHistogram?: { - bucketWeights?: { - } | null; + bucketWeights?: c.JSONValue | null; referenceTimestamp?: c.Time | null; totalWeight?: number | null; } | null; @@ -27,8 +26,7 @@ export interface VerticalPodAutoscalerCheckpoint { lastSampleStart?: c.Time | null; lastUpdateTime?: c.Time | null; memoryHistogram?: { - bucketWeights?: { - } | null; + bucketWeights?: c.JSONValue | null; referenceTimestamp?: c.Time | null; totalWeight?: number | null; } | null; @@ -84,25 +82,17 @@ export function toVerticalPodAutoscalerCheckpoint_status(input: c.JSONValue) { export function toVerticalPodAutoscalerCheckpoint_status_cpuHistogram(input: c.JSONValue) { const obj = c.checkObj(input); return { - bucketWeights: c.readOpt(obj["bucketWeights"], toVerticalPodAutoscalerCheckpoint_status_cpuHistogram_bucketWeights), + bucketWeights: c.readOpt(obj["bucketWeights"], c.identity), referenceTimestamp: c.readOpt(obj["referenceTimestamp"], c.toTime), totalWeight: c.readOpt(obj["totalWeight"], c.checkNum), }} export function toVerticalPodAutoscalerCheckpoint_status_memoryHistogram(input: c.JSONValue) { const obj = c.checkObj(input); return { - bucketWeights: c.readOpt(obj["bucketWeights"], toVerticalPodAutoscalerCheckpoint_status_memoryHistogram_bucketWeights), + bucketWeights: c.readOpt(obj["bucketWeights"], c.identity), referenceTimestamp: c.readOpt(obj["referenceTimestamp"], c.toTime), totalWeight: c.readOpt(obj["totalWeight"], c.checkNum), }} -export function toVerticalPodAutoscalerCheckpoint_status_cpuHistogram_bucketWeights(input: c.JSONValue) { - const obj = c.checkObj(input); - return { - }} -export function toVerticalPodAutoscalerCheckpoint_status_memoryHistogram_bucketWeights(input: c.JSONValue) { - const obj = c.checkObj(input); - return { - }} export interface VerticalPodAutoscalerCheckpointList extends ListOf { apiVersion?: "autoscaling.k8s.io/v1";