Registry Mirror
Skip to content

Conversation

@Itx-Psycho0

Copy link
Copy Markdown
Contributor

hey, this moves the schema generator off the archived alecthomas/jsonschema to invopop/jsonschema v0.14.0 like discussed in #4190

what changed:

  • schema/generator/main.go uses invopop now with FieldNameTag "yaml" (func.yaml uses yaml tags) and Anonymous true so it doesn't add a fake $id from the go package path
  • all the minimums are back in the jsonschema tag, no more jsonschema_extras. that includes DeliverySpec.Retry in function.go which wasn't in the issue
  • removed restoreTargetMinimum from fix: preserve fractional scale target minimum #4067, invopop reads minimum as a number so target gets 0.01 straight from the tag
  • removed the old trailing comment on KPAScaleOptions.Target, invopop reads trailing comments too so it would've ended up as the description in the schema

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

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>
@knative-prow knative-prow Bot added the kind/cleanup Cleanup label Nov 30, 2026
@knative-prow

knative-prow Bot commented Nov 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Itx-Psycho0
Once this PR has been reviewed and has the lgtm label, please assign matzew for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added size/XL 🤖 PR changes 500-999 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Nov 30, 2026
@knative-prow

knative-prow Bot commented Nov 30, 2026

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Cleanup needs-ok-to-test 🤖 Needs an org member to approve testing size/XL 🤖 PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move the func.yaml schema generator off the archived alecthomas/jsonschema

1 participant