Bug Report Checklist
Description
The Go code generator currently relies on the outdated gopkg.in/validator.v2 library, which lacks robust validation capabilities—especially for complex regex patterns. As a result, structs generated from OpenAPI specifications with regex-based validation rules often fail to validate correctly.
openapi-generator version
$ npx @openapitools/openapi-generator-cli version
7.14.0
OpenAPI declaration file content or url
Original repo
type: string
pattern: ^(?=.*\S.*)[^\x00-\x08\x0A-\x1f\x7f]{1,255}$
minLength: 1
maxLength: 255
Generation Details
Config:
generatorName: go
additionalProperties:
packageName: notification
withGoMod: false
enumClassPrefix: true
structPrefix: true
Generated result:
import (
"encoding/json"
"fmt"
"gopkg.in/validator.v2" // Generated package contains deprecated lib
)
...
type NotificationOrderItemDTO struct {
OfferId string `json:"offerId" validate:"regexp=^(?=.*\\\\S.*)[^\\\\x00-\\\\x08\\\\x0A-\\\\x1f\\\\x7f]{1,255}$"`
Count int32 `json:"count"`
}
And in UnmarshalJSON we have:
// try to unmarshal data into OrderCancelledNotificationDTO
err = newStrictDecoder(data).Decode(&dst.OrderCancelledNotificationDTO)
if err == nil {
jsonOrderCancelledNotificationDTO, _ := json.Marshal(dst.OrderCancelledNotificationDTO)
if string(jsonOrderCancelledNotificationDTO) == "{}" { // empty struct
dst.OrderCancelledNotificationDTO = nil
} else {
// This fails with: Items[0].OfferId: unknown tag
if err = validator.Validate(dst.OrderCancelledNotificationDTO); err != nil {
// Here we lost error of unknown tag usage and cannot unmarshal right JSON to dedicated struct type
dst.OrderCancelledNotificationDTO = nil
} else {
match++
}
}
} else {
dst.OrderCancelledNotificationDTO = nil
}
Steps to reproduce
git clone https://github.com/yandex-market/yandex-market-notification-api.git
- Use yaml config from Generation Details section above and run:
npx @openapitools/openapi-generator-cli generate \
-c config.yaml \
-i yandex-market-notification-api/openapi/openapi.yaml \
-o client/
- Go to a
client/model_send_notification_request.go file and you will see deprecated library
- Go to a
client/model_notification_order_item_dto.go file and you will see usage of unsupported regexp tag
- Try to unmarshal some vaild JSON, e.g.
{
"campaignId": 123456,
"orderId": 123456,
"items": [
{
"count": 1,
"offerId": "TEST-SKU-1"
}
],
"cancelledAt": "2025-07-29T09:02:46.452Z",
"notificationType": "ORDER_CANCELLED"
}
And the UnmarshalJSON method will get into this branch (even though a completely valid JSON was provided):
else { // no match
return fmt.Errorf("data failed to match schemas in oneOf(SendNotificationRequest)")
}
Related issues/PRs
Suggest a fix
If possible, why not use a more modern validation package like https://github.com/go-playground/validator/ ?
Please correct me, I may have missed some important technical details of this choice.
Thanks.
Bug Report Checklist
Description
The Go code generator currently relies on the outdated gopkg.in/validator.v2 library, which lacks robust validation capabilities—especially for complex regex patterns. As a result, structs generated from OpenAPI specifications with regex-based validation rules often fail to validate correctly.
openapi-generator version
OpenAPI declaration file content or url
Original repo
Generation Details
Config:
Generated result:
And in
UnmarshalJSONwe have:Steps to reproduce
git clone https://github.com/yandex-market/yandex-market-notification-api.gitclient/model_send_notification_request.gofile and you will see deprecated libraryclient/model_notification_order_item_dto.gofile and you will see usage of unsupported regexp tag{ "campaignId": 123456, "orderId": 123456, "items": [ { "count": 1, "offerId": "TEST-SKU-1" } ], "cancelledAt": "2025-07-29T09:02:46.452Z", "notificationType": "ORDER_CANCELLED" }And the
UnmarshalJSONmethod will get into this branch (even though a completely valid JSON was provided):Related issues/PRs
Suggest a fix
If possible, why not use a more modern validation package like https://github.com/go-playground/validator/ ?
Please correct me, I may have missed some important technical details of this choice.
Thanks.