3232import io .swagger .v3 .oas .models .parameters .Parameter ;
3333import java .util .Collection ;
3434import java .util .HashMap ;
35+ import java .util .HashSet ;
3536import java .util .Iterator ;
3637import java .util .Map ;
38+ import java .util .Set ;
3739import java .util .concurrent .CompletableFuture ;
3840
3941public class OpenAPIExecutor implements CallableTask <CallOpenAPI > {
@@ -105,24 +107,31 @@ private void fillHttpBuilder(WorkflowApplication application, OperationDefinitio
105107 Map <String , Object > headersMap = new HashMap <>();
106108 Map <String , Object > queryMap = new HashMap <>();
107109 Map <String , Object > pathParameters = new HashMap <>();
110+ Set <String > missingParams = new HashSet <>();
108111
109112 Map <String , Object > bodyParameters = new HashMap <>(parameters );
110113 for (Parameter parameter : operation .getParameters ()) {
111114 switch (parameter .getIn ()) {
112115 case "header" :
113- param (parameter . getName () , bodyParameters , headersMap );
116+ param (parameter , bodyParameters , headersMap , missingParams );
114117 break ;
115118 case "path" :
116- param (parameter . getName () , bodyParameters , pathParameters );
119+ param (parameter , bodyParameters , pathParameters , missingParams );
117120 break ;
118121 case "query" :
119- param (parameter . getName () , bodyParameters , queryMap );
122+ param (parameter , bodyParameters , queryMap , missingParams );
120123 break ;
121124 }
122125 }
123126
124- validateRequiredParameters (operation , headersMap , queryMap , pathParameters );
125-
127+ if (!missingParams .isEmpty ()) {
128+ throw new IllegalArgumentException (
129+ "Missing required OpenAPI parameters for operation '"
130+ + (operation .getOperation ().getOperationId () != null
131+ ? operation .getOperation ().getOperationId ()
132+ : "<unknown>" + "': " )
133+ + missingParams );
134+ }
126135 builder
127136 .withMethod (operation .getMethod ())
128137 .withPath (new OperationPathResolver (operation .getPath (), application , pathParameters ))
@@ -131,71 +140,22 @@ private void fillHttpBuilder(WorkflowApplication application, OperationDefinitio
131140 .withHeaders (headersMap );
132141 }
133142
134- private void param (String name , Map <String , Object > origMap , Map <String , Object > collectorMap ) {
135- Object value = origMap .remove (name );
136- if (value != null ) {
137- collectorMap .put (name , value );
138- }
139- }
140-
141- private void validateRequiredParameters (
142- OperationDefinition operation ,
143- Map <String , Object > headersMap ,
144- Map <String , Object > queryMap ,
145- Map <String , Object > pathParameters ) {
146-
147- StringBuilder missing = new StringBuilder ();
148-
149- for (Parameter parameter : operation .getParameters ()) {
150- if (!Boolean .TRUE .equals (parameter .getRequired ())) {
151- continue ;
152- }
153-
154- String in = parameter .getIn ();
155- String name = parameter .getName ();
156-
157- Map <String , Object > targetMap =
158- switch (in ) {
159- case "header" -> headersMap ;
160- case "path" -> pathParameters ;
161- case "query" -> queryMap ;
162- default -> null ;
163- };
164-
165- if (targetMap == null ) {
166- // We don't currently handle other "in" locations here (e.g., cookie).
167- // Treat as "not validated" instead of failing.
168- continue ;
169- }
170-
171- boolean present = targetMap .containsKey (name );
172-
173- if (!present ) {
174- // Try to satisfy the requirement using the OpenAPI default, if any
175- Schema <?> schema = parameter .getSchema ();
176- Object defaultValue = schema != null ? schema .getDefault () : null ;
177-
178- if (defaultValue != null ) {
179- targetMap .put (name , defaultValue );
180- present = true ;
181- }
143+ private void param (
144+ Parameter parameter ,
145+ Map <String , Object > origMap ,
146+ Map <String , Object > collectorMap ,
147+ Set <String > missingParams ) {
148+ String name = parameter .getName ();
149+ if (origMap .containsKey (name )) {
150+ collectorMap .put (parameter .getName (), origMap .remove (name ));
151+ } else if (parameter .getRequired ()) {
152+ Schema <?> schema = parameter .getSchema ();
153+ Object defaultValue = schema != null ? schema .getDefault () : null ;
154+ if (defaultValue != null ) {
155+ collectorMap .put (name , defaultValue );
156+ } else {
157+ missingParams .add (name );
182158 }
183-
184- if (!present ) {
185- if (!missing .isEmpty ()) {
186- missing .append (", " );
187- }
188- missing .append (in ).append (" parameter '" ).append (name ).append ("'" );
189- }
190- }
191-
192- if (!missing .isEmpty ()) {
193- String operationId =
194- operation .getOperation ().getOperationId () != null
195- ? operation .getOperation ().getOperationId ()
196- : "<unknown>" ;
197- throw new IllegalArgumentException (
198- "Missing required OpenAPI parameters for operation '" + operationId + "': " + missing );
199159 }
200160 }
201161}
0 commit comments