Skip to content

Commit 888249b

Browse files
authored
Release 6.4.2 (bugfix) (acacode#206)
* feat: add "onFormatRouteName" hook * chore: try to add github workflows * chore: rename gh workflow file to main * chore: fix changelog after rebase * fix: bugs with missing `name` property in in-path requests parameters in swagger schemas * fix: problem with usage --route-types with --modular option * bump: up version to 6.4.2
1 parent 8354a4f commit 888249b

File tree

9 files changed

+295
-4
lines changed

9 files changed

+295
-4
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# next release
22

3+
# 6.4.2
4+
5+
Fixes:
6+
- Bug with missing `name` property in in-path requests parameters
7+
- Problem with usage `--route-types` with `--modular` option (mising import data contracts)
8+
39
# 6.4.1
410

511
Fixes:

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "6.4.1",
3+
"version": "6.4.2",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",

src/routes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ const getRouteParams = (routeInfo, pathParams) => {
207207
};
208208
}
209209

210-
if (routeParam.in === "path" && routeParam.name) {
210+
if (routeParam.in === "path") {
211+
if (!routeParam.name) return;
212+
211213
routeParam.name = _.camelCase(routeParam.name);
212214
}
213215

templates/base/route-types.eta

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<%
2-
const { utils, config, routes } = it;
2+
const { utils, config, routes, modelTypes } = it;
3+
const { _ } = utils;
4+
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
35
%>
6+
7+
<% if (dataContracts.length) { %>
8+
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
9+
<% } %>
10+
411
<%
512
/* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
613
%>

tests/generated/v3.0/explode-param-3.0.1.ts

+22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* ---------------------------------------------------------------
1010
*/
1111

12+
export interface Floop {
13+
info?: string;
14+
}
15+
1216
export interface QueryParams {
1317
/**
1418
* Page number
@@ -223,6 +227,24 @@ export class HttpClient<SecurityDataType = unknown> {
223227
* Documentation
224228
*/
225229
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
230+
user = {
231+
/**
232+
* No description
233+
*
234+
* @name CreateFile
235+
* @summary Some summary
236+
* @request POST:/{user}/foos
237+
*/
238+
createFile: (user: string, data: { meme: string; memeType?: string }, params: RequestParams = {}) =>
239+
this.request<Floop, any>({
240+
path: `/${user}/foos`,
241+
method: "POST",
242+
body: data,
243+
type: ContentType.Json,
244+
format: "json",
245+
...params,
246+
}),
247+
};
226248
something = {
227249
/**
228250
* No description

tests/schemas/v3.0/explode-param-3.0.1.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@ info:
44
description: Documentation
55
version: "0.1"
66
paths:
7+
"/{user}/foos":
8+
parameters:
9+
- schema:
10+
type: string
11+
user: blbalbla
12+
in: path
13+
required: true
14+
post:
15+
summary: Some summary
16+
operationId: createFile
17+
responses:
18+
"200":
19+
description: OK
20+
content:
21+
application/json:
22+
schema:
23+
$ref: "#/components/schemas/Floop"
24+
requestBody:
25+
content:
26+
application/json:
27+
schema:
28+
type: object
29+
properties:
30+
meme:
31+
type: string
32+
default: ""
33+
memeType:
34+
type: string
35+
required:
36+
- meme
37+
required: true
38+
description: ""
739
/something/:
840
get:
941
operationId: gets
@@ -17,6 +49,11 @@ paths:
1749

1850
components:
1951
schemas:
52+
Floop:
53+
type: object
54+
properties:
55+
info:
56+
type: string
2057
QueryParams:
2158
type: object
2259
properties:

tests/spec/modular/route-types.ts

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/* eslint-disable */
2+
/* tslint:disable */
3+
/*
4+
* ---------------------------------------------------------------
5+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
6+
* ## ##
7+
* ## AUTHOR: acacode ##
8+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
9+
* ---------------------------------------------------------------
10+
*/
11+
12+
import { AuthentiqID, Claims, PushToken } from "./data-contracts";
13+
14+
export namespace key {
15+
/**
16+
* @description Revoke an Authentiq ID using email & phone. If called with `email` and `phone` only, a verification code will be sent by email. Do a second call adding `code` to complete the revocation.
17+
* @tags key, delete
18+
* @name KeyRevokeNosecret
19+
* @request DELETE:/key
20+
*/
21+
export namespace KeyRevokeNosecret {
22+
export type RequestParams = {};
23+
export type RequestQuery = { email: string; phone: string; code?: string };
24+
export type RequestBody = never;
25+
export type RequestHeaders = {};
26+
export type ResponseBody = { status?: string };
27+
}
28+
/**
29+
* @description Register a new ID `JWT(sub, devtoken)` v5: `JWT(sub, pk, devtoken, ...)` See: https://github.com/skion/authentiq/wiki/JWT-Examples
30+
* @tags key, post
31+
* @name KeyRegister
32+
* @request POST:/key
33+
*/
34+
export namespace KeyRegister {
35+
export type RequestParams = {};
36+
export type RequestQuery = {};
37+
export type RequestBody = AuthentiqID;
38+
export type RequestHeaders = {};
39+
export type ResponseBody = { secret?: string; status?: string };
40+
}
41+
/**
42+
* @description Revoke an Identity (Key) with a revocation secret
43+
* @tags key, delete
44+
* @name KeyRevoke
45+
* @request DELETE:/key/{PK}
46+
*/
47+
export namespace KeyRevoke {
48+
export type RequestParams = { pk: string };
49+
export type RequestQuery = { secret: string };
50+
export type RequestBody = never;
51+
export type RequestHeaders = {};
52+
export type ResponseBody = { status?: string };
53+
}
54+
/**
55+
* @description Get public details of an Authentiq ID.
56+
* @tags key, get
57+
* @name GetKey
58+
* @request GET:/key/{PK}
59+
*/
60+
export namespace GetKey {
61+
export type RequestParams = { pk: string };
62+
export type RequestQuery = {};
63+
export type RequestBody = never;
64+
export type RequestHeaders = {};
65+
export type ResponseBody = { since?: string; status?: string; sub?: string };
66+
}
67+
/**
68+
* @description HEAD info on Authentiq ID
69+
* @tags key, head
70+
* @name HeadKey
71+
* @request HEAD:/key/{PK}
72+
*/
73+
export namespace HeadKey {
74+
export type RequestParams = { pk: string };
75+
export type RequestQuery = {};
76+
export type RequestBody = never;
77+
export type RequestHeaders = {};
78+
export type ResponseBody = void;
79+
}
80+
/**
81+
* @description update properties of an Authentiq ID. (not operational in v4; use PUT for now) v5: POST issuer-signed email & phone scopes in a self-signed JWT See: https://github.com/skion/authentiq/wiki/JWT-Examples
82+
* @tags key, post
83+
* @name KeyUpdate
84+
* @request POST:/key/{PK}
85+
*/
86+
export namespace KeyUpdate {
87+
export type RequestParams = { pk: string };
88+
export type RequestQuery = {};
89+
export type RequestBody = AuthentiqID;
90+
export type RequestHeaders = {};
91+
export type ResponseBody = { status?: string };
92+
}
93+
/**
94+
* @description Update Authentiq ID by replacing the object. v4: `JWT(sub,email,phone)` to bind email/phone hash; v5: POST issuer-signed email & phone scopes and PUT to update registration `JWT(sub, pk, devtoken, ...)` See: https://github.com/skion/authentiq/wiki/JWT-Examples
95+
* @tags key, put
96+
* @name KeyBind
97+
* @request PUT:/key/{PK}
98+
*/
99+
export namespace KeyBind {
100+
export type RequestParams = { pk: string };
101+
export type RequestQuery = {};
102+
export type RequestBody = AuthentiqID;
103+
export type RequestHeaders = {};
104+
export type ResponseBody = { status?: string };
105+
}
106+
}
107+
108+
export namespace login {
109+
/**
110+
* @description push sign-in request See: https://github.com/skion/authentiq/wiki/JWT-Examples
111+
* @tags login, post
112+
* @name PushLoginRequest
113+
* @request POST:/login
114+
*/
115+
export namespace PushLoginRequest {
116+
export type RequestParams = {};
117+
export type RequestQuery = { callback: string };
118+
export type RequestBody = PushToken;
119+
export type RequestHeaders = {};
120+
export type ResponseBody = { status?: string };
121+
}
122+
/**
123+
* @description Get a current key register
124+
* @tags key, get
125+
* @name KeyRegister
126+
* @request GET:/login
127+
*/
128+
export namespace KeyRegister {
129+
export type RequestParams = {};
130+
export type RequestQuery = {};
131+
export type RequestBody = never;
132+
export type RequestHeaders = {};
133+
export type ResponseBody = { secret?: string; status?: string };
134+
}
135+
}
136+
137+
export namespace scope {
138+
/**
139+
* @description scope verification request See: https://github.com/skion/authentiq/wiki/JWT-Examples
140+
* @tags scope, post
141+
* @name SignRequest
142+
* @request POST:/scope
143+
*/
144+
export namespace SignRequest {
145+
export type RequestParams = {};
146+
export type RequestQuery = { test?: number };
147+
export type RequestBody = Claims;
148+
export type RequestHeaders = {};
149+
export type ResponseBody = { job?: string; status?: string };
150+
}
151+
/**
152+
* @description delete a verification job
153+
* @tags scope, delete
154+
* @name SignDelete
155+
* @request DELETE:/scope/{job}
156+
*/
157+
export namespace SignDelete {
158+
export type RequestParams = { job: string };
159+
export type RequestQuery = {};
160+
export type RequestBody = never;
161+
export type RequestHeaders = {};
162+
export type ResponseBody = { status?: string };
163+
}
164+
/**
165+
* @description get the status / current content of a verification job
166+
* @tags scope, get
167+
* @name SignRetrieve
168+
* @request GET:/scope/{job}
169+
*/
170+
export namespace SignRetrieve {
171+
export type RequestParams = { job: string };
172+
export type RequestQuery = {};
173+
export type RequestBody = never;
174+
export type RequestHeaders = {};
175+
export type ResponseBody = { exp?: number; field?: string; sub?: string };
176+
}
177+
/**
178+
* @description HEAD to get the status of a verification job
179+
* @tags scope, head
180+
* @name SignRetrieveHead
181+
* @request HEAD:/scope/{job}
182+
*/
183+
export namespace SignRetrieveHead {
184+
export type RequestParams = { job: string };
185+
export type RequestQuery = {};
186+
export type RequestBody = never;
187+
export type RequestHeaders = {};
188+
export type ResponseBody = void;
189+
}
190+
/**
191+
* @description this is a scope confirmation
192+
* @tags scope, post
193+
* @name SignConfirm
194+
* @request POST:/scope/{job}
195+
*/
196+
export namespace SignConfirm {
197+
export type RequestParams = { job: string };
198+
export type RequestQuery = {};
199+
export type RequestBody = never;
200+
export type RequestHeaders = {};
201+
export type ResponseBody = { status?: string };
202+
}
203+
/**
204+
* @description authority updates a JWT with its signature See: https://github.com/skion/authentiq/wiki/JWT-Examples
205+
* @tags scope, put
206+
* @name SignUpdate
207+
* @request PUT:/scope/{job}
208+
*/
209+
export namespace SignUpdate {
210+
export type RequestParams = { job: string };
211+
export type RequestQuery = {};
212+
export type RequestBody = never;
213+
export type RequestHeaders = {};
214+
export type ResponseBody = { jwt?: string; status?: string };
215+
}
216+
}

tests/spec/modular/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ schemas.forEach(({ absolutePath }) => {
1212
output: resolve(__dirname, "./"),
1313
modular: true,
1414
generateClient: true,
15+
generateRouteTypes: true,
1516
})
1617
.then(() => {
1718
const diagnostics = [

0 commit comments

Comments
 (0)