Exemple #1
0
func TestTypeDetectionInvalidItems(t *testing.T) {
	withoutItems := spec.QueryParam("without").CollectionOf(nil, "")
	binder := &untypedParamBinder{
		Name:      "without",
		parameter: withoutItems,
	}
	assert.Nil(t, binder.Type())

	items := new(spec.Items)
	items.Type = "array"
	withInvalidItems := spec.QueryParam("invalidItems").CollectionOf(items, "")
	binder = &untypedParamBinder{
		Name:      "invalidItems",
		parameter: withInvalidItems,
	}
	assert.Nil(t, binder.Type())

	noType := spec.QueryParam("invalidType")
	noType.Type = "invalid"
	binder = &untypedParamBinder{
		Name:      "invalidType",
		parameter: noType,
	}
	assert.Nil(t, binder.Type())
}
Exemple #2
0
func setParameterType(s *spec.Parameter, f *descriptor.Field) {
	if f.GetLabel() == godesc.FieldDescriptorProto_LABEL_REPEATED {
		s.Type = "array"
		items := new(spec.Items)
		if f.GetType() == godesc.FieldDescriptorProto_TYPE_MESSAGE {
			items.Ref = spec.MustCreateRef("#/definitions/" + f.GetTypeName())
		} else {
			ty, format := toSwaggerType(f.GetType())
			items.Type = ty
			items.Format = format
		}

		s.Items = items
		return
	}

	if f.GetType() == godesc.FieldDescriptorProto_TYPE_MESSAGE {
		s.Ref = spec.MustCreateRef("#/definitions/" + f.GetTypeName())
		return
	}

	ty, format := toSwaggerType(f.GetType())
	s.Type = ty
	s.Format = format
}