From 5ce5536ea140f477b0d406a21206965fac7bef74 Mon Sep 17 00:00:00 2001 From: Ivan Pushkin Date: Sat, 11 Mar 2023 19:02:10 +0100 Subject: [PATCH] Add form struct tag for x-www-form-urlencoded request schemas --- pkg/codegen/operations.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/codegen/operations.go b/pkg/codegen/operations.go index 7de40d61cc..28b991f904 100644 --- a/pkg/codegen/operations.go +++ b/pkg/codegen/operations.go @@ -663,6 +663,17 @@ func GenerateBodyDefinitions(operationID string, bodyOrRef *openapi3.RequestBody // type under #/components, we'll define a type for it, so // that we have an easy to use type for marshaling. if bodySchema.RefType == "" { + if contentType == "application/x-www-form-urlencoded" { + // Apply the appropriate structure tag if the request + // schema was defined under the operations' section. + for i := range bodySchema.Properties { + bodySchema.Properties[i].NeedsFormTag = true + } + + // Regenerate the Golang struct adding the new form tag. + bodySchema.GoType = GenStructFromSchema(bodySchema) + } + td := TypeDefinition{ TypeName: bodyTypeName, Schema: bodySchema,