Esempio n. 1
0
func setSchemaType(s *spec.Schema, f *descriptor.Field) {
	if f.GetLabel() == godesc.FieldDescriptorProto_LABEL_REPEATED {
		s.Type = spec.StringOrArray([]string{"array"})

		items := new(spec.Schema)
		if f.GetType() == godesc.FieldDescriptorProto_TYPE_MESSAGE {
			items.Ref = messageRef(f.Message)
		} else {
			ty, format := toSwaggerType(f.GetType())
			items.Type = spec.StringOrArray([]string{ty})
			items.Format = format
		}

		s.Items = &spec.SchemaOrArray{Schema: items}
		return
	}

	if f.GetType() == godesc.FieldDescriptorProto_TYPE_MESSAGE {
		s.Ref = messageRef(f.Message)
		return
	}

	ty, format := toSwaggerType(f.GetType())
	s.Type = spec.StringOrArray([]string{ty})
	s.Format = format
}
Esempio n. 2
0
func TestTypeResolver_AdditionalItems(t *testing.T) {
	_, resolver, err := basicTaskListResolver(t)
	tpe := spec.StringProperty()
	if assert.NoError(t, err) {
		// arrays of primitives and string formats with additional formats
		for _, val := range schTypeVals {
			var sch spec.Schema
			sch.Typed(val.Type, val.Format)
			var coll spec.Schema
			coll.Type = []string{"array"}
			coll.Items = new(spec.SchemaOrArray)
			coll.Items.Schema = tpe
			coll.AdditionalItems = new(spec.SchemaOrBool)
			coll.AdditionalItems.Schema = &sch

			rt, err := resolver.ResolveSchema(&coll, true)
			if assert.NoError(t, err) && assert.True(t, rt.IsArray) {
				assert.True(t, rt.HasAdditionalItems)
				assert.False(t, rt.IsNullable)
				//if assert.NotNil(t, rt.ElementType) {
				//assertPrimitiveResolve(t, "string", "", "string", *rt.ElementType)
				//}
			}
		}
	}
}