@@ -2493,6 +2493,76 @@ protected ApiResponse findMethodResponse(ApiResponses responses) {
24932493 return responses .get (code );
24942494 }
24952495
2496+ /**
2497+ * Set op's returnBaseType, returnType, examples etc.
2498+ *
2499+ * @param operation endpoint Operation
2500+ * @param schemas a map of the schemas in the openapi spec
2501+ * @param op endpoint CodegenOperation
2502+ * @param methodResponse the default ApiResponse for the endpoint
2503+ */
2504+ protected void handleMethodResponse (Operation operation ,
2505+ Map <String , Schema > schemas ,
2506+ CodegenOperation op ,
2507+ ApiResponse methodResponse ) {
2508+ Schema responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (methodResponse ));
2509+
2510+ if (responseSchema != null ) {
2511+ CodegenProperty cm = fromProperty ("response" , responseSchema );
2512+
2513+ if (ModelUtils .isArraySchema (responseSchema )) {
2514+ ArraySchema as = (ArraySchema ) responseSchema ;
2515+ CodegenProperty innerProperty = fromProperty ("response" , getSchemaItems (as ));
2516+ op .returnBaseType = innerProperty .baseType ;
2517+ } else if (ModelUtils .isMapSchema (responseSchema )) {
2518+ CodegenProperty innerProperty = fromProperty ("response" , ModelUtils .getAdditionalProperties (responseSchema ));
2519+ op .returnBaseType = innerProperty .baseType ;
2520+ } else {
2521+ if (cm .complexType != null ) {
2522+ op .returnBaseType = cm .complexType ;
2523+ } else {
2524+ op .returnBaseType = cm .baseType ;
2525+ }
2526+ }
2527+
2528+ // generate examples
2529+ String exampleStatusCode = "200" ;
2530+ for (String key : operation .getResponses ().keySet ()) {
2531+ if (operation .getResponses ().get (key ) == methodResponse && !key .equals ("default" )) {
2532+ exampleStatusCode = key ;
2533+ }
2534+ }
2535+ op .examples = new ExampleGenerator (schemas , this .openAPI ).generateFromResponseSchema (exampleStatusCode , responseSchema , getProducesInfo (this .openAPI , operation ));
2536+ op .defaultResponse = toDefaultValue (responseSchema );
2537+ op .returnType = cm .dataType ;
2538+ op .hasReference = schemas .containsKey (op .returnBaseType );
2539+
2540+ // lookup discriminator
2541+ Schema schema = schemas .get (op .returnBaseType );
2542+ if (schema != null ) {
2543+ CodegenModel cmod = fromModel (op .returnBaseType , schema );
2544+ op .discriminator = cmod .discriminator ;
2545+ }
2546+
2547+ if (cm .isContainer ) {
2548+ op .returnContainer = cm .containerType ;
2549+ if ("map" .equals (cm .containerType )) {
2550+ op .isMapContainer = true ;
2551+ } else if ("list" .equalsIgnoreCase (cm .containerType )) {
2552+ op .isListContainer = true ;
2553+ } else if ("array" .equalsIgnoreCase (cm .containerType )) {
2554+ op .isListContainer = true ;
2555+ }
2556+ } else {
2557+ op .returnSimpleType = true ;
2558+ }
2559+ if (languageSpecificPrimitives ().contains (op .returnBaseType ) || op .returnBaseType == null ) {
2560+ op .returnTypeIsPrimitive = true ;
2561+ }
2562+ }
2563+ addHeaders (methodResponse , op .responseHeaders );
2564+ }
2565+
24962566 /**
24972567 * Convert OAS Operation object to Codegen Operation object
24982568 *
@@ -2585,62 +2655,7 @@ public CodegenOperation fromOperation(String path,
25852655 op .responses .get (op .responses .size () - 1 ).hasMore = false ;
25862656
25872657 if (methodResponse != null ) {
2588- Schema responseSchema = ModelUtils .unaliasSchema (this .openAPI , ModelUtils .getSchemaFromResponse (methodResponse ));
2589-
2590- if (responseSchema != null ) {
2591- CodegenProperty cm = fromProperty ("response" , responseSchema );
2592-
2593- if (ModelUtils .isArraySchema (responseSchema )) {
2594- ArraySchema as = (ArraySchema ) responseSchema ;
2595- CodegenProperty innerProperty = fromProperty ("response" , getSchemaItems (as ));
2596- op .returnBaseType = innerProperty .baseType ;
2597- } else if (ModelUtils .isMapSchema (responseSchema )) {
2598- CodegenProperty innerProperty = fromProperty ("response" , ModelUtils .getAdditionalProperties (responseSchema ));
2599- op .returnBaseType = innerProperty .baseType ;
2600- } else {
2601- if (cm .complexType != null ) {
2602- op .returnBaseType = cm .complexType ;
2603- } else {
2604- op .returnBaseType = cm .baseType ;
2605- }
2606- }
2607-
2608- // generate examples
2609- String exampleStatusCode = "200" ;
2610- for (String key : operation .getResponses ().keySet ()) {
2611- if (operation .getResponses ().get (key ) == methodResponse && !key .equals ("default" )) {
2612- exampleStatusCode = key ;
2613- }
2614- }
2615- op .examples = new ExampleGenerator (schemas , this .openAPI ).generateFromResponseSchema (exampleStatusCode , responseSchema , getProducesInfo (this .openAPI , operation ));
2616- op .defaultResponse = toDefaultValue (responseSchema );
2617- op .returnType = cm .dataType ;
2618- op .hasReference = schemas .containsKey (op .returnBaseType );
2619-
2620- // lookup discriminator
2621- Schema schema = schemas .get (op .returnBaseType );
2622- if (schema != null ) {
2623- CodegenModel cmod = fromModel (op .returnBaseType , schema );
2624- op .discriminator = cmod .discriminator ;
2625- }
2626-
2627- if (cm .isContainer ) {
2628- op .returnContainer = cm .containerType ;
2629- if ("map" .equals (cm .containerType )) {
2630- op .isMapContainer = true ;
2631- } else if ("list" .equalsIgnoreCase (cm .containerType )) {
2632- op .isListContainer = true ;
2633- } else if ("array" .equalsIgnoreCase (cm .containerType )) {
2634- op .isListContainer = true ;
2635- }
2636- } else {
2637- op .returnSimpleType = true ;
2638- }
2639- if (languageSpecificPrimitives ().contains (op .returnBaseType ) || op .returnBaseType == null ) {
2640- op .returnTypeIsPrimitive = true ;
2641- }
2642- }
2643- addHeaders (methodResponse , op .responseHeaders );
2658+ handleMethodResponse (operation , schemas , op , methodResponse );
26442659 }
26452660 }
26462661
@@ -3511,7 +3526,7 @@ protected List<Map<String, Object>> toExamples(Map<String, Object> examples) {
35113526 * @param response API response
35123527 * @param properties list of codegen property
35133528 */
3514- private void addHeaders (ApiResponse response , List <CodegenProperty > properties ) {
3529+ protected void addHeaders (ApiResponse response , List <CodegenProperty > properties ) {
35153530 if (response .getHeaders () != null ) {
35163531 for (Map .Entry <String , Header > headerEntry : response .getHeaders ().entrySet ()) {
35173532 String description = headerEntry .getValue ().getDescription ();
@@ -4316,7 +4331,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
43164331 }
43174332 }
43184333
4319- private void updateEnumVarsWithExtensions (List <Map <String , Object >> enumVars , Map <String , Object > vendorExtensions ) {
4334+ protected void updateEnumVarsWithExtensions (List <Map <String , Object >> enumVars , Map <String , Object > vendorExtensions ) {
43204335 if (vendorExtensions != null ) {
43214336 updateEnumVarsWithExtensions (enumVars , vendorExtensions , "x-enum-varnames" , "name" );
43224337 updateEnumVarsWithExtensions (enumVars , vendorExtensions , "x-enum-descriptions" , "enumDescription" );
0 commit comments