Skip to content

Commit

Permalink
Merge pull request #330 from hey-api/fix/some-formatting-issues
Browse files Browse the repository at this point in the history
fix: cleanup some styling issues when generating client without forma…
  • Loading branch information
jordanshatford authored Apr 10, 2024
2 parents 8305346 + 8bc753c commit 598bc2a
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-humans-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix: cleanup some styling issues when generating client without formatting
10 changes: 6 additions & 4 deletions packages/openapi-ts/src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export class TypeScriptFile {
}

public toString(seperator: string = '\n') {
const importsString = this._imports.map(v => tsNodeToString(v)).join('\n');
return [importsString, ...this._items.map(v => (typeof v === 'string' ? v : tsNodeToString(v)))].join(
seperator
);
const values: string[] = [];
if (this._imports.length) {
values.push(this._imports.map(v => tsNodeToString(v)).join('\n'));
}
values.push(...this._items.map(v => (typeof v === 'string' ? v : tsNodeToString(v))))
return values.join(seperator);
}

public write(file: PathOrFileDescriptor, seperator: string = '\n') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const getRequestBody = (options: ApiRequestOptions): unknown => {
if (options.body) {
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
return JSON.stringify(options.body)
return JSON.stringify(options.body);
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
return options.body;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/core/angular/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: Api
}),
switchMap(async response => {
for (const fn of config.interceptors.response._fns) {
response = await fn(response)
response = await fn(response);
}
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/core/axios/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, ax
let response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);

for (const fn of config.interceptors.response._fns) {
response = await fn(response)
response = await fn(response);
}

const responseBody = getResponseBody(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const sendRequest = async <T>(
onCancel(() => controller.abort());

for (const fn of config.interceptors.request._fns) {
requestConfig = await fn(requestConfig)
requestConfig = await fn(requestConfig);
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const getRequestBody = (options: ApiRequestOptions): unknown => {
if (options.body !== undefined) {
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
return JSON.stringify(options.body)
return JSON.stringify(options.body);
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
return options.body;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/core/fetch/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);

for (const fn of config.interceptors.response._fns) {
response = await fn(response)
response = await fn(response);
}

const responseBody = await getResponseBody(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const sendRequest = async (
{{/equals}}

for (const fn of config.interceptors.request._fns) {
request = await fn(request)
request = await fn(request);
}

onCancel(() => controller.abort());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const getRequestBody = (options: ApiRequestOptions): unknown => {
if (options.body !== undefined) {
if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
return JSON.stringify(options.body)
return JSON.stringify(options.body);
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
return options.body;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/core/xhr/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
let response = await sendRequest(config, options, url, body, formData, headers, onCancel);

for (const fn of config.interceptors.response._fns) {
response = await fn(response)
response = await fn(response);
}

const responseBody = getResponseBody(response);
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/templates/core/xhr/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const sendRequest = async (
xhr.onerror = () => reject(new Error('Network error'));

for (const fn of config.interceptors.request._fns) {
xhr = await fn(xhr)
xhr = await fn(xhr);
}

xhr.send(body ?? formData);
Expand Down
5 changes: 2 additions & 3 deletions packages/openapi-ts/src/templates/exportService.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
{{/equals}}
export class {{{name}}}{{{@root.$config.postfixServices}}} {
{{#if @root.$config.name}}

constructor(public readonly httpRequest: BaseHttpRequest) {}

{{else}}
{{#equals @root.$config.client 'angular'}}

constructor(public readonly http: HttpClient) {}

{{/equals}}
{{/if}}

{{#each operations}}
/**
{{#if deprecated}}
Expand Down

0 comments on commit 598bc2a

Please sign in to comment.