Skip to content

Commit

Permalink
fixed 065_encode_struct case
Browse files Browse the repository at this point in the history
  • Loading branch information
gopherus committed Jun 12, 2024
1 parent e7f1bd0 commit d5f129d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion e2e/local/regression/cases/065_encode_struct/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pipeline:
action: http/runner:send
requests:
- Method: GET
URL: 'http://127.0.0.1:8080/v1/api/dev/vendors-check?ids=[2/101/2]'
URL: 'http://127.0.0.1:8080/v1/api/dev/vendors-check?ids=2/101/2,2/101/2'
Expect:
JSONBody: $LoadJSON('${parentPath}/expect.json')

4 changes: 3 additions & 1 deletion internal/translator/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ func (s *Service) adjustCodecType(parameter *state.Parameter, types *xreflect.Ty
output.Schema.Name = name
output.Schema.Package = pkg
output.Schema.DataType = name
output.Schema.Cardinality = parameter.Schema.Cardinality
if parameter.Schema.Cardinality == state.Many {
output.Schema.Cardinality = parameter.Schema.Cardinality
}
case codec.KeyFirebaseAuth:
if len(output.Args) < 2 {
return fmt.Errorf("%v invalid arguments count", output.Name)
Expand Down
8 changes: 8 additions & 0 deletions view/state/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ func BuildSchema(field *reflect.StructField, pTag *tags.Parameter, result *Param
lookupType = extension.Config.Types.Lookup
}
rawType := field.Type
isSlice := false
if rawType.Kind() == reflect.Slice {
isSlice = true
rawType = rawType.Elem()
}
if rawType.Kind() == reflect.Ptr {
Expand All @@ -248,10 +250,16 @@ func BuildSchema(field *reflect.StructField, pTag *tags.Parameter, result *Param
rawName := rawType.Name()
if pTag.DataType != "" {
result.Schema = &Schema{Name: pTag.DataType}
if isSlice {
result.Schema.Cardinality = Many
}
if result.Output == nil {
result.Schema.SetType(field.Type)
} else if result.Output.Schema == nil {
result.Output.Schema = &Schema{}
if isSlice {
result.Output.Schema.Cardinality = Many
}
result.Output.Schema.SetType(field.Type)
setter.SetStringIfEmpty(&result.Output.Schema.DataType, rawName)
}
Expand Down

0 comments on commit d5f129d

Please sign in to comment.