func testCollectionFormat(t *testing.T, param *spec.Parameter, valid bool) {
	binder := &untypedParamBinder{
		parameter: param,
	}
	_, _, err := binder.readValue(url.Values(nil), reflect.ValueOf(nil))
	if valid {
		assert.NoError(t, err)
	} else {
		assert.Error(t, err)
		assert.Equal(t, errors.InvalidCollectionFormat(param.Name, param.In, param.CollectionFormat), err)
	}
}
Exemple #2
0
func (p *untypedParamBinder) readValue(values interface{}, target reflect.Value) ([]string, bool, error) {
	name, in, cf, tpe := p.parameter.Name, p.parameter.In, p.parameter.CollectionFormat, p.parameter.Type
	if tpe == "array" {
		if cf == "multi" {
			if !p.allowsMulti() {
				return nil, false, errors.InvalidCollectionFormat(name, in, cf)
			}
			return values.(url.Values)[name], false, nil
		}

		v := httpkit.ReadSingleValue(values.(httpkit.Gettable), name)
		return p.readFormattedSliceFieldValue(v, target)
	}

	v := httpkit.ReadSingleValue(values.(httpkit.Gettable), name)
	if v == "" {
		return nil, false, nil
	}
	return []string{v}, false, nil
}