swagger-api / swagger-api/swagger-codegen
typescript-fetch strict compile errors for BaseApi and RequiredError with tsconfig.json strict = true
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am compiling our swagger definition which is passing validation (valid json). The codegen tool typescript-fetch works as expected and generates the required output. I can run the project as expected with typescript setting tsconfig.json property strict set to false. I would prefer to leave strict set to true as the rest of our project is well formed.
These are the following errors we receive:
ERROR in D:/Development/alloy-vue/src/commons/api/api.ts
58:15 Property 'configuration' has no initializer and is not definitely assigned in the constructor.
56 | */
57 | export class BaseAPI {
> 58 | protected configuration: Configuration;
| ^
59 |
60 | constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = portableFetch) {
61 | if (configuration) {
ERROR in D:/Development/alloy-vue/src/commons/api/api.ts
75:5 Property 'name' has no initializer and is not definitely assigned in the constructor.
73 | */
74 | export class RequiredError extends Error {
> 75 | name: "RequiredError"
| ^
76 | constructor(public field: string, msg?: string) {
77 | super(msg);
78 | }
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Link to swagger json
https://gist.github.com/fungus1487/bfd56c4dbae372e90f4a3be83068824e
Command line used for generation
java -jar swagger-codegen-cli-2.3.1.jar generate -i "url of json" -l typescript-fetch -o ./out
Steps to reproduce
Simply compile the linked json with typescript-fetch and enable strict property in tsconfig.json
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
Generate the linked Swagger JSON with the typescript-fetch target, then compile the output with tsconfig.json strict enabled and inspect api.ts, especially BaseAPI and RequiredError. Done means the generated client compiles without the reported strict-property-initialization errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100