Skip to content

Commit a5a5165

Browse files
committed
#179 Tidy up and format for BeanParam OpenAPI
1 parent cbdd30f commit a5a5165

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/MethodParam.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,22 @@ public void buildParamName(Append writer) {
3232
}
3333

3434
public void buildApiDocumentation(MethodDocBuilder methodDoc) {
35-
if (elementParam.paramType() != ParamType.BEANPARAM)
35+
if (elementParam.paramType() != ParamType.BEANPARAM) {
3636
elementParam.buildApiDocumentation(methodDoc);
37-
else {
37+
} else {
3838
asElement(elementParam.element().asType()).getEnclosedElements().stream()
3939
.filter(e -> e.getKind() == ElementKind.FIELD)
4040
.map(VariableElement.class::cast)
41-
.forEach(
42-
e -> {
43-
final var typeMirror = e.asType();
44-
45-
new ElementReader(
46-
e,
47-
Util.parse(typeMirror.toString()),
48-
Util.typeDef(typeMirror),
49-
ParamType.QUERYPARAM,
50-
false)
51-
.buildApiDocumentation(methodDoc);
52-
});
41+
.forEach(e -> buildDoc(methodDoc, e));
5342
}
5443
}
5544

45+
private static void buildDoc(MethodDocBuilder methodDoc, VariableElement e) {
46+
final var typeMirror = e.asType();
47+
new ElementReader(e, Util.parse(typeMirror.toString()), Util.typeDef(typeMirror), ParamType.QUERYPARAM, false)
48+
.buildApiDocumentation(methodDoc);
49+
}
50+
5651
public boolean isBody() {
5752
return elementParam.paramType() == ParamType.BODY;
5853
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ private OpenAPI initOpenAPI() {
7979

8080
Schema toSchema(String rawType, Element element) {
8181
final var typeElement = elements.getTypeElement(rawType);
82-
final var varElement =
83-
elements.getTypeElement(Util.trimAnnotations(element.asType().toString()));
84-
82+
final var varElement = elements.getTypeElement(Util.trimAnnotations(element.asType().toString()));
8583
if (typeElement == null) {
8684
// primitive types etc
8785
return schemaBuilder.toSchema(element.asType());

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ private static TypeMirror typeArgument(TypeMirror type) {
135135
}
136136

137137
Schema<?> toSchema(Element element) {
138-
var schema = toSchema(element.asType());
139-
138+
final var schema = toSchema(element.asType());
140139
setLengthMinMax(element, schema);
141140
setFormatFromValidation(element, schema);
142141
if (isNotNullable(element)) {

tests/test-javalin-jsonb/src/main/resources/public/openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"openapi" : "3.0.1",
33
"info" : {
4-
"title" : "Example service",
4+
"title" : "Example service showing off the Path extension method of controller",
55
"description" : "Example Javalin controllers with Java and Maven",
66
"version" : ""
77
},
88
"tags" : [
99
{
1010
"name" : "tag1",
11-
"description" : "it's somethin"
11+
"description" : "this is added to openapi tags"
1212
},
1313
{
1414
"name" : "tag1",
15-
"description" : "this is added to openapi tags"
15+
"description" : "it's somethin"
1616
}
1717
],
1818
"paths" : {

tests/test-javalin/src/main/resources/public/openapi.json

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,22 @@
682682
"description" : "",
683683
"parameters" : [
684684
{
685-
"name" : "bean",
686-
"in" : "bean",
685+
"name" : "name",
686+
"in" : "query",
687687
"schema" : {
688-
"$ref" : "#/components/schemas/GetBeanForm"
688+
"maxLength" : 150,
689+
"minLength" : 2,
690+
"type" : "string",
691+
"nullable" : false
692+
}
693+
},
694+
{
695+
"name" : "email",
696+
"in" : "query",
697+
"schema" : {
698+
"maxLength" : 100,
699+
"type" : "string",
700+
"format" : "email"
689701
}
690702
}
691703
],
@@ -835,22 +847,6 @@
835847
}
836848
}
837849
},
838-
"GetBeanForm" : {
839-
"type" : "object",
840-
"properties" : {
841-
"name" : {
842-
"maxLength" : 150,
843-
"minLength" : 2,
844-
"type" : "string",
845-
"nullable" : false
846-
},
847-
"email" : {
848-
"maxLength" : 100,
849-
"type" : "string",
850-
"format" : "email"
851-
}
852-
}
853-
},
854850
"HelloDto" : {
855851
"type" : "object",
856852
"properties" : {

0 commit comments

Comments
 (0)