swaggest / openapi-go

OpenAPI structures for Go
https://pkg.go.dev/github.com/swaggest/openapi-go/openapi3
MIT License
248 stars 23 forks source link

How would you set a field as required? #40

Closed AdamJSoftware closed 2 years ago

AdamJSoftware commented 2 years ago

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 commented 2 years ago

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

vearutop commented 2 years ago

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 commented 2 years ago

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