ensure the dom contains the prefixed path to the openapi file

This commit is contained in:
David Weiser 2020-08-17 14:25:11 -07:00
parent ef83dce725
commit 75d43f149d

View file

@ -267,29 +267,9 @@ func TestRouter(t *testing.T) {
}
func TestRouterDocsPrefix(t *testing.T) {
type EchoResponse struct {
Value string `json:"value" description:"The echoed back word"`
}
r := NewTestRouter(t, DocsRoutePrefix("/prefix"))
r.Resource("/echo",
PathParam("word", "The word to echo back"),
QueryParam("greet", "Return a greeting", false),
ResponseJSON(http.StatusOK, "Successful echo response"),
ResponseError(http.StatusBadRequest, "Invalid input"),
).Put("Echo back an input word.", func(word string, greet bool) (*EchoResponse, *ErrorModel) {
if word == "test" {
return nil, &ErrorModel{Detail: "Value not allowed: test"}
}
v := word
if greet {
v = "Hello, " + word
}
return &EchoResponse{Value: v}, nil
})
r := NewRouter("api", "v", DocsRoutePrefix("/prefix"))
r.Resource("/hello").Get("doc", func() string { return "Hello" })
// Check spec & docs routes
w := httptest.NewRecorder()
@ -301,6 +281,7 @@ func TestRouterDocsPrefix(t *testing.T) {
req, _ = http.NewRequest(http.MethodGet, "/prefix/docs", nil)
r.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, "prefix/openapi", w.Body.String())
}
func TestRouterRequestBody(t *testing.T) {