func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interface{}) bool { specName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) t.Logf("verifying %s YAML fixture %q", fixtureType, specName) b, err := swag.YAMLDoc(fileName) if !assert.NoError(t, err) { return false } var expected map[string]interface{} if !assert.NoError(t, json.Unmarshal(b, &expected)) { return false } if !assert.NoError(t, json.Unmarshal(b, schema)) { return false } cb, err := json.MarshalIndent(schema, "", " ") if !assert.NoError(t, err) { return false } var actual map[string]interface{} if !assert.NoError(t, json.Unmarshal(cb, &actual)) { return false } return assert.EqualValues(t, expected, actual) }
// 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, "") }
func TestCircularSpecExpansion(t *testing.T) { doc, err := swag.YAMLDoc("../fixtures/expansion/circularSpec.yaml") assert.NoError(t, err) spec := new(Swagger) err = json.Unmarshal(doc, spec) assert.NoError(t, err) assert.NotPanics(t, func() { err = expandSpec(spec) assert.NoError(t, err) }, "Calling expand spec with circular refs, should not panic!") }
func TestIssue415(t *testing.T) { doc, err := swag.YAMLDoc("../fixtures/expansion/clickmeter.yaml") assert.NoError(t, err) spec := new(Swagger) err = json.Unmarshal(doc, spec) assert.NoError(t, err) assert.NotPanics(t, func() { err = expandSpec(spec) assert.NoError(t, err) }, "Calling expand spec with response schemas that have circular refs, should not panic!") }
func TestAdditionalPropertiesWithObject(t *testing.T) { schema := new(Schema) b, err := swag.YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml") if assert.NoError(t, err) { var expected map[string]interface{} if assert.NoError(t, json.Unmarshal(b, &expected)) && assert.NoError(t, json.Unmarshal(b, schema)) { cb, err := json.MarshalIndent(schema, "", " ") if assert.NoError(t, err) { var actual map[string]interface{} if assert.NoError(t, json.Unmarshal(cb, &actual)) { assert.Equal(t, expected, actual) } } } } }
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) }) }
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) }) }