Skip to content

Commit c22f407

Browse files
authored
Merge branch 'v3' into dependabot/go_modules/google.golang.org/protobuf-1.36.5
2 parents 3618008 + fc0dd51 commit c22f407

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ specification and a client tool.
269269

270270
## 3. Run
271271

272-
Now let's compile and run the service:
272+
First let's make sure that all package dependencies are downloaded:
273+
274+
```bash
275+
go mod tidy
276+
```
277+
278+
Next, let's compile and run the service:
273279

274280
```bash
275281
cd cmd/calc

http/codegen/server_types_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestServerTypes(t *testing.T) {
3232
{"server-query-custom-name", testdata.PayloadQueryCustomNameDSL, QueryCustomNameServerTypesFile},
3333
{"server-header-custom-name", testdata.PayloadHeaderCustomNameDSL, HeaderCustomNameServerTypesFile},
3434
{"server-cookie-custom-name", testdata.PayloadCookieCustomNameDSL, CookieCustomNameServerTypesFile},
35+
{"server-payload-with-validated-alias", testdata.PayloadWithValidatedAliasDSL, PayloadWithValidatedAliasServerTypeCode},
3536
}
3637
for _, c := range cases {
3738
t.Run(c.Name, func(t *testing.T) {
@@ -380,3 +381,39 @@ func NewMethodCookieCustomNamePayload(c2 *string) *servicecookiecustomname.Metho
380381
return v
381382
}
382383
`
384+
385+
const PayloadWithValidatedAliasServerTypeCode = `// MethodStreamingBody is the type of the "ServicePayloadValidatedAlias"
386+
// service "Method" endpoint HTTP request body.
387+
type MethodStreamingBody struct {
388+
Name *ValidatedStringStreamingBody ` + "`" + `form:"name,omitempty" json:"name,omitempty" xml:"name,omitempty"` + "`" + `
389+
}
390+
391+
// ValidatedStringStreamingBody is used to define fields on request body types.
392+
type ValidatedStringStreamingBody string
393+
394+
// NewMethodStreamingBody builds a ServicePayloadValidatedAlias service Method
395+
// endpoint payload.
396+
func NewMethodStreamingBody(body *MethodStreamingBody) *servicepayloadvalidatedalias.MethodStreamingPayload {
397+
v := &servicepayloadvalidatedalias.MethodStreamingPayload{}
398+
if body.Name != nil {
399+
name := servicepayloadvalidatedalias.ValidatedString(*body.Name)
400+
v.Name = &name
401+
}
402+
403+
return v
404+
}
405+
406+
// ValidateMethodStreamingBody runs the validations defined on
407+
// MethodStreamingBody
408+
func ValidateMethodStreamingBody(body *MethodStreamingBody) (err error) {
409+
if body.Name != nil {
410+
err = goa.MergeErrors(err, goa.ValidatePattern("body.name", string(*body.Name), "^[a-zA-Z]+$"))
411+
}
412+
if body.Name != nil {
413+
if utf8.RuneCountInString(string(*body.Name)) < 10 {
414+
err = goa.MergeErrors(err, goa.InvalidLengthError("body.name", string(*body.Name), utf8.RuneCountInString(string(*body.Name)), 10, true))
415+
}
416+
}
417+
return
418+
}
419+
`

http/codegen/service_data.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2586,9 +2586,10 @@ func attributeTypeData(ut expr.UserType, req, ptr, server bool, rd *ServiceData)
25862586
ctx = "response"
25872587
}
25882588
desc = name + " is used to define fields on " + ctx + " body types."
2589-
if req || !req && !server {
2590-
// generate validations for responses client-side and for
2591-
// requests server-side and CLI
2589+
if (req || !req && !server) && !expr.IsAlias(ut) {
2590+
// Generate validations for responses client-side and for
2591+
// requests server-side and CLI.
2592+
// Alias types are validated inline in the parent type
25922593
validate = codegen.ValidationCode(ut.Attribute(), ut, hctx, true, expr.IsAlias(ut), false, "body")
25932594
}
25942595
if validate != "" {

http/codegen/testdata/payload_dsls.go

+18
Original file line numberDiff line numberDiff line change
@@ -3648,3 +3648,21 @@ var PayloadCookieCustomNameDSL = func() {
36483648
})
36493649
})
36503650
}
3651+
3652+
var PayloadWithValidatedAliasDSL = func() {
3653+
var ValidatedString = Type("ValidatedString", String, func() {
3654+
MinLength(10)
3655+
Pattern("^[a-zA-Z]+$")
3656+
})
3657+
3658+
Service("ServicePayloadValidatedAlias", func() {
3659+
Method("Method", func() {
3660+
StreamingPayload(func() {
3661+
Attribute("name", ValidatedString)
3662+
})
3663+
HTTP(func() {
3664+
GET("/")
3665+
})
3666+
})
3667+
})
3668+
}

0 commit comments

Comments
 (0)