Generated files with angular client undefined.ts
See original GitHub issueDescribe the bug
Description | Value |
---|---|
Usage | npx |
Version | 0.18.2 |
Client | Angular |
@angular/common | 13.2.1 |
@angular/core | 13.2.1 |
rxjs | 7.5.2 |
When using following command in an angular project as a library :
npx -y openapi-typescript-codegen@0.18.2 --input ./v3.json --output projects\api\src --useOptions --indent=2 -c=angular --name=FooBarClient --postfix=Service
I’ve used the v3.json from samples folder.
I’m getting the following:
projects/api/src/client.ts
import type { BaseHttpRequest } from './core/BaseHttpRequest';
import type { OpenAPIConfig } from './core/OpenAPI';
import { } from './core/'; // <==== here ⚠️
import { PetService } from './services/PetService';
import { StoreService } from './services/StoreService';
import { UserService } from './services/UserService';
type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
export class FooBarClient {
public readonly pet: PetService;
public readonly store: StoreService;
public readonly user: UserService;
public readonly request: BaseHttpRequest;
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = ) { // <==== here ⚠️
this.request = new HttpRequest({
BASE: config?.BASE ?? '/api/v3',
VERSION: config?.VERSION ?? '1.0.4',
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
CREDENTIALS: config?.CREDENTIALS ?? 'include',
TOKEN: config?.TOKEN,
USERNAME: config?.USERNAME,
PASSWORD: config?.PASSWORD,
HEADERS: config?.HEADERS,
ENCODE_PATH: config?.ENCODE_PATH,
});
this.pet = new PetService(this.request);
this.store = new StoreService(this.request);
this.user = new UserService(this.request);
}
}
projects/api/src/core/request.ts
// empty file ⚠️
projects/api/src/core/undefined.ts
import type { ApiRequestOptions } from './ApiRequestOptions';
import { BaseHttpRequest } from './BaseHttpRequest';
import type { CancelablePromise } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';
import { request as __request } from './request';
export class extends BaseHttpRequest { // <==== here ⚠️
constructor(config: OpenAPIConfig) {
super(config);
}
/**
* Request method
* @param options The request options from the service
* @returns CancelablePromise<T>
* @throws ApiError
*/
public request<T>(options: ApiRequestOptions): CancelablePromise<T> {
return __request(this.config, options);
}
}
I’ve also tried with one of my own OpenAPI v3 JSON specification file and I’m getting the same.
Can you help me on that ? Have I missed something ?
PS: I’ve in my src/app a core folder. Hope it does not create any conflict 👀 .
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Angular 5 + Swagger Codegen && Strict Null Checks
I tried to exclude generated swagger files in tslint.json and tsconfig extensions as well with no luck. Is there a way to set...
Read more >Undefined Apollo service in Apollo Angular queries/mutations
Describe the bug When using auto-generated queries or mutations, Mutation.apollo is undefined: in fesm5 ng.apollo.js: mutate(variables, ...
Read more >Basics of testing components - Angular
app/dashboard/dashboard-hero.component.spec.ts (class tests) ... It also generates an initial test file for the component, banner-external.component.spec.ts ...
Read more >Integrating GraphQL Code Generator in your frontend ...
In this article we'll try to explain and demonstrate common patterns for frontend development with GraphQL and GraphQL Code Generator.
Read more >API - esbuild
echo 'let x: number = 1' > in.tsesbuild in.ts --outfile=out.jscat out.jslet x = 1; ... This sets the output format for the generated...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@smarlhens It seems related to the command:
You dont need the “=” character in the parameters and you should use forward slashes for paths
@smarlhens I pushed a new version
0.19.0
, that should have support for the--name
param. It’s exporting an AngularNgModule
with all the services as providers and injects the OpenAPI configuration object once.