-
Notifications
You must be signed in to change notification settings - Fork 40
kedge does not fail when extra fields specified #168
Comments
This is not going to be easy thing to solve :( |
If it would have been But with There are lot of manual ways to handle it like the following which is influenced from stackoverflow question. package main
import (
"encoding/json"
"fmt"
)
type Foo struct {
A int `json:"a"`
B int `json:"b"`
X map[string]interface{} `json:"-"` // Rest of the fields should go here.
}
func main() {
s := `{"a":1, "b":2, "x":1, "y":1}`
f := Foo{}
if err := json.Unmarshal([]byte(s), &f); err != nil {
panic(err)
}
// 'f' has:
// {A:1 B:2 X:map[]}
if err := json.Unmarshal([]byte(s), &f.X); err != nil {
panic(err)
}
// 'f' has:
// {A:1 B:2 X:map[a:1 b:2 x:1 y:1]}
// now manually delete fields we know are valid from
// 'X' which is 'a' and 'b'
delete(f.X, "a")
delete(f.X, "b")
// 'f' has:
// {A:1 B:2 X:map[x:1 y:1]}
} I am not sure if wanna do it this way. Also there is an open issue in golang upstream for adding support to json tags to find the extra fields golang/go#15314 . When I was working on opencompose health feature redhat-developer/opencompose#143 I came across this problem so we(me and @kadel) decided that we won't do extra fields checks for |
@surajssd @kadel , I am trying to do it with Jsonschema and gojsonschema,
|
fwiw, @surajnarwade and I sat down brainstorming this issue last week, and we're 90% there, some code remains. |
Is there any progress on this? |
@surajnarwade let me know whenever you have time, we can sit and finish this off |
@surajnarwade are you working on this? What is progress? |
@surajnarwade can you try whatever you are doing with the jsonschema at https://github.com/kedgeproject/kedge-jsonschema/blob/master/configs/deploymentspecmod.json |
the link is not valid |
@kadel this should work https://github.com/kedgeproject/json-schema/blob/master/schema/deploymentspecmod.json Today I separated the configs/schema from the schema generator! |
I'm confused from content of that directory :-( |
@kadel not sure yet so keeping them! |
@surajssd @surajnarwade correct me if I'm wrong, but the JSON schema is not helping here, right? Is this because Kubernetes does not support this? During demos, I've come across this multiple times since extra fields are not caught, bumping priority. |
Related PR #192 |
how is this blocked on kubeval? |
ping @surajnarwade
we could validate using reflect magic on golang structs, but I'm not aware of anything to validate against the JSON schema. |
Why we can't use one of those?: There is even talk about it from one really smart guy https://www.slideshare.net/surajssd009005/jsonschema-with-golang ? Or Am I missing something? |
LOL 🙈 @surajnarwade told the library has some additional checks wrt kubernetes and openshift specifically! |
@surajssd @containscafeine @kadel , once instrumenta/openapi2jsonschema#4 gets solved, we are ready to sort out this issue. |
Problem is not with |
Can we somehow create a workaround for it? Can we inject |
It means that it will validate extra keys that are in deeper levels, just root level's won't be validated?
There was no movement in the upstream repo. If it doesn't change maybe we should fork and fix it ourselves. |
it seems there's some problem with JSON schema, they are reported here |
any progress on this? |
We should validate it automatically by default, and have flag for disabling it if needed. We need to work on stabilizing it. |
Closing this Since #481 got merged |
I have an extra field in my kedge definition -
Running
kedge generate
on this file does not fail and simply ignores the extra field, while it should have failed saying something likeunknown field 'batman' passed as input
This creates a lot of room for error since a simple spelling mistake in the spec will render the generated artifacts useless and the user will never get to know about it.
The text was updated successfully, but these errors were encountered: