danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.89k stars 138 forks source link

Bug? Hidden Body field is not recognized by validation #516

Open krisatverbidio opened 1 month ago

krisatverbidio commented 1 month ago

When a body parameter is marked as hidden from the documentation, the validator does not recognize it as a valid field.

Example:

type UpdateAddressInput struct {
    AddressIdPathParam
    Body struct {
        Address1      *string `json:"address1" required:"false"`
        Address2      *string `json:"address2" required:"false"`
        ZipPostalCode *string `json:"zip_postal_code" required:"false"`
        City          *string `json:"city" required:"false"`
        Country       *string `json:"country" required:"false"`
        State         *string `json:"state" required:"false"`

        // App sends over id and address_masked, so we want to just ignore them
        ID            *uuid.UUID `json:"id,omitempty" hidden:"true"` 
        AddressMasked *bool      `json:"address_masked,omitempty" hidden:"true"`
    }
}

However, the endpoint returns a 422:

  "errors": [
    {
      "message": "unexpected property",
      "location": "body.id",
      "value": {
        "address1": "456 Main St",
        "address_masked": true,
        "id": "00000000-0000-0000-0000-000000000000"
      }
    },
    {
      "message": "unexpected property",
      "location": "body.address_masked",
      "value": {
        "address1": "456 Main St",
        "address_masked": true,
        "id": "00000000-0000-0000-0000-000000000000"
      }
    }
  ]