swagger-api / swagger-api/swagger-codegen
[typescript-angular] Generated APIs contain errors (angular 7.2.0)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The code for the generated API services contain TSLINT errors and a comiplation error.
The generated code has a lot of the following:
-
let httpHeaderAccepts: string[]should beconst httpHeaderAccepts: string[]since its not modified afterwards. -
if (httpHeaderAcceptSelected != undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); }should beif (httpHeaderAcceptSelected !== undefined) { headers = headers.set('Accept', httpHeaderAcceptSelected); } -
if (httpContentTypeSelected != undefined) { headers = headers.set('Content-Type', httpContentTypeSelected); }should beif (httpContentTypeSelected !== undefined) { headers = headers.set('Content-Type', httpContentTypeSelected); } -
return this.httpClient.post<any>(${this.basePath}/pet, body, { withCredentials: this.configuration.withCredentials, headers: headers, observe: observe, reportProgress: reportProgress } );don't know why but it keeps givving me the following error on headers, observe and reportProgress: TSLint: Expected property shorthand in object literal ('{reportProgress}'). (object-literal-shorthand) -
And finally the compilation error:
formParams = formParams.append('name', <any>name) || formParams;Error: ERROR in ../pet.service.ts(451,26): error TS1345: An expression of type 'void' cannot be tested for truthiness
Swagger-codegen version
2.4.2
Swagger declaration file content or url
The standard pet store swagger file used in all their examples.
https://petstore.swagger.io/v2/swagger.json
Command line used for generation
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${swaggerContractsDirectory}/swagger.json</inputSpec>
<language>typescript-angular</language>
<output>${swaggerOutputDirectory}</output>
<configOptions>
<ngVersion>7.2.0</ngVersion>
<providedInRoot>true</providedInRoot>
</configOptions>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateModelDocumentation>false</generateModelDocumentation>
<supportingFilesToGenerate>variables.ts,configuration.ts,encoder.ts</supportingFilesToGenerate>
<!--<generateSupportingFiles>false</generateSupportingFiles>-->
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Execute a mvn clean install on the pom containing the code above
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 reproducing the generated TypeScript Angular client from the standard Pet Store Swagger file using the Maven configuration in the issue, then inspect the typescript-angular generator output responsible for the generated API services. Done means the generated services compile under Angular 7.2.0 and no longer produce the reported TSLint errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100