当前位置: 首页>>代码示例>>Golang>>正文


Golang spec.Load函数代码示例

本文整理汇总了Golang中github.com/aiyi/swagger-gin/spec.Load函数的典型用法代码示例。如果您正苦于以下问题:Golang Load函数的具体用法?Golang Load怎么用?Golang Load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Load函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: opBuilder

func opBuilder(name, fname string) (codeGenOpBuilder, error) {
	if fname == "" {
		fname = "../fixtures/codegen/todolist.simple.yml"
	}

	specDoc, err := spec.Load(fname)
	if err != nil {
		return codeGenOpBuilder{}, err
	}

	op, ok := specDoc.OperationForName(name)
	if !ok {
		return codeGenOpBuilder{}, errors.New("No operation could be found for " + name)
	}

	return codeGenOpBuilder{
		Name:          name,
		APIPackage:    "restapi",
		ModelsPackage: "models",
		Principal:     "models.User",
		Target:        ".",
		Operation:     *op,
		Doc:           specDoc,
		Authed:        false,
		ExtraSchemas:  make(map[string]GenSchema),
	}, nil
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:27,代码来源:operation_test.go

示例2: TestSchemaValidation_StringProps

func TestSchemaValidation_StringProps(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "StringValidations"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			prop := gm.Properties[0]
			if assertValidation(t, "\"name\"", "m.Name", prop) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("string_validations.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "m.validateName(formats", res)
						assertInCode(t, "err := validate.MinLength(\"name\",", res)
						assertInCode(t, "err := validate.MaxLength(\"name\",", res)
						assertInCode(t, "err := validate.Pattern(\"name\",", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:28,代码来源:schemavalidation_test.go

示例3: TestSchemaValidation_Strings

func TestSchemaValidation_Strings(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "NamedString"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			if assertValidation(t, "", "m", gm.GenSchema) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("named_string.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "err := validate.MinLength", res)
						assertInCode(t, "err := validate.MaxLength", res)
						assertInCode(t, "err := validate.Pattern", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:26,代码来源:schemavalidation_test.go

示例4: TestSchemaValidation_NestedMapPropsComplex

func TestSchemaValidation_NestedMapPropsComplex(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "NestedMapComplexValidations"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			prop := gm.Properties[0]
			if assertValidation(t, "\"meta\"", "m.Meta", prop) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("nested_map_complex_validations.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "m.validateMeta(formats", res)
						assertInCode(t, "for k := range m.Meta {", res)
						assertInCode(t, "for kk := range m.Meta[k] {", res)
						assertInCode(t, "for kkk := range m.Meta[k][kk] {", res)
						assertInCode(t, "m.Meta[k][kk][kkk].Validate(formats)", res)
						assertInCode(t, "err := validate.MinLength(\"name\",", res)
						assertInCode(t, "err := validate.MaxLength(\"name\",", res)
						assertInCode(t, "err := validate.Pattern(\"name\",", res)
						assertInCode(t, "err := validate.Minimum(\"age\",", res)
						assertInCode(t, "err := validate.Maximum(\"age\",", res)
						assertInCode(t, "err := validate.MultipleOf(\"age\",", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:35,代码来源:schemavalidation_test.go

示例5: TestSchemaValidation_NamedNestedMap

func TestSchemaValidation_NamedNestedMap(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "NamedNestedMap"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			if assertValidation(t, "", "m", gm.GenSchema) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("named_nested_map.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "for k := range m {", res)
						assertInCode(t, "for kk := range m[k] {", res)
						assertInCode(t, "for kkk := range m[k][kk] {", res)
						assertInCode(t, "err := validate.Minimum(k+\".\"+kk+\".\"+kkk,", res)
						assertInCode(t, "err := validate.Maximum(k+\".\"+kk+\".\"+kkk,", res)
						assertInCode(t, "err := validate.MultipleOf(k+\".\"+kk+\".\"+kkk,", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:29,代码来源:schemavalidation_test.go

示例6: TestSchemaValidation_NamedArrayAdditional

func TestSchemaValidation_NamedArrayAdditional(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "NamedArrayAdditional"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			if assertValidation(t, "", "m", gm.GenSchema) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("named_array_additional.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, k+") validateP0(formats", res)
						assertInCode(t, k+") validateP1(formats", res)
						assertInCode(t, "err := validate.Required(\"0\",", res)
						assertInCode(t, "err := validate.MinLength(\"0\",", res)
						assertInCode(t, "err := validate.MaxLength(\"0\",", res)
						assertInCode(t, "err := validate.Pattern(\"0\",", res)
						assertInCode(t, "err := validate.Required(\"1\",", res)
						assertInCode(t, "err := validate.Minimum(\"1\",", res)
						assertInCode(t, "err := validate.Maximum(\"1\",", res)
						assertInCode(t, "err := validate.MultipleOf(\"1\",", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
						assertInCode(t, "m.NamedArrayAdditionalItems[i]", res)

					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:35,代码来源:schemavalidation_test.go

示例7: TestSchemaValidation_ArrayAdditionalProps

func TestSchemaValidation_ArrayAdditionalProps(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "ArrayAdditionalValidations"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			prop := gm.Properties[0]
			if assertValidation(t, "\"args\"", "m.Args", prop) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("array_additional_validations.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "m.validateArgs(formats", res)
						assertInCode(t, "err := validate.Required(\"P0\",", res)
						assertInCode(t, "err := validate.MinLength(\"P0\",", res)
						assertInCode(t, "err := validate.MaxLength(\"P0\",", res)
						assertInCode(t, "err := validate.Pattern(\"P0\",", res)
						assertInCode(t, "err := validate.Required(\"P1\",", res)
						assertInCode(t, "err := validate.Minimum(\"P1\",", res)
						assertInCode(t, "err := validate.Maximum(\"P1\",", res)
						assertInCode(t, "err := validate.MultipleOf(\"P1\",", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
						assertInCode(t, "m.ArrayAdditionalValidationsArgsTuple0Items[i]", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:34,代码来源:schemavalidation_test.go

示例8: TestSchemaValidation_RequiredProps

func TestSchemaValidation_RequiredProps(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "RequiredProps"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			assert.Len(t, gm.Properties, 6)
			for _, p := range gm.Properties {
				if assert.True(t, p.Required) {
					buf := bytes.NewBuffer(nil)
					err := modelTemplate.Execute(buf, gm)
					if assert.NoError(t, err) {
						formatted, err := formatGoFile("required_props.go", buf.Bytes())
						if assert.NoError(t, err) {
							res := string(formatted)
							assertInCode(t, k+") Validate(formats", res)
							assertInCode(t, "validate"+swag.ToGoName(p.Name), res)
							assertInCode(t, "err := validate.Required", res)
							assertInCode(t, "errors.CompositeValidationError(res...)", res)
						}
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:28,代码来源:schemavalidation_test.go

示例9: TestGenerateModel_WithItemsAndAdditional2

func TestGenerateModel_WithItemsAndAdditional2(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.models.yml")
	if assert.NoError(t, err) {
		definitions := specDoc.Spec().Definitions
		k := "WithItemsAndAdditional2"
		schema := definitions[k]
		genModel, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			assert.Nil(t, genModel.Items)
			assert.True(t, genModel.IsComplexObject)
			prop := getDefinitionProperty(genModel, "tags")
			assert.True(t, prop.IsComplexObject)
			buf := bytes.NewBuffer(nil)
			err := modelTemplate.Execute(buf, genModel)
			if assert.NoError(t, err) {
				b, err := formatGoFile("with_complex_items.go", buf.Bytes())
				if assert.NoError(t, err) {
					res := string(b)
					assertInCode(t, "type "+k+" struct {", res)
					assertInCode(t, "type "+k+"TagsTuple0 struct {", res)
					// this would fail if it accepts additionalItems because it would come out as []interface{}
					assertInCode(t, "P0 string `json:\"-\"`", res)
					assertInCode(t, "Tags "+k+"TagsTuple0 `json:\"tags,omitempty\"`", res)
					assertInCode(t, k+"TagsTuple0Items []int32 `json:\"-\"`", res)

				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:30,代码来源:model_test.go

示例10: TestSchemaValidation_NamedNestedArray

func TestSchemaValidation_NamedNestedArray(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "NamedNestedArray"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			if assertValidation(t, "", "m", gm.GenSchema) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("named_nested_array.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "iNamedNestedArraySize := int64(len(m))", res)
						assertInCode(t, "iiNamedNestedArraySize := int64(len(m[i]))", res)
						assertInCode(t, "iiiNamedNestedArraySize := int64(len(m[i][ii]))", res)
						assertInCode(t, "err := validate.MinItems(\"\"", res)
						assertInCode(t, "err := validate.MaxItems(\"\"", res)
						assertInCode(t, "err := validate.MinItems(strconv.Itoa(i),", res)
						assertInCode(t, "err := validate.MaxItems(strconv.Itoa(i),", res)
						assertInCode(t, "err := validate.MinItems(strconv.Itoa(i)+\".\"+strconv.Itoa(ii),", res)
						assertInCode(t, "err := validate.MaxItems(strconv.Itoa(i)+\".\"+strconv.Itoa(ii),", res)
						assertInCode(t, "err := validate.MinLength(strconv.Itoa(i)+\".\"+strconv.Itoa(ii)+\".\"+strconv.Itoa(iii),", res)
						assertInCode(t, "err := validate.MaxLength(strconv.Itoa(i)+\".\"+strconv.Itoa(ii)+\".\"+strconv.Itoa(iii),", res)
						assertInCode(t, "err := validate.Pattern(strconv.Itoa(i)+\".\"+strconv.Itoa(ii)+\".\"+strconv.Itoa(iii),", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:35,代码来源:schemavalidation_test.go

示例11: TestGenerateModel_WithComplexAdditional

func TestGenerateModel_WithComplexAdditional(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.models.yml")
	if assert.NoError(t, err) {
		definitions := specDoc.Spec().Definitions
		k := "WithComplexAdditional"
		schema := definitions[k]
		genModel, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			assert.Nil(t, genModel.Items)
			assert.True(t, genModel.IsComplexObject)
			prop := getDefinitionProperty(genModel, "tags")
			assert.True(t, prop.IsComplexObject)
			buf := bytes.NewBuffer(nil)
			err := modelTemplate.Execute(buf, genModel)
			if assert.NoError(t, err) {
				b, err := formatGoFile("with_complex_additional.go", buf.Bytes())
				if assert.NoError(t, err) {
					res := string(b)
					assertInCode(t, "type WithComplexAdditional struct {", res)
					assertInCode(t, "type WithComplexAdditionalTagsTuple0 struct {", res)
					assertInCode(t, "Tags WithComplexAdditionalTagsTuple0 `json:\"tags,omitempty\"`", res)
					assertInCode(t, "P0 string `json:\"-\"`", res)
					assertInCode(t, "WithComplexAdditionalTagsTuple0Items []WithComplexAdditionalTagsItems `json:\"-\"`", res)
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:28,代码来源:model_test.go

示例12: TestEnum_MapThing

func TestEnum_MapThing(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
	if assert.NoError(t, err) {
		definitions := specDoc.Spec().Definitions
		k := "MapThing"
		schema := definitions[k]
		genModel, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			buf := bytes.NewBuffer(nil)
			err := modelTemplate.Execute(buf, genModel)
			if assert.NoError(t, err) {
				ff, err := formatGoFile("map_thing.go", buf.Bytes())
				if assert.NoError(t, err) {
					res := string(ff)
					assertInCode(t, "var mapThingEnum []interface{}", res)
					assertInCode(t, k+") validateMapThingEnum(path, location string, value map[string]string)", res)
					assertInCode(t, "m.validateMapThingEnum(\"\", \"body\", m)", res)
					assertInCode(t, "var mapThingValueEnum []interface{}", res)
					assertInCode(t, k+") validateMapThingValueEnum(path, location string, value string)", res)
					assertInCode(t, "m.validateMapThingValueEnum(k, \"body\", m[k])", res)
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:25,代码来源:enum_test.go

示例13: TestEnum_SliceAndAdditionalItemsThing

func TestEnum_SliceAndAdditionalItemsThing(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.enums.yml")
	if assert.NoError(t, err) {
		definitions := specDoc.Spec().Definitions
		k := "SliceAndAdditionalItemsThing"
		schema := definitions[k]
		genModel, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			buf := bytes.NewBuffer(nil)
			err := modelTemplate.Execute(buf, genModel)
			if assert.NoError(t, err) {
				ff, err := formatGoFile("slice_and_additional_items_thing.go", buf.Bytes())
				if assert.NoError(t, err) {
					res := string(ff)
					assertInCode(t, "var sliceAndAdditionalItemsThingEnum []interface{}", res)
					assertInCode(t, k+") validateSliceAndAdditionalItemsThingEnum(path, location string, value SliceAndAdditionalItemsThing)", res)
					//assertInCode(t, "m.validateSliceAndAdditionalItemsThingEnum(\"\", \"body\", m)", res)
					assertInCode(t, "var sliceAndAdditionalItemsThingP0Enum []interface{}", res)
					assertInCode(t, k+") validateP0Enum(path, location string, value string)", res)
					assertInCode(t, "m.validateP0Enum(\"0\", \"body\", m.P0)", res)
					assertInCode(t, "var sliceAndAdditionalItemsThingItemsEnum []interface{}", res)
					assertInCode(t, k+") validateSliceAndAdditionalItemsThingItemsEnum(path, location string, value float32)", res)
					assertInCode(t, "m.validateSliceAndAdditionalItemsThingItemsEnum(strconv.Itoa(i+1), \"body\", m.SliceAndAdditionalItemsThingItems[i])", res)
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:28,代码来源:enum_test.go

示例14: TestSchemaValidation_AllOfProps

func TestSchemaValidation_AllOfProps(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.schemavalidation.yml")
	if assert.NoError(t, err) {
		k := "AllOfValidations"
		schema := specDoc.Spec().Definitions[k]

		gm, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) {
			prop := gm.Properties[0]
			if assertValidation(t, "\"meta\"", "m.Meta", prop) {
				buf := bytes.NewBuffer(nil)
				err := modelTemplate.Execute(buf, gm)
				if assert.NoError(t, err) {
					formatted, err := formatGoFile("all_of_validations.go", buf.Bytes())
					if assert.NoError(t, err) {
						res := string(formatted)
						assertInCode(t, k+") Validate(formats", res)
						assertInCode(t, "m.validateMeta(formats", res)
						assertInCode(t, "validate.MinLength(\"meta\"+\".\"+\"name\",", res)
						assertInCode(t, "validate.Minimum(\"meta\"+\".\"+\"age\",", res)
						assertInCode(t, "validate.MinItems(\"meta\"+\".\"+\"args\",", res)
						assertInCode(t, "validate.MinItems(\"meta\"+\".\"+\"assoc\",", res)
						assertInCode(t, "validate.MinItems(\"meta\"+\".\"+\"assoc\"+\".\"+strconv.Itoa(i),", res)
						assertInCode(t, "validate.MinItems(\"meta\"+\".\"+\"assoc\"+\".\"+strconv.Itoa(i)+\".\"+strconv.Itoa(ii),", res)
						assertInCode(t, "validate.MinLength(\"meta\"+\".\"+\"assoc\"+\".\"+strconv.Itoa(i)+\".\"+strconv.Itoa(ii)+\".\"+strconv.Itoa(iii),", res)
						assertInCode(t, "validate.Minimum(\"meta\"+\".\"+\"opts\"+\".\"+k,", res)
						assertInCode(t, "validate.Minimum(\"meta\"+\".\"+\"extOpts\"+\".\"+k+\".\"+kk+\".\"+kkk,", res)
						assertInCode(t, "validate.MinLength(\"meta\"+\".\"+\"coords\"+\".\"+\"name\",", res)
						assertInCode(t, "errors.CompositeValidationError(res...)", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:35,代码来源:schemavalidation_test.go

示例15: TestGenerateModel_WithTuple

func TestGenerateModel_WithTuple(t *testing.T) {
	specDoc, err := spec.Load("../fixtures/codegen/todolist.models.yml")
	if assert.NoError(t, err) {
		definitions := specDoc.Spec().Definitions
		k := "WithTuple"
		schema := definitions[k]
		genModel, err := makeGenDefinition(k, "models", schema, specDoc)
		if assert.NoError(t, err) && assert.NotEmpty(t, genModel.ExtraSchemas) && assert.NotEmpty(t, genModel.Properties) {
			assert.False(t, genModel.IsTuple)
			assert.True(t, genModel.IsComplexObject)
			assert.False(t, genModel.IsArray)
			assert.False(t, genModel.IsAnonymous)

			sch := genModel.ExtraSchemas[0]
			assert.True(t, sch.IsTuple)
			assert.False(t, sch.IsComplexObject)
			assert.False(t, sch.IsArray)
			assert.False(t, sch.IsAnonymous)
			assert.Equal(t, k+"FlagsTuple0", sch.Name)
			assert.False(t, sch.HasAdditionalItems)
			assert.Nil(t, sch.AdditionalItems)

			prop := genModel.Properties[0]
			assert.False(t, genModel.IsTuple)
			assert.True(t, genModel.IsComplexObject)
			assert.False(t, prop.IsArray)
			assert.False(t, prop.IsAnonymous)
			assert.Equal(t, k+"FlagsTuple0", prop.GoType)
			assert.Equal(t, "flags", prop.Name)
			buf := bytes.NewBuffer(nil)
			err := modelTemplate.Execute(buf, genModel)
			if assert.NoError(t, err) {
				ff, err := formatGoFile("with_tuple.go", buf.Bytes())
				if assert.NoError(t, err) {
					res := string(ff)
					assertInCode(t, "swagger:model "+k+"Flags", res)
					assertInCode(t, "type "+k+"FlagsTuple0 struct {", res)
					assertInCode(t, "P0 int64 `json:\"-\"`", res)
					assertInCode(t, "P1 string `json:\"-\"`", res)
					assertInCode(t, k+"FlagsTuple0) UnmarshalJSON", res)
					assertInCode(t, k+"FlagsTuple0) MarshalJSON", res)
					assertInCode(t, "json.Marshal(data)", res)
					assert.NotRegexp(t, regexp.MustCompile("lastIndex"), res)

					for i, p := range sch.Properties {
						r := "m.P" + strconv.Itoa(i)
						if !p.IsNullable {
							r = "&" + r
						}
						assertInCode(t, "json.Unmarshal(stage1["+strconv.Itoa(i)+"], "+r+")", res)
						assertInCode(t, "P"+strconv.Itoa(i)+",", res)
					}
				}
			}
		}
	}
}
开发者ID:johnqxu,项目名称:swagger-gin,代码行数:57,代码来源:model_test.go


注:本文中的github.com/aiyi/swagger-gin/spec.Load函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。