Fix yet another bug in OpenAPI extension generation

pull/6/head
mbohlool 2017-05-04 13:11:49 -07:00
parent c083871b68
commit bcd0288e60
2 changed files with 23 additions and 5 deletions

View File

@ -132,7 +132,9 @@ func (o *openAPI) buildDefinitionRecursively(name string) error {
SwaggerSchemaProps: item.Schema.SwaggerSchemaProps,
}
if extensions != nil {
schema.Extensions = spec.Extensions{}
if schema.Extensions == nil {
schema.Extensions = spec.Extensions{}
}
for k, v := range extensions {
schema.Extensions[k] = v
}

View File

@ -17,6 +17,7 @@ limitations under the License.
package openapi
import (
"encoding/json"
"fmt"
"net/http"
"strings"
@ -203,7 +204,7 @@ func getConfig(fullMethods bool) (*openapi.Config, *restful.Container) {
if strings.HasPrefix(friendlyName, "go_default_test") {
friendlyName = "openapi" + friendlyName[len("go_default_test"):]
}
return friendlyName, nil
return friendlyName, spec.Extensions{"x-test2": "test2"}
},
}, container
}
@ -388,7 +389,8 @@ func getTestInputDefinition() spec.Schema {
},
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-test": "test",
"x-test": "test",
"x-test2": "test2",
},
},
}
@ -414,6 +416,11 @@ func getTestOutputDefinition() spec.Schema {
},
},
},
VendorExtensible: spec.VendorExtensible{
Extensions: spec.Extensions{
"x-test2": "test2",
},
},
}
}
@ -441,7 +448,16 @@ func TestBuildSwaggerSpec(t *testing.T) {
},
}
err := o.init(container.RegisteredWebServices())
if assert.NoError(err) {
assert.Equal(expected, o.swagger)
if !assert.NoError(err) {
return
}
expected_json, err := json.Marshal(expected)
if !assert.NoError(err) {
return
}
actual_json, err := json.Marshal(o.swagger)
if !assert.NoError(err) {
return
}
assert.Equal(string(expected_json), string(actual_json))
}