@@ -2117,17 +2117,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2117
2117
}
2118
2118
2119
2119
List <Parameter > parameters = operation .getParameters ();
2120
- CodegenParameter bodyParam = null ;
2121
- List <CodegenParameter > allParams = new ArrayList <>();
2122
- List <CodegenParameter > bodyParams = new ArrayList <>();
2123
- List <CodegenParameter > pathParams = new ArrayList <>();
2124
- List <CodegenParameter > queryParams = new ArrayList <>();
2125
- List <CodegenParameter > headerParams = new ArrayList <>();
2126
- List <CodegenParameter > cookieParams = new ArrayList <>();
2127
- List <CodegenParameter > formParams = new ArrayList <>();
2128
- List <CodegenParameter > requiredParams = new ArrayList <>();
2129
-
2130
- List <CodegenContent > codegenContents = new ArrayList <>();
2120
+ final OpenAPIParameters openAPIParameters = new OpenAPIParameters ();
2131
2121
2132
2122
RequestBody body = operation .getRequestBody ();
2133
2123
if (body != null ) {
@@ -2188,20 +2178,20 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2188
2178
}
2189
2179
// todo: this segment is only to support the "older" template design. it should be removed once all templates are updated with the new {{#contents}} tag.
2190
2180
formParameter .getVendorExtensions ().put (CodegenConstants .IS_FORM_PARAM_EXT_NAME , Boolean .TRUE );
2191
- formParams . add (formParameter .copy ());
2181
+ openAPIParameters . addFormParam (formParameter .copy ());
2192
2182
if (body .getRequired () != null && body .getRequired ()) {
2193
- requiredParams . add (formParameter .copy ());
2183
+ openAPIParameters . addRequiredParam (formParameter .copy ());
2194
2184
}
2195
- allParams . add (formParameter );
2185
+ openAPIParameters . addAllParams (formParameter );
2196
2186
}
2197
- codegenContents . add (codegenContent );
2187
+ openAPIParameters . addCodegenContents (codegenContent );
2198
2188
}
2199
2189
} else {
2200
- bodyParam = fromRequestBody (body , schemaName , schema , schemas , imports );
2190
+ CodegenParameter bodyParam = fromRequestBody (body , schemaName , schema , schemas , imports );
2191
+ openAPIParameters .setBodyParam (bodyParam );
2201
2192
if (foundSchemas .isEmpty ()) {
2202
- // todo: this segment is only to support the "older" template design. it should be removed once all templates are updated with the new {{#contents}} tag.
2203
- bodyParams .add (bodyParam .copy ());
2204
- allParams .add (bodyParam );
2193
+ openAPIParameters .addBodyParams (bodyParam .copy ());
2194
+ openAPIParameters .addAllParams (bodyParam );
2205
2195
} else {
2206
2196
boolean alreadyAdded = false ;
2207
2197
for (Schema usedSchema : foundSchemas ) {
@@ -2214,7 +2204,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2214
2204
}
2215
2205
}
2216
2206
foundSchemas .add (schema );
2217
- codegenContents . add (codegenContent );
2207
+ openAPIParameters . addCodegenContents (codegenContent );
2218
2208
}
2219
2209
}
2220
2210
}
@@ -2225,52 +2215,24 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
2225
2215
param = getParameterFromRef (param .get$ref (), openAPI );
2226
2216
}
2227
2217
CodegenParameter codegenParameter = fromParameter (param , imports );
2228
- allParams .add (codegenParameter );
2229
- // Issue #2561 (neilotoole) : Moved setting of is<Type>Param flags
2230
- // from here to fromParameter().
2231
- if (param instanceof QueryParameter || "query" .equalsIgnoreCase (param .getIn ())) {
2232
- queryParams .add (codegenParameter .copy ());
2233
- } else if (param instanceof PathParameter || "path" .equalsIgnoreCase (param .getIn ())) {
2234
- pathParams .add (codegenParameter .copy ());
2235
- } else if (param instanceof HeaderParameter || "header" .equalsIgnoreCase (param .getIn ())) {
2236
- headerParams .add (codegenParameter .copy ());
2237
- } else if (param instanceof CookieParameter || "cookie" .equalsIgnoreCase (param .getIn ())) {
2238
- cookieParams .add (codegenParameter .copy ());
2239
- }
2240
- if (codegenParameter .required ) {
2241
- requiredParams .add (codegenParameter .copy ());
2242
- }
2218
+ openAPIParameters .addParameters (param , codegenParameter );
2243
2219
}
2244
2220
}
2245
2221
2246
2222
addOperationImports (codegenOperation , imports );
2247
2223
2248
- codegenOperation .bodyParam = bodyParam ;
2224
+ codegenOperation .bodyParam = openAPIParameters . getBodyParam () ;
2249
2225
codegenOperation .httpMethod = httpMethod .toUpperCase ();
2250
2226
2251
2227
// move "required" parameters in front of "optional" parameters
2252
2228
if (sortParamsByRequiredFlag ) {
2253
- Collections .sort (allParams , new Comparator <CodegenParameter >() {
2254
- @ Override
2255
- public int compare (CodegenParameter one , CodegenParameter another ) {
2256
- if (one .required == another .required ) return 0 ;
2257
- else if (one .required ) return -1 ;
2258
- else return 1 ;
2259
- }
2260
- });
2229
+ openAPIParameters .sortRequiredAllParams ();
2261
2230
}
2262
2231
2263
- codegenOperation .allParams = addHasMore (allParams );
2264
- codegenOperation .bodyParams = addHasMore (bodyParams );
2265
- codegenOperation .pathParams = addHasMore (pathParams );
2266
- codegenOperation .queryParams = addHasMore (queryParams );
2267
- codegenOperation .headerParams = addHasMore (headerParams );
2268
- codegenOperation .cookieParams = addHasMore (cookieParams );
2269
- codegenOperation .formParams = addHasMore (formParams );
2270
- codegenOperation .requiredParams = addHasMore (requiredParams );
2232
+ openAPIParameters .addHasMore (codegenOperation );
2271
2233
codegenOperation .externalDocs = operation .getExternalDocs ();
2272
2234
2273
- configuresParameterForMediaType (codegenOperation , codegenContents );
2235
+ configuresParameterForMediaType (codegenOperation , openAPIParameters . getCodegenContents () );
2274
2236
// legacy support
2275
2237
codegenOperation .nickname = codegenOperation .operationId ;
2276
2238
@@ -3002,16 +2964,6 @@ private void addHeaders(ApiResponse response, List<CodegenProperty> target, Map<
3002
2964
}
3003
2965
}
3004
2966
3005
- protected static List <CodegenParameter > addHasMore (List <CodegenParameter > objs ) {
3006
- if (objs != null ) {
3007
- for (int i = 0 ; i < objs .size (); i ++) {
3008
- objs .get (i ).secondaryParam = i > 0 ;
3009
- objs .get (i ).getVendorExtensions ().put (CodegenConstants .HAS_MORE_EXT_NAME , i < objs .size () - 1 );
3010
- }
3011
- }
3012
- return objs ;
3013
- }
3014
-
3015
2967
private static Map <String , Object > addHasMore (Map <String , Object > objs ) {
3016
2968
if (objs != null ) {
3017
2969
for (int i = 0 ; i < objs .size () - 1 ; i ++) {
@@ -4379,7 +4331,7 @@ protected void configuresParameterForMediaType(CodegenOperation codegenOperation
4379
4331
}
4380
4332
}
4381
4333
);
4382
- addHasMore (content .getParameters ());
4334
+ OpenAPIParameters . addHasMore (content .getParameters ());
4383
4335
}
4384
4336
codegenOperation .getContents ().addAll (codegenContents );
4385
4337
}
0 commit comments