Conversation
schema/generator used github.com/alecthomas/jsonschema, which was archived in 2022. Its limits had turned into workarounds in our code: minimum was parsed as an int (so target's 0.01 became 0 and the generator patched it back), a zero minimum in the jsonschema tag was dropped (so minimums were declared through jsonschema_extras), and tag descriptions could not contain commas. Switch to the maintained successor, github.com/invopop/jsonschema v0.14.0: - Reflect with FieldNameTag "yaml" (func.yaml is named by yaml tags) and Anonymous (no $id derived from the Go package path). - Declare every minimum in the jsonschema tag again, including DeliverySpec.Retry, and drop jsonschema_extras. - Remove restoreTargetMinimum, which the new library makes unnecessary. - Remove the trailing comment on KPAScaleOptions.Target, which was out of date and which invopop would publish as its description. The schema now declares draft 2020-12 with $defs instead of draft-04 with definitions. Apart from that, map fields use additionalProperties instead of patternProperties ".*", and the Envs list type gets its own definition. Both mean the same. Every required, enum, pattern, minimum, maximum and minItems is unchanged. TestNumericBounds checks the fractional, zero and integral bounds in the generated schema. TestDescriptionsAreComplete checks that a description sharing its tag with minimum is kept whole. Fixes knative#4190 Signed-off-by: Itx-Psycho0 <anuragh3re@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Itx-Psycho0 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Itx-Psycho0. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
hey, this moves the schema generator off the archived alecthomas/jsonschema to invopop/jsonschema v0.14.0 like discussed in #4190
what changed:
the schema now says draft 2020-12 and uses $defs instead of definitions. other than that the only differences are maps using additionalProperties instead of patternProperties ".*" and Envs getting its own definition, both mean the same thing. i compared old vs new property by property and every required/enum/pattern/min/max/minItems/description is the same
for the draft question i kept 2020-12. i validated 31 func.yaml files against both the old draft-04 schema and the new one using santhosh-tekuri/jsonschema (already in our deps). that's the 13 in the repo plus 18 edge cases like target 0.01 vs 0.001, min -1, max over int32, utilization 101, empty keda triggers, retry 0 / -1, wrong types, unknown keys etc. both schemas gave the exact same result on every file. yaml-language-server and intellij both support 2020-12 and we don't use exclusiveMinimum anywhere. and funcYamlSchemaURI() points at the release branch so people only get the new schema with the next release
deps: drops alecthomas/jsonschema and iancoleman/orderedmap, adds invopop/jsonschema v0.14.0 which brings bahlo/generic-list-go, buger/jsonparser, pb33f/ordered-map/v2 and go.yaml.in/yaml/v4 (bumped to the stable v4.0.0, invopop only asks for rc.2) as indirect. all only reachable from schema/generator
tests: rewrote main_test.go. TestNumericBounds checks the bounds in the generated schema (0.01, all the zero minimums, the int32 max etc) and that target has no exclusiveMinimum, i checked it fails if a minimum goes back to jsonschema_extras. TestDescriptionsAreComplete checks descriptions that share a tag with minimum don't get cut. make check-schema and make check-embedded-fs pass. make check only shows the 9 staticcheck findings that are on main right now too, none in files this touches. unit tests for schema/ and pkg/functions pass except TestTemplates_ModeCustom which fails on main too on my machine (umask 0002)
/kind cleanup
Fixes #4190
Release Note
func.yaml JSON schema now uses JSON Schema draft 2020-12 instead of draft-04, the rules it checks are the same