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

How would you set a field as required? #40

Closed
AdamJSoftware opened this issue Aug 6, 2022 · 3 comments
Closed

How would you set a field as required? #40

AdamJSoftware opened this issue Aug 6, 2022 · 3 comments

Comments

@AdamJSoftware
Copy link

I can see that path automatically gets the required property, but what about other fields? Is there any required/not_nullable tag that can be used?

I tried looking through the documentation but I don't really see anything that can help me with this.

@AdamJSoftware
Copy link
Author

I've tried using the validate tag but it seems to do nothing for some reason

@vearutop
Copy link
Member

vearutop commented Aug 6, 2022

openapi-go uses github.com/swaggest/jsonschema-go to reflect JSON schema, please check https://github.com/swaggest/jsonschema-go#field-tags for more details on supported field tags.

In your case you need to add required:"true" to the required field.

type MyStruct struct {
 Foo int `json:"foo" required:"true"`
}

@AdamJSoftware
Copy link
Author

Yep that fixes my problems! Was looking at the wrong jsonschema go project!

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