Skip to content

func.yaml schema generator truncates fractional minimum values (e.g. 0.01 -> 0) #4066

Description

@aliok

The func.yaml JSON schema is generated with github.com/alecthomas/jsonschema. Its number-keyword handling stores minimum/maximum as int (Type.Minimum int, reflect.go:60) and parses the tag value with strconv.Atoi — for both the jsonschema tag (numbericKeywords, reflect.go:614) and the jsonschema_extras tag (extraKeywords). A fractional minimum such as 0.01 fails to parse, the error is discarded, and the emitted schema gets minimum: 0.

As a result, schema-based validation is looser than the runtime ValidateScale. For example scale.kpa.target requires >= 0.01 at runtime, but the generated schema only enforces > 0 (via an exclusiveMinimum: true workaround), so a value like 0.001 passes the published schema/func_yaml-schema.json while ValidateScale rejects it at deploy time.

This is a pre-existing, generator-wide limitation affecting any fractional minimum (not specific to the scale fields): the library simply cannot express a non-integer minimum.

Possible fixes

  • Post-process the generated schema in schema/generator/main.go to set fractional minima after reflection (targeted, but per-field).
  • Switch to a jsonschema library / tag path that supports float minima, then regenerate schema/func_yaml-schema.json so schema validation matches ValidateScale.

Context

Surfaced by the Copilot review of #4063:
#4063 (comment)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions