Skip to content

Rename Produces defaultStatus -> statusCode #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions http-api/src/main/java/io/avaje/http/api/Produces.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
String value() default MediaType.APPLICATION_JSON;

/**
* The default status code of the generated route.
* The status code of the route when successful.
*
* <p>When not specified, the default status are as follows: <br>
* GET(200) <br>
Expand All @@ -45,5 +45,5 @@
* PATCH(200, void methods 204) <br>
* DELETE(200, void methods 204)
*/
int defaultStatus() default 0;
int statusCode() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public boolean isVoid() {
}

public boolean hasProducesStatus() {
return producesAnnotation.map(ProducesPrism::defaultStatus).filter(s -> s > 0).isPresent();
return producesAnnotation.map(ProducesPrism::statusCode).filter(s -> s > 0).isPresent();
}

public String produces() {
Expand Down Expand Up @@ -384,7 +384,7 @@ public int statusCode() {
return statusCode;
}
return producesAnnotation
.map(ProducesPrism::defaultStatus)
.map(ProducesPrism::statusCode)
.filter(s -> s > 0)
.orElseGet(() -> webMethod.statusCode(isVoid));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Person testPostList(List<Person> m) {
}

@Put("/put")
@Produces(value = MediaType.TEXT_PLAIN, defaultStatus = 203)
@Produces(value = MediaType.TEXT_PLAIN, statusCode = 203)
@OpenAPIResponse(responseCode = "204", type = String.class)
String testDefaultStatus(Context ctx) {
if (ctx.contentType().equals(MediaType.APPLICATION_PDF)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example;

import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -80,9 +81,13 @@ String strBody(@BodyString String body) {
return body;
}

@Produces(statusCode=202)
@Post("/blah")
Map<String, Object> strBody2() {
return Map.of("hi", "yo", "level", 42L);
var map = new LinkedHashMap<String, Object>();
map.put("hi", "yo");
map.put("level", 42L);
return map;
}

@ExceptionHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ void strBody() {
assertThat(res.headers().firstValue("Content-Length")).isPresent();
}

@Test
void blah() {
HttpResponse<String> res = client.request()
.path("test/blah")
.POST()
.asString();

assertThat(res.statusCode()).isEqualTo(202);
assertThat(res.body()).isEqualTo("{\"hi\":\"yo\",\"level\":42}");
assertThat(res.headers().firstValue("Content-Type")).isPresent().get().isEqualTo("application/json");
assertThat(res.headers().firstValue("Content-Length")).isPresent();
}

@Test
void ithrowRuntimeException() {

Expand Down