Skip to content

Commit 2451d89

Browse files
committed
Fixes
1 parent 18d3399 commit 2451d89

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Diff for: codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/ValidationGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void generateShapeValidationFunctions(Set<Shape> operationInputShapes, S
9898
writer.openBlock("func $L(v $P) error {", "}", functionName, shapeSymbol, () -> {
9999
writer.addUseImports(GoDependency.SMITHY);
100100
writer.openBlock("if v == nil {", "}", () -> writer.write("return nil"));
101-
writer.write("invalidParams := &smithy.InvalidParamsError{Context: $S}", shapeSymbol.getName());
101+
writer.write("invalidParams := smithy.InvalidParamsError{Context: $S}", shapeSymbol.getName());
102102
switch (shape.getType()) {
103103
case STRUCTURE:
104104
shape.members().forEach(memberShape -> {
@@ -111,7 +111,7 @@ private void generateShapeValidationFunctions(Set<Shape> operationInputShapes, S
111111
if (isEnum) {
112112
writer.write("if len(v.$L) == 0 {", memberName);
113113
} else {
114-
writer.write("if v.$L != nil {", memberName);
114+
writer.write("if v.$L == nil {", memberName);
115115
}
116116
writer.write("invalidParams.Add(smithy.NewErrParamRequired($S))", memberName);
117117
if (hasHelper) {

Diff for: validation.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (e *InvalidParamsError) Add(err InvalidParamError) {
2727
// updated and base context to reflect the merging.
2828
//
2929
// Use for nested validations errors.
30-
func (e *InvalidParamsError) AddNested(nestedCtx string, nested *InvalidParamsError) {
30+
func (e *InvalidParamsError) AddNested(nestedCtx string, nested InvalidParamsError) {
3131
for _, err := range nested.errs {
3232
err.SetContext(e.Context)
3333
err.AddNestedContext(nestedCtx)
@@ -41,7 +41,7 @@ func (e *InvalidParamsError) Len() int {
4141
}
4242

4343
// Error returns the string formatted form of the invalid parameters.
44-
func (e *InvalidParamsError) Error() string {
44+
func (e InvalidParamsError) Error() string {
4545
w := &bytes.Buffer{}
4646
fmt.Fprintf(w, "%d validation error(s) found.\n", len(e.errs))
4747

@@ -53,7 +53,7 @@ func (e *InvalidParamsError) Error() string {
5353
}
5454

5555
// Errs returns a slice of the invalid parameters
56-
func (e *InvalidParamsError) Errs() []error {
56+
func (e InvalidParamsError) Errs() []error {
5757
errs := make([]error, len(e.errs))
5858
for i := 0; i < len(errs); i++ {
5959
errs[i] = e.errs[i]
@@ -84,16 +84,18 @@ type invalidParamError struct {
8484
}
8585

8686
// Error returns the string version of the invalid parameter error.
87-
func (e *invalidParamError) Error() string {
87+
func (e invalidParamError) Error() string {
8888
return fmt.Sprintf("%s, %s.", e.reason, e.Field())
8989
}
9090

9191
// Field Returns the field and context the error occurred.
92-
func (e *invalidParamError) Field() string {
92+
func (e invalidParamError) Field() string {
9393
sb := &strings.Builder{}
94-
sb.WriteString(e.field)
94+
sb.WriteString(e.context)
9595
if sb.Len() > 0 {
96-
sb.WriteRune('.')
96+
if len(e.nestedContext) == 0 || (len(e.nestedContext) > 0 && e.nestedContext[:1] != "[") {
97+
sb.WriteRune('.')
98+
}
9799
}
98100
if len(e.nestedContext) > 0 {
99101
sb.WriteString(e.nestedContext)

0 commit comments

Comments
 (0)