Examples of "Flexible schema control with jsonschema-go"? #126
Answered
by
vearutop
RPGillespie6
asked this question in
Q&A
-
|
The readme mentions "Flexible schema control with jsonschema-go" but I can't find a single example of how to utilize such customization with openapi-go. For example, I found this snippet: But I can't figure out how to then make the openapi reflector aware of Apologies of all the new discussions I'm opening, this is a great library! |
Beta Was this translation helpful? Give feedback.
Answered by
vearutop
Jul 11, 2024
Replies: 1 comment 1 reply
-
|
You can add these customizations to r := openapi31.NewReflector()
r.DefaultOptions = append(r.DefaultOptions, jsonschema.InterceptProp(func(params jsonschema.InterceptPropParams) error {
if !params.Processed {
return nil
}
if v, ok := params.Field.Tag.Lookup("validate"); ok {
if strings.Contains(v, "required") {
params.ParentSchema.Required = append(params.ParentSchema.Required, params.Name)
}
}
return nil
})) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
RPGillespie6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can add these customizations to
DefaultOptionsof OpenAPI reflector.