question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated files with angular client undefined.ts

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ferdikoomencommented, Feb 7, 2022

@smarlhens It seems related to the command:

npx -y openapi-typescript-codegen@0.19.0 --input ./v3.json --output projects/api/src --useOptions --indent 2 -c angular --postfix Service

You dont need the “=” character in the parameters and you should use forward slashes for paths

1reaction
ferdikoomencommented, Feb 7, 2022

@smarlhens I pushed a new version 0.19.0, that should have support for the --name param. It’s exporting an Angular NgModule with all the services as providers and injects the OpenAPI configuration object once.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found