Skip to content

Commit 2abbc33

Browse files
committed
Revamp body validation and fix diagnostic drops + CHANGELOG update
1 parent e955afb commit 2abbc33

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

changelog/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ Previously, alias support was limited and resulted in the aliased type effective
8282
* Added a global `ApiValidator` as the entry point to the HIR validation subsystem.</br>
8383
This currently includes a URL conflict detection algorithm to emit diagnostics upon route conflicts such as between `POST /a/b/c` and `POST /a/{foo}/c`
8484

85+
* Added an explicit visitor error when using interfaces in general and `interface{}` in particular
86+
87+
* Added a validation error when passing arrays via inputs that do not accept them (i.e., a URL parameter)
88+
89+
90+
### Bugfixes
91+
92+
* Fixed array/slice support. Previously resulted in broken generated code
93+
94+
* Fixed cases where model fields were named after the type rather than the field name or JSON tag
95+
96+
* Fixed an issue where `any` yielded an `object` schema entity rather than a 'map-like' one, i.e.,
97+
```json
98+
"someField": {
99+
"additionalProperties": {
100+
"type": "object"
101+
},
102+
"type": "object"
103+
}
104+
```
85105

86106
------------------
87107

core/validators/receiver.validator.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (v ReceiverValidator) validateParams(receiver *metadata.ReceiverMeta) ([]di
9191
return diags, err
9292
}
9393

94-
common.AppendIfNotNil(diags, diag)
94+
diags = common.AppendIfNotNil(diags, diag)
9595
if passedIn == nil {
9696
// If we couldn't process the passedIn portion, no reason in continuing.
9797
// An error or error diagnostic will have been added, at this point.
@@ -100,12 +100,12 @@ func (v ReceiverValidator) validateParams(receiver *metadata.ReceiverMeta) ([]di
100100

101101
switch *passedIn {
102102
case definitions.PassedInBody:
103-
common.AppendIfNotNil(diags, v.validateBodyParam(receiver, param))
103+
diags = common.AppendIfNotNil(diags, v.validateBodyParam(receiver, param))
104104
default:
105-
common.AppendIfNotNil(diags, v.validateNonBodyParam(receiver, param, *passedIn))
105+
diags = common.AppendIfNotNil(diags, v.validateNonBodyParam(receiver, param, *passedIn))
106106
}
107107

108-
common.AppendIfNotNil(diags, v.validateParamsCombinations(processedParams, param, *passedIn))
108+
diags = common.AppendIfNotNil(diags, v.validateParamsCombinations(processedParams, param, *passedIn))
109109

110110
processedParams = append(processedParams, funcParamEx{FuncParam: param, PassedIn: *passedIn})
111111
}
@@ -155,21 +155,15 @@ func (v ReceiverValidator) validateBodyParam(
155155
receiver *metadata.ReceiverMeta,
156156
param metadata.FuncParam,
157157
) *diagnostics.ResolvedDiagnostic {
158-
// Verify the body is a struct
159-
if param.SymbolKind != common.SymKindStruct {
160-
nameInSchema, err := metadata.GetParameterSchemaName(param.Name, param.Annotations)
161-
if err != nil {
162-
nameInSchema = "unknown"
163-
}
164-
158+
// Verify the body is not a built-in
159+
if param.Type.SymbolKind.IsBuiltin() {
165160
diag := diagnostics.NewErrorDiagnostic(
166161
receiver.Annotations.FileName(),
167162
fmt.Sprintf(
168-
"body parameters must be structs but '%s' (schema name '%s', type '%s') is of kind '%s'",
163+
"body parameter '%s' (schema name '%s', type '%s') is a built-in primitive or special (e.g. time.Time) which is not allowed",
169164
param.Name,
170-
nameInSchema,
165+
getParamSchemaNameOrFallback(param, "unknown"),
171166
param.Type.Name,
172-
param.Type.SymbolKind,
173167
),
174168
diagnostics.DiagReceiverInvalidBody,
175169
param.Range,

0 commit comments

Comments
 (0)