1010import java .nio .file .Paths ;
1111import java .util .ArrayList ;
1212import java .util .Collections ;
13- import java .util .HashMap ;
1413import java .util .List ;
1514import java .util .Map ;
1615
2120import org .eclipse .microprofile .config .spi .ConfigSource ;
2221import org .eclipse .microprofile .openapi .annotations .Operation ;
2322import org .eclipse .microprofile .openapi .annotations .media .Schema ;
24- import org .eclipse .microprofile .openapi .models .OpenAPI ;
2523import org .eclipse .microprofile .openapi .models .media .Schema .SchemaType ;
2624import org .jboss .jandex .Index ;
2725import org .jboss .jandex .IndexView ;
3634import io .quarkus .test .junit .QuarkusTest ;
3735import io .smallrye .config .PropertiesConfigSource ;
3836import io .smallrye .config .SmallRyeConfigBuilder ;
39- import io .smallrye .openapi .api .OpenApiConfig ;
4037import io .smallrye .openapi .api .SmallRyeOpenAPI ;
41- import io .smallrye .openapi .runtime .io .Format ;
42- import io .smallrye .openapi .runtime .io .OpenApiSerializer ;
43- import io .smallrye .openapi .runtime .scanner .OpenApiAnnotationScanner ;
4438
4539@ QuarkusTest
4640class QuarkusAnnotationScanTest {
4741
4842 private static final Logger LOG = Logger .getLogger (QuarkusAnnotationScanTest .class );
4943
50- static void printToConsole (OpenAPI oai ) throws IOException {
51- // Remember to set debug level logging.
52- LOG .debug (OpenApiSerializer .serialize (oai , Format .JSON ));
53- }
54-
55- static void assertJsonEquals (String expectedResource , OpenAPI actual ) throws Exception {
44+ static void assertJsonEquals (String expectedResource , SmallRyeOpenAPI actual ) throws Exception {
5645 URL resourceUrl = QuarkusAnnotationScanTest .class .getResource (expectedResource );
5746 assertJsonEquals (resourceUrl , actual );
5847 }
5948
60- static void assertJsonEquals (URL expectedResourceUrl , OpenAPI actual ) throws Exception {
49+ static void assertJsonEquals (URL expectedResourceUrl , SmallRyeOpenAPI actual ) throws Exception {
50+ String actualJSON = actual .toJSON ();
51+ LOG .debug (actualJSON );
52+
6153 JSONAssert .assertEquals (
62- String . join ( " \n " , Files .readAllLines (Paths .get (expectedResourceUrl .toURI () ))),
63- OpenApiSerializer . serialize ( actual , Format . JSON ) ,
54+ Files .readString (Paths .get (expectedResourceUrl .toURI ())),
55+ actualJSON ,
6456 true );
6557 }
6658
67- static OpenApiConfig emptyConfig () {
68- return dynamicConfig (Collections .emptyMap ());
69- }
70-
71- static OpenApiConfig dynamicConfig (String key , Object value ) {
72- Map <String , String > config = new HashMap <>(1 );
73- config .put (key , value .toString ());
74- return dynamicConfig (config );
59+ static SmallRyeOpenAPI scan (IndexView index , Config config ) {
60+ return SmallRyeOpenAPI .builder ()
61+ .defaultRequiredProperties (false )
62+ .withIndex (index )
63+ .withConfig (config )
64+ .build ();
7565 }
7666
77- static OpenApiConfig dynamicConfig (Map <String , String > properties ) {
78- Config config = new SmallRyeConfigBuilder ()
67+ static Config config (Map <String , String > properties ) {
68+ return new SmallRyeConfigBuilder ()
7969 .withSources (new PropertiesConfigSource (properties , "unit-test" , ConfigSource .DEFAULT_ORDINAL ))
8070 .build ();
81- return OpenApiConfig .fromConfig (config );
8271 }
8372
8473 static IndexView index (String ... classNames ) {
@@ -103,27 +92,18 @@ static IndexView index(String... classNames) {
10392 void testKotlinPropertyName () throws Exception {
10493 IndexView index = index ("io.smallrye.openapi.testdata.kotlin.KotlinBean" ,
10594 "io.smallrye.openapi.testdata.kotlin.KotlinLongValue" );
106- OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner (emptyConfig (), index );
107-
108- OpenAPI result = scanner .scan ();
109-
110- printToConsole (result );
95+ SmallRyeOpenAPI result = scan (index , config (Collections .emptyMap ()));
11196 assertJsonEquals ("components.schemas.kotlin-value-class-propname.json" , result );
11297 }
11398
114- @ SuppressWarnings ("deprecation" )
11599 @ ParameterizedTest
116100 @ ValueSource (strings = {
117101 "io.smallrye.openapi.testdata.kotlin.JavaDeprecatedKotlinBean" ,
118102 "io.smallrye.openapi.testdata.kotlin.DeprecatedKotlinBean"
119103 })
120104 void testDeprecatedAnnotation (String className ) throws Exception {
121105 IndexView index = index (className );
122- OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner (emptyConfig (), index );
123-
124- OpenAPI result = scanner .scan ();
125-
126- printToConsole (result );
106+ SmallRyeOpenAPI result = scan (index , config (Collections .emptyMap ()));
127107 assertJsonEquals ("components.schemas.kotlin-deprecated-annotation.json" , result );
128108 }
129109
@@ -132,22 +112,14 @@ void testRecordWithPojoPrefixedRecordComponents() throws Exception {
132112 Index index = Index .of (
133113 io .smallrye .openapi .testdata .java .records .NonBeanRecord .class ,
134114 io .smallrye .openapi .testdata .java .records .RecordReferencingBean .class );
135- OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner (emptyConfig (), index );
136-
137- OpenAPI result = scanner .scan ();
138-
139- printToConsole (result );
115+ SmallRyeOpenAPI result = scan (index , config (Collections .emptyMap ()));
140116 assertJsonEquals ("components.schemas.prefixed-record-component-names.json" , result );
141117 }
142118
143119 @ Test
144120 void testKotlinResourceWithUnwrappedFlowSSE () throws Exception {
145121 IndexView index = index ("io.smallrye.openapi.testdata.kotlin.KotlinResource" );
146- OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner (emptyConfig (), index );
147-
148- OpenAPI result = scanner .scan ();
149-
150- printToConsole (result );
122+ SmallRyeOpenAPI result = scan (index , config (Collections .emptyMap ()));
151123 assertJsonEquals ("components.schemas.kotlin-flow-unwrapped.json" , result );
152124 }
153125
@@ -173,16 +145,15 @@ public Widget get() {
173145 }
174146
175147 Index index = Index .of (Named .class , Widget .class , WidgetsResource .class );
176- OpenAPI result = SmallRyeOpenAPI .builder ()
148+ SmallRyeOpenAPI result = SmallRyeOpenAPI .builder ()
177149 .withIndex (index )
178150 .enableModelReader (false )
179151 .enableStandardFilter (false )
180152 .enableStandardStaticFiles (false )
181- .build ()
182- .model ();
153+ .build ();
183154
184- printToConsole (result );
185- var nameModel = result .getComponents ().getSchemas ().get ("Widget" ).getProperties ().get ("nombre" );
155+ LOG . debug (result . toJSON () );
156+ var nameModel = result .model (). getComponents ().getSchemas ().get ("Widget" ).getProperties ().get ("nombre" );
186157 assertNotNull (nameModel );
187158 assertEquals (List .of (SchemaType .STRING ), nameModel .getType ());
188159 }
0 commit comments