Skip to content

Commit c2fa6e2

Browse files
committed
keep validation stuff
1 parent 747a690 commit c2fa6e2

File tree

3 files changed

+59
-27
lines changed

3 files changed

+59
-27
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.avaje.http.generator.core.SecuritySchemesPrism;
2323
import io.avaje.http.generator.core.TagPrism;
2424
import io.avaje.http.generator.core.TagsPrism;
25+
import io.avaje.http.generator.core.Util;
2526
import io.swagger.v3.oas.models.Components;
2627
import io.swagger.v3.oas.models.OpenAPI;
2728
import io.swagger.v3.oas.models.Operation;
@@ -77,12 +78,17 @@ private OpenAPI initOpenAPI() {
7778
}
7879

7980
Schema toSchema(String rawType, Element element) {
80-
TypeElement typeElement = elements.getTypeElement(rawType);
81+
final var typeElement = elements.getTypeElement(rawType);
82+
final var varElement =
83+
elements.getTypeElement(Util.trimAnnotations(element.asType().toString()));
84+
8185
if (typeElement == null) {
8286
// primitive types etc
8387
return schemaBuilder.toSchema(element.asType());
88+
} else if (varElement != null) {
89+
return schemaBuilder.toSchema(element);
8490
} else {
85-
return schemaBuilder.toSchema(typeElement.asType());
91+
return schemaBuilder.toSchema(typeElement);
8692
}
8793
}
8894

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ private static TypeMirror typeArgument(TypeMirror type) {
132132
return typeArguments.get(0);
133133
}
134134

135+
Schema<?> toSchema(Element element) {
136+
var schema = toSchema(element.asType());
137+
138+
setLengthMinMax(element, schema);
139+
setFormatFromValidation(element, schema);
140+
if (isNotNullable(element)) {
141+
schema.setNullable(Boolean.FALSE);
142+
}
143+
return schema;
144+
}
145+
135146
Schema<?> toSchema(TypeMirror type) {
136147
if (types.isAssignable(type, completableFutureType)) {
137148
type = typeArgument(type);

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,39 @@
692692
"description" : "",
693693
"parameters" : [
694694
{
695-
"name" : "bean",
696-
"in" : "bean",
695+
"name" : "name",
696+
"in" : "query",
697697
"schema" : {
698-
"$ref" : "#/components/schemas/GetBeanForm"
698+
"maxLength" : 150,
699+
"minLength" : 2,
700+
"type" : "string",
701+
"nullable" : false
702+
}
703+
},
704+
{
705+
"name" : "email",
706+
"in" : "query",
707+
"schema" : {
708+
"maxLength" : 100,
709+
"type" : "string",
710+
"format" : "email"
711+
}
712+
},
713+
{
714+
"name" : "addresses",
715+
"in" : "query",
716+
"schema" : {
717+
"type" : "array",
718+
"items" : {
719+
"type" : "string"
720+
}
721+
}
722+
},
723+
{
724+
"name" : "head",
725+
"in" : "header",
726+
"schema" : {
727+
"type" : "string"
699728
}
700729
}
701730
],
@@ -1440,6 +1469,11 @@
14401469
}
14411470
}
14421471
}
1472+
},
1473+
}
1474+
}
1475+
}
1476+
}
14431477
},
14441478
"/test/int" : {
14451479
"put" : {
@@ -1805,28 +1839,6 @@
18051839
}
18061840
}
18071841
},
1808-
"GetBeanForm" : {
1809-
"type" : "object",
1810-
"properties" : {
1811-
"name" : {
1812-
"maxLength" : 150,
1813-
"minLength" : 2,
1814-
"type" : "string",
1815-
"nullable" : false
1816-
},
1817-
"email" : {
1818-
"maxLength" : 100,
1819-
"type" : "string",
1820-
"format" : "email"
1821-
},
1822-
"addresses" : {
1823-
"type" : "array",
1824-
"items" : {
1825-
"type" : "string"
1826-
}
1827-
}
1828-
}
1829-
},
18301842
"HelloDto" : {
18311843
"type" : "object",
18321844
"properties" : {
@@ -1876,6 +1888,9 @@
18761888
}
18771889
}
18781890
},
1891+
"InputStream" : {
1892+
"type" : "object"
1893+
},
18791894
"MyForm" : {
18801895
"type" : "object",
18811896
"properties" : {

0 commit comments

Comments
 (0)