Skip to content

FormData validation not working #232

@dmlambea

Description

@dmlambea

Describe the bug
Schema validation tags (like "required") are not being taken into account for "formData" fields. Validation is not being performed.

To Reproduce
Please run a server with: https://go.dev/play/p/IJ3IkfC3VxQ

My go.mod is:

module rest_example

go 1.23.1

require (
        github.com/go-chi/chi/v5 v5.2.1
        github.com/google/uuid v1.6.0
        github.com/swaggest/jsonschema-go v0.3.78
        github.com/swaggest/rest v0.2.74
        github.com/swaggest/usecase v1.3.1
)

require (
        github.com/cespare/xxhash/v2 v2.3.0 // indirect
        github.com/santhosh-tekuri/jsonschema/v3 v3.1.0 // indirect
        github.com/swaggest/form/v5 v5.1.1 // indirect
        github.com/swaggest/openapi-go v0.2.57 // indirect
        github.com/swaggest/refl v1.4.0 // indirect
        gopkg.in/yaml.v2 v2.4.0 // indirect
)

Test the code using cURL, with the field "desc" intentionally empty:

curl -v 'http://localhost:8080/example' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Content-Type: multipart/form-data; boundary=----ExampleFormBoundary' \
  --data-raw $'------ExampleFormBoundary\r\nContent-Disposition: form-data; name="name"\r\n\r\nExample name\r\n------ExampleFormBoundary\r\nContent-Disposition: form-data; name="desc"\r\n\r\n\r\n------ExampleFormBoundary\r\nContent-Disposition: form-data; name="contact"\r\n\r\nFAX\r\n------ExampleFormBoundary\r\nContent-Disposition: form-data; name="extras"\r\n\r\n[{"reqID":"01976449-06ef-7317-af95-5643608b7d70","serverTimestamp":"2025-06-12T13:16:36Z"}]\r\n------ExampleFormBoundary\r\n'

Expected behavior
cURL should show a bad request (HTTP Status 400) because field "desc" is not being populated.

Side note: field "extras" is not being populated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions