Skip to content

Commit f778f78

Browse files
committed
Update Javadoc for Consumes and tidy generator internals
1 parent 444d34a commit f778f78

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

http-api/src/main/java/io/avaje/http/api/Consumes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Specify endpoint request media type for the generated OpenAPI json.
1212
*
1313
* <p>When not specified the default MediaType is application/json, so we specify this on
14-
* controllers or methods where the responses return a different media type.
14+
* controllers or methods where the request consumes a different media type.
1515
*
1616
* <pre>{@code
1717
* @Path("/customers")

http-generator-core/src/main/java/io/avaje/http/generator/core/openapi/MethodDocBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MethodDocBuilder {
2424
private final DocContext ctx;
2525

2626
private final Operation operation = new Operation();
27-
private Optional<ConsumesPrism> consumeOp;
27+
private final Optional<ConsumesPrism> consumeOp;
2828

2929
public MethodDocBuilder(MethodReader methodReader, DocContext ctx) {
3030
this.methodReader = methodReader;
@@ -34,9 +34,7 @@ public MethodDocBuilder(MethodReader methodReader, DocContext ctx) {
3434
}
3535

3636
public void build() {
37-
38-
if (ctx.isOpenApiAvailable()
39-
&& methodReader.findAnnotation(HiddenPrism::getOptionalOn).isPresent()) {
37+
if (ctx.isOpenApiAvailable() && methodReader.findAnnotation(HiddenPrism::getOptionalOn).isPresent()) {
4038
return;
4139
}
4240

http-generator-core/src/main/java/io/avaje/http/generator/core/openapi/MethodParamDocBuilder.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ public class MethodParamDocBuilder {
2828
private final String rawType;
2929
private final ParamType paramType;
3030
private final Element element;
31-
private Optional<ConsumesPrism> consumeOp;
31+
private final Optional<ConsumesPrism> consumeOp;
3232

3333
public MethodParamDocBuilder(MethodDocBuilder methodDoc, ElementReader param) {
34-
3534
this.ctx = methodDoc.getContext();
3635
this.javadoc = methodDoc.getJavadoc();
3736
this.operation = methodDoc.getOperation();
3837
this.consumeOp = methodDoc.consumeOp();
39-
4038
this.paramType = param.paramType();
4139
this.paramName = param.paramName();
4240
this.varName = param.varName();
@@ -48,7 +46,6 @@ public MethodParamDocBuilder(MethodDocBuilder methodDoc, ElementReader param) {
4846
* Build the OpenAPI documentation for the method parameter.
4947
*/
5048
public void build() {
51-
5249
if (paramType == ParamType.FORM || paramType == ParamType.BODY) {
5350
addMetaRequestBody(ctx, javadoc, operation);
5451

@@ -57,7 +54,7 @@ public void build() {
5754
param.setName(varName);
5855
param.setDescription(javadoc.getParams().get(paramName));
5956

60-
Schema schema = ctx.toSchema(rawType, element);
57+
Schema<?> schema = ctx.toSchema(rawType, element);
6158
if (paramType == ParamType.FORMPARAM) {
6259
ctx.addFormParam(operation, varName, schema);
6360

@@ -70,24 +67,22 @@ public void build() {
7067
}
7168

7269
private void addMetaRequestBody(DocContext ctx, Javadoc javadoc, Operation operation) {
73-
74-
Schema schema = ctx.toSchema(rawType, element);
75-
String description = javadoc.getParams().get(paramName);
70+
final var schema = ctx.toSchema(rawType, element);
71+
final var description = javadoc.getParams().get(paramName);
7672
var mediaType =
7773
consumeOp
7874
.map(ConsumesPrism::value)
79-
.orElseGet(
80-
() -> {
81-
boolean asForm = (paramType == ParamType.FORM);
82-
var mime = asForm ? APP_FORM : APP_JSON;
83-
84-
if (schema instanceof StringSchema) {
85-
mime = APP_TXT;
86-
}
87-
return mime;
88-
});
75+
.orElseGet(() -> requestMedia(schema));
8976

9077
ctx.addRequestBody(operation, schema, mediaType, description);
9178
}
9279

80+
private String requestMedia(Schema<?> schema) {
81+
if (schema instanceof StringSchema) {
82+
return APP_TXT;
83+
}
84+
boolean asForm = (paramType == ParamType.FORM);
85+
return asForm ? APP_FORM : APP_JSON;
86+
}
87+
9388
}

0 commit comments

Comments
 (0)