Skip to content

Commit

Permalink
feature/WEOS-1250 - review changes
Browse files Browse the repository at this point in the history
ensure returning json configuration does not redirect
  • Loading branch information
atoniaw committed Feb 18, 2022
1 parent c0154df commit 5c04e6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/rest/controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func APIDiscovery(api *RESTAPI, projection projections.Projection, commandDispat
//get content type expected for 200 response
responseType := newContext.Value(weoscontext.RESPONSE_PREFIX + strconv.Itoa(http.StatusOK))
if responseType == "application/json" {
return ctxt.Redirect(http.StatusPermanentRedirect, SWAGGERJSONENDPOINT)
return ctxt.JSON(http.StatusOK, api.Swagger)
} else if responseType == "application/html" {
return ctxt.Redirect(http.StatusPermanentRedirect, SWAGGERUIENDPOINT)
}
Expand Down
15 changes: 12 additions & 3 deletions end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,9 +1435,18 @@ func theTotalNoEventsAndProcessedAndFailuresShouldBeReturned() error {
}

func theApiAsJsonShouldBeShown() error {
url := rec.HeaderMap.Get("Location")
if url != api.SWAGGERJSONENDPOINT {
return fmt.Errorf("the json result should have been returned")
contentEntity := map[string]interface{}{}
err := json.NewDecoder(rec.Body).Decode(&contentEntity)

if err != nil {
return err
}

if len(contentEntity) == 0 {
return fmt.Errorf("expected a response to be returned")
}
if _, ok := contentEntity["openapi"]; !ok {
return fmt.Errorf("expected the content entity to have a content 'openapi'")
}
return nil
}
Expand Down

0 comments on commit 5c04e6c

Please sign in to comment.