當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Schema.Default方法代碼示例

本文整理匯總了Golang中github.com/go-openapi/spec.Schema.Default方法的典型用法代碼示例。如果您正苦於以下問題:Golang Schema.Default方法的具體用法?Golang Schema.Default怎麽用?Golang Schema.Default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/go-openapi/spec.Schema的用法示例。


在下文中一共展示了Schema.Default方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: assertBuiltinSliceElem

func assertBuiltinSliceElem(t testing.TB, resolver *typeResolver, aliased bool, i int, val builtinVal) bool {
	val.Nullable = false
	if nullableExtension(val.Extensions) != nil {
		val.Nullable = *nullableExtension(val.Extensions)
	}
	sliceType := "[]" + val.Expected
	if val.Nullable {
		sliceType = "[]*" + val.Expected
	}
	val.Expected = sliceType

	val.Aliased = aliased
	if aliased {
		val.AliasedType = val.Expected
		val.Expected = "models.MyAliasedThing"
	}

	// fmt.Println("nullable:", val.Nullable)
	items := new(spec.Schema)
	items.Typed(val.Type, val.Format)
	items.Default = val.Default
	items.ReadOnly = val.ReadOnly
	items.Extensions = val.Extensions
	items.Minimum = val.Minimum
	items.Maximum = val.Maximum
	items.MultipleOf = val.MultipleOf
	items.MinLength = val.MinLength
	items.MaxLength = val.MaxLength

	sch := spec.ArrayProperty(items)

	rt, err := resolver.ResolveSchema(sch, !aliased, val.Required)
	if assert.NoError(t, err) {

		if val.Nullable {
			if !assert.True(t, rt.ElemType.IsNullable, "expected nullable for item at: %d", i) {
				return false
			}
		} else {
			if !assert.False(t, rt.ElemType != nil && rt.ElemType.IsNullable, "expected not nullable for item at: %d", i) {
				return false
			}
		}

		if val.Aliased {
			if !assert.Equal(t, val.Aliased, rt.IsAliased, "expected (%q, %q) to be an aliased type at: %d", val.Type, val.Format, i) {
				return false
			}
			if !assert.Equal(t, val.AliasedType, rt.AliasedType, "expected %q (%q, %q) to be aliased as %q, but got %q at %d", val.Expected, val.Type, val.Format, val.AliasedType, rt.AliasedType, i) {
				return false
			}
		}

		if !assertBuiltinSliceElemnResolve(t, val.Type, val.Format, val.Expected, rt, i) {
			return false
		}
	}
	return true
}
開發者ID:Cl0udPhish,項目名稱:go-swagger,代碼行數:59,代碼來源:pointer_test.go

示例2: assertBuiltinVal

func assertBuiltinVal(t testing.TB, resolver *typeResolver, aliased bool, i int, val builtinVal) bool {
	val.Aliased = aliased
	if aliased {
		val.AliasedType = val.Expected
		val.Expected = "models.MyAliasedThing"
	}

	sch := new(spec.Schema)
	sch.Typed(val.Type, val.Format)
	sch.Default = val.Default
	sch.ReadOnly = val.ReadOnly
	sch.Extensions = val.Extensions
	sch.Minimum = val.Minimum
	sch.Maximum = val.Maximum
	sch.MultipleOf = val.MultipleOf
	sch.MinLength = val.MinLength
	sch.MaxLength = val.MaxLength

	rt, err := resolver.ResolveSchema(sch, !aliased, val.Required)
	if assert.NoError(t, err) {
		if val.Nullable {
			if !assert.True(t, rt.IsNullable, "expected nullable for item at: %d", i) {
				// fmt.Println("isRequired:", val.Required)
				// pretty.Println(sch)
				return false
			}
		} else {
			if !assert.False(t, rt.IsNullable, "expected not nullable for item at: %d", i) {
				// fmt.Println("isRequired:", val.Required)
				// pretty.Println(sch)
				return false
			}
		}
		if !assert.Equal(t, val.Aliased, rt.IsAliased, "expected (%q, %q) to be an aliased type", val.Type, val.Format) {
			return false
		}
		if val.Aliased {
			if !assert.Equal(t, val.AliasedType, rt.AliasedType, "expected %q (%q, %q) to be aliased as %q, but got %q", val.Expected, val.Type, val.Format, val.AliasedType, rt.AliasedType) {
				return false
			}
		}
		if !assertBuiltinResolve(t, val.Type, val.Format, val.Expected, rt, i) {
			return false
		}
	}
	return true
}
開發者ID:Cl0udPhish,項目名稱:go-swagger,代碼行數:47,代碼來源:pointer_test.go


注:本文中的github.com/go-openapi/spec.Schema.Default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。