Skip to content

Commit

Permalink
When a endpoint accepts GET with a body, also allow POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Sep 22, 2023
1 parent 16483bc commit 5622e20
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MultiFetchRoutes(
pathPrefix("multi-fetch") {
pathPrefix("resources") {
extractCaller { implicit caller =>
(get & entity(as[MultiFetchRequest])) { request =>
((get | post) & entity(as[MultiFetchRequest])) { request =>
implicit val printer: Printer = selectPrinter(request)
emit(multiFetch(request).flatMap(_.asJson))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class ResourcesTrialRoutes(
}

private def generateRoute: Route =
(get & pathPrefix("trial") & pathPrefix("resources")) {
((get | post) & pathPrefix("trial") & pathPrefix("resources")) {
extractCaller { implicit caller =>
(resolveProjectRef & pathEndOrSingleSlash) { project =>
authorizeFor(project, Write).apply {
Expand All @@ -100,7 +100,6 @@ final class ResourcesTrialRoutes(
}
)
}

}

object ResourcesTrialRoutes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class MultiFetchRoutesSpec extends BaseRouteSpec {
}
}

"return expected results as annotated source for a user with limited access" in {
"return expected results as annotated source for a user with limited access using post method" in {
val entity = request(ResourceRepresentation.AnnotatedSourceJson).toEntity
Get(endpoint, entity) ~> asAlice ~> routes ~> check {
Post(endpoint, entity) ~> asAlice ~> routes ~> check {
status shouldEqual StatusCodes.OK
response.asJson shouldEqual jsonContentOf("multi-fetch/annotated-source-response.json")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur
}
}

"generate a resource passing a new schema" in {
"generate a resource passing a new schema and using post" in {
val payload = json"""{ "schema": $schemaSource, "resource": $validSource }"""
Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check {
response.status shouldEqual StatusCodes.OK
val jsonResponse = response.asJsonObject
jsonResponse("schema") should not be empty
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/docs/delta/api/multi-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Please visit @ref:[Authentication & authorization](authentication.md) section to
## Payload

```
GET /v1/multi-fetch/resources
GET|POST /v1/multi-fetch/resources
{
"format": {format}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/docs/delta/api/trial.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It applies the same validation steps than the creation/update of resources, the
that nothing is persisted.

```
GET /v1/trial/resources/{org_label}/{project_label}
GET|POST /v1/trial/resources/{org_label}/{project_label}
{
"schema": {schema},
Expand Down

0 comments on commit 5622e20

Please sign in to comment.