Example #1
0
func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interface{}) {
	specName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
	Convey("verifying "+fixtureType+" YAML fixture "+specName, t, func() {
		b, err := swag.YAMLDoc(fileName)
		So(err, ShouldBeNil)
		Println()
		var expected map[string]interface{}
		err = json.Unmarshal(b, &expected)
		So(err, ShouldBeNil)

		err = json.Unmarshal(b, schema)
		So(err, ShouldBeNil)

		cb, err := json.MarshalIndent(schema, "", "  ")
		So(err, ShouldBeNil)

		var actual map[string]interface{}
		err = json.Unmarshal(cb, &actual)
		So(err, ShouldBeNil)
		So(actual, ShouldBeEquivalentTo, expected)
	})
}
Example #2
0
func TestAdditionalPropertiesWithObject(t *testing.T) {
	schema := new(Schema)
	Convey("verifying model with map with object value", t, func() {
		b, err := swag.YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml")
		So(err, ShouldBeNil)
		Println()

		var expected map[string]interface{}
		err = json.Unmarshal(b, &expected)
		So(err, ShouldBeNil)

		err = json.Unmarshal(b, schema)
		So(err, ShouldBeNil)

		cb, err := json.MarshalIndent(schema, "", "  ")
		So(err, ShouldBeNil)

		var actual map[string]interface{}
		err = json.Unmarshal(cb, &actual)
		So(err, ShouldBeNil)
		So(actual, ShouldBeEquivalentTo, expected)
		pretty.Println(actual)
	})
}