Skip to content

Commit b5d3d50

Browse files
authored
Release 6.1.1 (Bugfix) (#186)
* internal: beatify output for spec tests * docs: update title text in README * bump: 6.1.1 version; fix: --axios, --modular options
1 parent 9621fed commit b5d3d50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+29245
-75
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# next release
22

3+
# 6.1.1
4+
5+
Fixes:
6+
- Problems with `--axios` option
7+
- ignoring `path`, `format`, `type` payload properties in `request()` method of `HttpClient`
8+
- Missing `format` property for requests in `--modular` option
9+
10+
# 6.1.0
11+
312
Features:
413
- `--silent` option. Output only errors to console (default: false)
514

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
Generate api via swagger scheme.
1313
Supports OA 3.0, 2.0, JSON, yaml
14-
Generated api module use [**Fetch Api**](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make requests.
14+
Generated api module use [**Fetch Api**](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) or [**Axios**](https://github.com/axios/axios) to make requests.
1515

1616
<br>
1717
<br>

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "6.1.0",
3+
"version": "6.1.1",
44
"description": "Create typescript api module from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts --extract-request-params --enum-names-as-values",
@@ -32,6 +32,7 @@
3232
"test:--js": "node tests/spec/js/test.js",
3333
"test:--js--axios": "node tests/spec/jsAxios/test.js",
3434
"test:--axios": "node tests/spec/axios/test.js",
35+
"test:--axios--single-http-client": "node tests/spec/axiosSingleHttpClient/test.js",
3536
"test:partialBaseTemplate": "node tests/spec/partialBaseTemplate/test.js",
3637
"test:partialDefaultTemplate": "node tests/spec/partialDefaultTemplate/test.js"
3738
},

templates/base/http-clients/axios-http-client.eta

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<%
22
const { apiConfig, generateResponses } = it;
33
%>
4-
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";
4+
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from "axios";
55

66
export type QueryParamsType = Record<string | number, any>;
7-
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
87

9-
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params"> {
8+
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
109
/** set parameter to `true` for call `securityWorker` for this request */
1110
secure?: boolean;
1211
/** request path */
@@ -16,7 +15,7 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "pa
1615
/** query params */
1716
query?: QueryParamsType;
1817
/** format of response (i.e. response.json() -> format: "json") */
19-
format?: keyof Omit<Body, "body" | "bodyUsed">;
18+
format?: ResponseType;
2019
/** request body */
2120
body?: unknown;
2221
}
@@ -77,7 +76,9 @@ export class HttpClient<SecurityDataType = unknown> {
7776
...(requestParams.headers || {}),
7877
},
7978
params: query,
79+
responseType: format,
8080
data: body,
81+
url: path,
8182
});
8283
};
8384
}

templates/base/http-clients/fetch-http-client.eta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface FullRequestParams extends Omit<RequestInit, "body"> {
1515
/** query params */
1616
query?: QueryParamsType;
1717
/** format of response (i.e. response.json() -> format: "json") */
18-
format?: keyof Omit<Body, "body" | "bodyUsed">;
18+
format?: ResponseFormat;
1919
/** request body */
2020
body?: unknown;
2121
/** base url */

templates/default/procedure-call.eta

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { type, errorType, contentTypes } = route.response;
77
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
88
const queryName = (query && query.name) || "query";
99
const pathParams = _.values(parameters);
10+
const isFetchTemplate = config.httpClientType === config.constants.HTTP_CLIENT.FETCH;
1011

1112
const requestConfigParam = {
1213
name: pathParams.some((pathArg) => pathArg.name === "params") ? "requestParams" : "params",
@@ -51,7 +52,7 @@ const requestContentKind = {
5152
const responseContentKind = {
5253
"JSON": '"json"',
5354
"IMAGE": '"blob"',
54-
"FORM_DATA": '"formData"'
55+
"FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
5556
}
5657

5758
const bodyTmpl = _.get(payload, "name") || null;

templates/modular/procedure-call.eta

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { type, errorType, contentTypes } = route.response;
77
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
88
const queryName = (query && query.name) || "query";
99
const pathParams = _.values(parameters);
10+
const isFetchTemplate = config.httpClientType === config.constants.HTTP_CLIENT.FETCH;
1011

1112
const requestConfigParam = {
1213
name: pathParams.some((pathArg) => pathArg.name === "params") ? "requestParams" : "params",
@@ -51,7 +52,7 @@ const requestContentKind = {
5152
const responseContentKind = {
5253
"JSON": '"json"',
5354
"IMAGE": '"blob"',
54-
"FORM_DATA": '"formData"'
55+
"FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
5556
}
5657

5758
const bodyTmpl = _.get(payload, "name") || null;
@@ -90,5 +91,6 @@ const describeReturnType = () => {
9091
<%~ bodyTmpl ? `body: ${bodyTmpl},` : '' %>
9192
<%~ securityTmpl ? `secure: ${securityTmpl},` : '' %>
9293
<%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
94+
<%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
9395
...<%~ _.get(requestConfigParam, "name") %>,
9496
})

tests/generated/v2.0/adafruit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export interface FullRequestParams extends Omit<RequestInit, "body"> {
177177
/** query params */
178178
query?: QueryParamsType;
179179
/** format of response (i.e. response.json() -> format: "json") */
180-
format?: keyof Omit<Body, "body" | "bodyUsed">;
180+
format?: ResponseFormat;
181181
/** request body */
182182
body?: unknown;
183183
/** base url */

tests/generated/v2.0/another-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export interface FullRequestParams extends Omit<RequestInit, "body"> {
153153
/** query params */
154154
query?: QueryParamsType;
155155
/** format of response (i.e. response.json() -> format: "json") */
156-
format?: keyof Omit<Body, "body" | "bodyUsed">;
156+
format?: ResponseFormat;
157157
/** request body */
158158
body?: unknown;
159159
/** base url */

0 commit comments

Comments
 (0)