openapi-go icon indicating copy to clipboard operation
openapi-go copied to clipboard

How to use custom x- tags in a schema

Open tpl996 opened this issue 2 years ago • 2 comments

If a schema like

components: schemas: CreateSomethingRequest: type: object required: - something properties: something: type: number example: 1 x-oapi-codegen-extra-tags: validate: gte=0

was required, how can this x-oapi-codegen-extra-tags field be specified?

tpl996 avatar Feb 20 '23 09:02 tpl996

Types that allow custom extensions (x-), usually have a WithMapOfAnythingItem method available (like this).

vearutop avatar Feb 20 '23 10:02 vearutop

perfect - thank you for the prompt response

tpl996 avatar Feb 20 '23 11:02 tpl996

For openapi31 operations you would do:

oc, err := reflector.NewOperationContext(http.MethodGet, "/api/v4/endpoint/{id}")
oc.(openapi31.OperationExposer).Operation().WithMapOfAnythingItem("x-api-name", "getEndpointByID")

RPGillespie6 avatar May 22 '24 23:05 RPGillespie6