Skip to content

Commit f921602

Browse files
authored
Add form struct tag for x-www-form-urlencoded request schemas (#1000)
1 parent afac8ae commit f921602

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/codegen/operations.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,17 @@ func GenerateBodyDefinitions(operationID string, bodyOrRef *openapi3.RequestBody
663663
// type under #/components, we'll define a type for it, so
664664
// that we have an easy to use type for marshaling.
665665
if bodySchema.RefType == "" {
666+
if contentType == "application/x-www-form-urlencoded" {
667+
// Apply the appropriate structure tag if the request
668+
// schema was defined under the operations' section.
669+
for i := range bodySchema.Properties {
670+
bodySchema.Properties[i].NeedsFormTag = true
671+
}
672+
673+
// Regenerate the Golang struct adding the new form tag.
674+
bodySchema.GoType = GenStructFromSchema(bodySchema)
675+
}
676+
666677
td := TypeDefinition{
667678
TypeName: bodyTypeName,
668679
Schema: bodySchema,

0 commit comments

Comments
 (0)