oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

feat: add config to emit `required:"true"` field tag

Open xobotyi opened this issue 2 years ago • 3 comments

It is handy for cases when openapi spec is generated from sources and source's types reuses types generated from other openapi spec.

xobotyi avatar Sep 13 '22 19:09 xobotyi

type StructuresProject struct {
	CreatedAt  int                   `json:"createdAt" required:"true"`
	CreatorID  string                `json:"creatorID" required:"true"`
	Deleted    bool                  `json:"deleted" required:"true"`
}

We use https://github.com/swaggest/openapi-go to generate schemas from the code

xobotyi avatar Oct 03 '22 11:10 xobotyi

So, basically, we use spec generation from internal types, and generates public client and types from generated spec. Then, other service tries to reuse type generated from spec, but it generated spec it turns optional field since has no required:"true" tag

xobotyi avatar Oct 31 '22 10:10 xobotyi

As for now we're using patched fork but really want to jump back to main package to avoid mess with merging your updates.

xobotyi avatar Oct 31 '22 10:10 xobotyi

In the end I've managed to make a hook for spec-generator and it utilizes x-oapi-codegen-extra-tags to achieve same functionality.

xobotyi avatar Nov 06 '23 16:11 xobotyi