-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[TS][Angular] better handling of multiple responses #13426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,10 @@ | |
|
|
||
| package org.openapitools.codegen.languages; | ||
|
|
||
| import io.swagger.v3.oas.models.Operation; | ||
| import io.swagger.v3.oas.models.media.Schema; | ||
| import io.swagger.v3.oas.models.responses.ApiResponse; | ||
|
|
||
| import org.openapitools.codegen.*; | ||
| import org.openapitools.codegen.meta.features.DocumentationFeature; | ||
| import org.openapitools.codegen.meta.features.GlobalFeature; | ||
|
|
@@ -394,6 +397,25 @@ private String applyLocalTypeMapping(String type) { | |
| return type; | ||
| } | ||
|
|
||
| @Override | ||
| protected void handleMethodResponse(final Operation operation, final Map<String, Schema> schemas, final CodegenOperation op, final ApiResponse methodResponse, final Map<String, String> importMappings) { | ||
| super.handleMethodResponse(operation, schemas, op, methodResponse, importMappings); | ||
|
|
||
| if (op.responses != null && op.responses.size() > 1) { | ||
| String returnType = ""; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please simplify the code by using an |
||
| for (CodegenResponse codegenResponse : op.responses) { | ||
| if (returnType.length() > 0 && codegenResponse.dataType != null) { | ||
| returnType = returnType + "|" + codegenResponse.dataType; | ||
| } else if (codegenResponse.dataType != null) { | ||
| returnType = codegenResponse.dataType; | ||
| } | ||
| } | ||
| if (returnType.length() > 0) { | ||
| op.returnType = returnType; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void postProcessParameter(CodegenParameter parameter) { | ||
| super.postProcessParameter(parameter); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ import { Observable } from 'rxjs'; | |
|
|
||
| // @ts-ignore | ||
| import { ComplexParams } from '../model/complexParams'; | ||
| // @ts-ignore | ||
| import { ConflictResponse } from '../model/conflictResponse'; | ||
|
|
||
| // @ts-ignore | ||
| import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; | ||
|
|
@@ -96,17 +98,18 @@ export class MatrixParamsService { | |
| * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. | ||
| * @param reportProgress flag to report request and response progress. | ||
| */ | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<any>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<HttpResponse<any>>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<HttpEvent<any>>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<any> { | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<ConflictResponse>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<ConflictResponse>>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<ConflictResponse>>; | ||
| public complexMatrixParamExploded(matrixParamExploded?: ComplexParams, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ToppScorer could you please provide a usage example? Or perhaps I am missing the point completely?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upon further review, you're completely right. This should only consider the 2xx responses. Unfortunately the issues microsoft/TypeScript#13219 and ReactiveX/rxjs#2646 are not resolved yet. So we have no options to have a typed error response. I'm trying to change that asap. (For our project we will still use it, to have at least an indication of the potential error model). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any updates on this? Above linked issues are closed. |
||
|
|
||
| let localVarHeaders = this.defaultHeaders; | ||
|
|
||
| let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; | ||
| if (localVarHttpHeaderAcceptSelected === undefined) { | ||
| // to determine the Accept header | ||
| const httpHeaderAccepts: string[] = [ | ||
| 'application/json' | ||
| ]; | ||
| localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); | ||
| } | ||
|
|
@@ -132,7 +135,7 @@ export class MatrixParamsService { | |
| } | ||
|
|
||
| let localVarPath = `/complexMatrixParamExploded${this.configuration.encodeParam({name: "matrixParamExploded", value: matrixParamExploded, in: "path", style: "matrix", explode: true, dataType: "ComplexParams", dataFormat: undefined})}`; | ||
| return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`, | ||
| return this.httpClient.request<ConflictResponse>('put', `${this.configuration.basePath}${localVarPath}`, | ||
| { | ||
| context: localVarHttpContext, | ||
| responseType: <any>responseType_, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Path Parameter Stuff | ||
| * This API shows the usage of various path parameter styles | ||
| * | ||
| * The version of the OpenAPI document: 1.0.0 | ||
| * | ||
| * | ||
| * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
| * https://openapi-generator.tech | ||
| * Do not edit the class manually. | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * Conflict response | ||
| */ | ||
| export interface ConflictResponse { | ||
| detail: string; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './complexParams'; | ||
| export * from './conflictResponse'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment with an example what this part of the code handles