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

Misuse of jsonschema in specs. #884

Closed
suchen-sci opened this issue Dec 28, 2022 · 0 comments
Closed

Misuse of jsonschema in specs. #884

suchen-sci opened this issue Dec 28, 2022 · 0 comments

Comments

@suchen-sci
Copy link
Contributor

suchen-sci commented Dec 28, 2022

Currently, we use jsonschema in Spec this way:

type Spec struct {
    Field1  string  `json:"field1" jsonschema:"required"`
    Field2  string  `json:"field2" jsonschema:"omitempty,enum=1,enum=2"`

We want in our yaml file must contain field1 and may or may not contain field2, if contain field2 it must be one of ["1", "2"].
But in practice, I find write jsonschema in this way not work as expected.

The right way should be like:

type Spec struct {
    Field1  *string  `json:"field1" jsonschema:"required"`
    Field2  string  `json:"field2,omitempty" jsonschema:"omitempty,enum=1,enum=2"`

For fileld1, the reason is simple, field1 is required, and default value of *stirng nil is not acceptable (default value of string "" is acceptable in previous case).

For field2 we need set omitempty in json part too, only in jsonschema part is not good enough.

I think we should consider to update these influenced Specs... Any idea here?

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

2 participants