Skip to content

Commit

Permalink
Merge branch 'fix/ng2-issues'
Browse files Browse the repository at this point in the history
  • Loading branch information
yhnavein committed Oct 21, 2023
2 parents 38b526c + 0542f66 commit a121df1
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 108 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Instead of writing any code by hand for fetching particular resources, we will l
prettier ./FILE_PATH.ts --write
```

[dprint](https://dprint.dev/cli/) - the superfast one
[dprint](https://dprint.dev/cli/) - the super fast one

```sh
dprint fmt ./FILE_PATH.ts
Expand Down Expand Up @@ -215,7 +215,7 @@ Quick comparison table:

| swaggie | NSwag |
| --------------------------------------------------------------- | ----------------------------------------------------------- |
| - Written in node.js | - Written in .NET |
| - Written in node.js + TypeScript | - Written in .NET |
| - Fast | - Slow |
| - ![swaggie size](https://packagephobia.now.sh/badge?p=swaggie) | - ![nswag size](https://packagephobia.now.sh/badge?p=nswag) |
| - Easy to contribute to | - Contributing hard |
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swaggie",
"version": "0.8.1",
"version": "0.8.2",
"description": "Generate ES6 or TypeScript service integration code from an OpenAPI spec",
"author": {
"name": "Piotr Dabrowski",
Expand Down Expand Up @@ -52,15 +52,15 @@
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/chai": "4.3.5",
"@types/js-yaml": "4.0.5",
"@types/mocha": "10.0.1",
"@types/node-fetch": "2.6.4",
"@types/sinon": "^10.0.16",
"chai": "4.3.7",
"@types/chai": "4.3.9",
"@types/js-yaml": "4.0.8",
"@types/mocha": "10.0.3",
"@types/node-fetch": "2.6.7",
"@types/sinon": "^10.0.20",
"chai": "4.3.10",
"mocha": "10.2.0",
"sinon": "^15.2.0",
"sinon": "^17.0.0",
"sucrase": "3.34.0",
"typescript": "5.1.6"
"typescript": "5.2.2"
}
}
9 changes: 4 additions & 5 deletions src/gen/templateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('loadAllTemplateFiles', () => {
it('should load template file to the memory', async () => {
loadAllTemplateFiles('axios');

const cachedTemplate = Eta.templates.get("client.ejs")
const cachedTemplate = Eta.templates.get('client.ejs');
expect(cachedTemplate).to.be.a('function');
});
});
Expand Down Expand Up @@ -78,7 +78,6 @@ describe('render', () => {
});
});


describe('custom templates', () => {
const tempDir = `${os.tmpdir()}/custom-template`;

Expand All @@ -89,14 +88,14 @@ describe('custom templates', () => {

fs.copyFileSync(
path.join(__dirname, '..', '..', 'templates', 'fetch', 'client.ejs'),
path.join(tempDir, 'client.ejs'),
path.join(tempDir, 'client.ejs')
);

loadAllTemplateFiles(tempDir);
});

it('should handle custom template', async () => {
const templateFunction = await renderFile('client.ejs', {
it('should handle custom template', () => {
const templateFunction = renderFile('client.ejs', {
clientName: 'Test',
camelCaseName: 'test',
baseUrl: null,
Expand Down
20 changes: 10 additions & 10 deletions templates/ng2/baseClient.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,54 @@

import { Observable, throwError as _observableThrow, of as _observableOf } from "rxjs";
import { Injectable, Inject, Optional, InjectionToken } from "@angular/core";
import { HttpClient, HttpHeaders, HttpResponse, HttpResponseBase } from "@angular/common/http";
import { HttpClient, HttpHeaders, HttpResponse, HttpResponseBase } from "@angular/common/httpClient";

export const <%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL = new InjectionToken<string>("<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL");

abstract class BaseService {
private http: HttpClient;
private httpClient: HttpClient;
private baseUrl: string;

constructor(
@Inject(HttpClient) http: HttpClient,
@Inject(HttpClient) httpClient: HttpClient,
@Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string
) {
this.http = http;
this.httpClient = httpClient;
this.baseUrl = baseUrl ? baseUrl : '';
}

protected $get<T>(url: string, options?: any): Observable<T> {
return this.http
return this.httpClient
.get<T>(this.baseUrl + url, options)
.pipe((response: any) => response);
}

protected $getAll<T>(url: string, options?: any): Observable<T[]> {
return this.http
return this.httpClient
.get<T[]>(this.baseUrl + url, options)
.pipe((response: any) => response);
}

protected $delete<T>(url: string, options?: any): Observable<T> {
return this.http
return this.httpClient
.delete(this.baseUrl + url, options)
.pipe((response: any) => response);
}

protected $post(url: string, data: any, options?: any): Observable<any> {
return this.http
return this.httpClient
.post(this.baseUrl + url, data, options)
.pipe((response: any) => response);
}

protected $patch<T>(url: string, data: any, options?: any): Observable<T> {
return this.http
return this.httpClient
.patch(this.baseUrl + url, data, options)
.pipe((response: any) => response);
}

protected $put(url: string, data: any, options?: any): Observable<any> {
return this.http
return this.httpClient
.put(this.baseUrl + url, data, options)
.pipe((response: any) => response);
}
Expand Down
4 changes: 2 additions & 2 deletions templates/ng2/client.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
})
export class <%= it.clientName -%>Service extends BaseService {
constructor(
@Inject(HttpClient) http: HttpClient,
@Inject(HttpClient) httpClient: HttpClient,
@Optional() @Inject(<%= (it.servicePrefix || 'API').toUpperCase() -%>_BASE_URL) baseUrl?: string
) {
super(http, baseUrl);
super(httpClient, baseUrl);
}

<% it.operations.forEach((operation) => { %>
Expand Down
2 changes: 1 addition & 1 deletion templates/ng2/operation.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
<%= it.name %>(
<% it.parameters.forEach((parameter) => { %>
<%= parameter.name %>: <%= parameter.type %><%= parameter.optional ? ' | null | undefined' : '' %>,
<%= parameter.name %>: <%~ parameter.type %><%= parameter.optional ? ' | null | undefined' : '' %>,
<% }); %>
config?: any
): Observable<<%~ it.returnType %>> {
Expand Down
Loading

0 comments on commit a121df1

Please sign in to comment.