Exemplo n.º 1
0
// YAMLSpec loads a swagger spec document
func YAMLSpec(path string) (*Document, error) {
	data, err := swag.YAMLDoc(path)
	if err != nil {
		return nil, err
	}

	return New(data, "")
}
Exemplo n.º 2
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)
	})
}
Exemplo n.º 3
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)
	})
}