3232import org .openapitools .codegen .config .GlobalSettings ;
3333
3434import io .quarkiverse .openapi .generator .deployment .CodegenConfig ;
35+ import io .quarkiverse .openapi .generator .deployment .OpenApiGeneratorOptions ;
3536import io .quarkiverse .openapi .generator .deployment .circuitbreaker .CircuitBreakerConfigurationParser ;
3637import io .quarkiverse .openapi .generator .deployment .wrapper .OpenApiClassicClientGeneratorWrapper ;
3738import io .quarkiverse .openapi .generator .deployment .wrapper .OpenApiClientGeneratorWrapper ;
@@ -109,6 +110,7 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
109110
110111 if (Files .isDirectory (openApiDir )) {
111112 final boolean isRestEasyReactive = isRestEasyReactive (context );
113+ boolean isHibernateValidatorPresent = isHibernateValidatorPresent (context );
112114
113115 if (isRestEasyReactive ) {
114116 if (!isJacksonReactiveClientPresent (context )) {
@@ -123,16 +125,36 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
123125 Optional <String > templateBaseDir = getTemplateBaseDirRelativeToSourceRoot (context .inputDir (), context .config ());
124126 Path templateDir = templateBaseDir .map (Path ::of )
125127 .orElseGet (() -> context .workDir ().resolve ("classes" ).resolve ("templates" ));
126- openApiFilesPaths
128+ List < Path > openApiPaths = openApiFilesPaths
127129 .filter (Files ::isRegularFile )
128130 .filter (path -> {
129131 String fileName = path .getFileName ().toString ();
130132 return fileName .endsWith (inputExtension ())
131133 && !filesToExclude .contains (fileName )
132134 && (filesToInclude .isEmpty () || filesToInclude .contains (fileName ));
133- })
134- .forEach (openApiFilePath -> generate (context .config (), openApiFilePath , outDir , templateDir ,
135- isRestEasyReactive ));
135+ }).toList ();
136+
137+ for (Path openApiPath : openApiPaths ) {
138+
139+ Boolean usingBeanValidation = getValues (context .config (), openApiPath ,
140+ CodegenConfig .ConfigName .BEAN_VALIDATION , Boolean .class )
141+ .orElse (false );
142+
143+ if (usingBeanValidation && !isHibernateValidatorPresent ) {
144+ throw new CodeGenException (
145+ "You need to add io.quarkus:quarkus-hibernate-validator to your dependencies." );
146+ }
147+
148+ OpenApiGeneratorOptions options = new OpenApiGeneratorOptions (
149+ context .config (),
150+ openApiPath ,
151+ outDir ,
152+ templateDir ,
153+ isRestEasyReactive );
154+
155+ generate (options );
156+ }
157+
136158 } catch (IOException e ) {
137159 throw new CodeGenException ("Failed to generate java files from OpenApi files in " + openApiDir .toAbsolutePath (),
138160 e );
@@ -150,6 +172,10 @@ private static boolean isJacksonClassicClientPresent(CodeGenContext context) {
150172 return isExtensionCapabilityPresent (context , Capability .RESTEASY_JSON_JACKSON_CLIENT );
151173 }
152174
175+ protected static boolean isHibernateValidatorPresent (CodeGenContext context ) {
176+ return isExtensionCapabilityPresent (context , Capability .HIBERNATE_VALIDATOR );
177+ }
178+
153179 private void validateUserConfiguration (CodeGenContext context ) throws CodeGenException {
154180 List <String > configurations = StreamSupport .stream (context .config ().getPropertyNames ().spliterator (), false )
155181 .collect (Collectors .toList ());
@@ -171,8 +197,12 @@ private static String determineRestClientReactiveJacksonCapabilityId() {
171197 }
172198
173199 // TODO: do not generate if the output dir has generated files and the openapi file has the same checksum of the previous run
174- protected void generate (final Config config , final Path openApiFilePath , final Path outDir ,
175- Path templateDir , boolean isRestEasyReactive ) {
200+ protected void generate (OpenApiGeneratorOptions options ) {
201+ Config config = options .config ();
202+ Path openApiFilePath = options .openApiFilePath ();
203+ Path outDir = options .outDir ();
204+ boolean isRestEasyReactive = options .isRestEasyReactive ();
205+
176206 final String basePackage = getBasePackage (config , openApiFilePath );
177207 final Boolean verbose = config .getOptionalValue (getGlobalConfigName (CodegenConfig .ConfigName .VERBOSE ), Boolean .class )
178208 .orElse (false );
@@ -183,7 +213,7 @@ protected void generate(final Config config, final Path openApiFilePath, final P
183213 final OpenApiClientGeneratorWrapper generator = createGeneratorWrapper (openApiFilePath , outDir , isRestEasyReactive ,
184214 verbose , validateSpec );
185215
186- generator .withTemplateDir (templateDir );
216+ generator .withTemplateDir (options . templateDir () );
187217
188218 generator .withClassesCodeGenConfig (ClassCodegenConfigParser .parse (config , basePackage ))
189219 .withCircuitBreakerConfig (CircuitBreakerConfigurationParser .parse (
0 commit comments