swagger-api / swagger-api/swagger-codegen
[typescript-angular] replace Error with rxjs throwError if a parameter is missing
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If RxJS6 is used, the current method still has to use try-catch block.
public addPet(body: Pet, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling addPet.');
}
}
try {
addPet(null).pipe(catchError(e => {
console.log(e);
return EMPTY;
})).subscribe();
} catch (e) {
console.log("Exception", e);
}
However, if throwError is used in RxJS6, api request can be simplified.
public addPet(body: SwgPetHa, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (body === null || body === undefined) {
return throwError('Required parameter body was null or undefined when calling addPet.');
}
}
addPet(null).pipe(catchError(e => {
console.log(e);
return EMPTY;
})).subscribe();
Swagger-codegen version
Swagger Codegen 2.X
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the TypeScript Angular templates or generator entry points that emit the required-parameter checks shown in the issue. Review how the generated addPet method handles a missing body with RxJS 6, then verify that the generated client reports the error through the observable flow without requiring an outer try-catch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100