Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid double checking if a tagged int string like !!int '${variable} is actually an integer #1048

Open
kevinvalk opened this issue Aug 24, 2024 · 0 comments

Comments

@kevinvalk
Copy link

kevinvalk commented Aug 24, 2024

Is your enhancement related to a problem? Please describe.

I am extensively using Flux2 for Kubernetes GitOps deployments. They support variable substitution in YAML files as shown in https://fluxcd.io/flux/components/kustomize/kustomizations/#post-build-variable-substitution In essence, they just preprocess all YAML files and replace any ${variable_name} with whatever you have defined. However, when combining this with schema validation, whenever you use variables that require integers, numbers, etc break.

Given the following scheme

{
  "type": "object",
  "properties": {
    "string": {
      "type": "string"
    },
    "integer": {
      "type": "integer"
    }
  }
}

This obviously works

string: '1'
integer: 1

This also works nicely

string: !!str 1
integer: !!int '1'

But for the integer case, this does not work and will still throw an integer type error!

string: !!str '${asd}'
integer: !!int '${variable_that_turns_in_an_int}'

Describe the solution you would like

I think it makes sense that if you perform a manual cast like !!int the scheme validation system should simply accept that whatever follows is an integer. Not also try to cast it to an integer itself and if that fails, throw a type error.

Describe alternatives you have considered

I see no alternatives to fix this problem.

Additional context

The question is, could this be a breaking change as now in theory when you write !!int, there is no actual validation performed anymore on the string value (if it can be converted to an int). My personal opinion is that whenever you add a tag, you perform an explicit cast and don't care about more type checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant