4
4
import io .swagger .codegen .v3 .CodegenContent ;
5
5
import io .swagger .codegen .v3 .CodegenOperation ;
6
6
import io .swagger .codegen .v3 .CodegenParameter ;
7
+ import io .swagger .codegen .v3 .generators .util .OpenAPIUtil ;
8
+ import io .swagger .v3 .oas .models .OpenAPI ;
9
+ import io .swagger .v3 .oas .models .media .ArraySchema ;
10
+ import io .swagger .v3 .oas .models .media .Schema ;
7
11
import io .swagger .v3 .oas .models .parameters .CookieParameter ;
8
12
import io .swagger .v3 .oas .models .parameters .HeaderParameter ;
9
13
import io .swagger .v3 .oas .models .parameters .Parameter ;
13
17
import java .util .ArrayList ;
14
18
import java .util .Collections ;
15
19
import java .util .List ;
20
+ import java .util .Map ;
21
+ import java .util .Set ;
16
22
17
23
public class OperationParameters {
18
24
@@ -147,6 +153,40 @@ public void sortRequiredAllParams() {
147
153
});
148
154
}
149
155
156
+ public void parseNestedObjects (String name , Schema schema , Set <String > imports , DefaultCodegenConfig codegenConfig , OpenAPI openAPI ) {
157
+ schema = OpenAPIUtil .getRefSchemaIfExists (schema , openAPI );
158
+ if (schema == null || !isObjectWithProperties (schema )) {
159
+ return ;
160
+ }
161
+ final Map <String , Schema > properties = schema .getProperties ();
162
+ for (String key : properties .keySet ()) {
163
+ Schema property = properties .get (key );
164
+ property = OpenAPIUtil .getRefSchemaIfExists (property , openAPI );
165
+ boolean required ;
166
+ if (schema .getRequired () == null || schema .getRequired ().isEmpty ()) {
167
+ required = false ;
168
+ } else {
169
+ required = schema .getRequired ().stream ().anyMatch (propertyName -> key .equalsIgnoreCase (propertyName .toString ()));
170
+ }
171
+ final String parameterName ;
172
+ if (property instanceof ArraySchema ) {
173
+ parameterName = String .format ("%s[%s][]" , name , key );
174
+ } else {
175
+ parameterName = String .format ("%s[%s]" , name , key );
176
+ }
177
+ if (isObjectWithProperties (property )) {
178
+ parseNestedObjects (parameterName , property , imports , codegenConfig , openAPI );
179
+ continue ;
180
+ }
181
+ final Parameter queryParameter = new QueryParameter ()
182
+ .name (parameterName )
183
+ .required (required )
184
+ .schema (property );
185
+ final CodegenParameter codegenParameter = codegenConfig .fromParameter (queryParameter , imports );
186
+ addParameters (queryParameter , codegenParameter );
187
+ }
188
+ }
189
+
150
190
public static List <CodegenParameter > addHasMore (List <CodegenParameter > codegenParameters ) {
151
191
if (codegenParameters == null || codegenParameters .isEmpty ()) {
152
192
return codegenParameters ;
@@ -157,4 +197,10 @@ public static List<CodegenParameter> addHasMore(List<CodegenParameter> codegenPa
157
197
}
158
198
return codegenParameters ;
159
199
}
200
+
201
+ private boolean isObjectWithProperties (Schema schema ) {
202
+ return ("object" .equalsIgnoreCase (schema .getType ()) || schema .getType () == null )
203
+ && schema .getProperties () != null
204
+ && !schema .getProperties ().isEmpty ();
205
+ }
160
206
}
0 commit comments