Skip to content

Commit

Permalink
Release 6.4.2 (bugfix) (#206)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
js2me authored Mar 9, 2021
1 parent 8354a4f commit 888249b
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next release

# 6.4.2

Fixes:
- Bug with missing `name` property in in-path requests parameters
- Problem with usage `--route-types` with `--modular` option (mising import data contracts)

# 6.4.1

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-typescript-api",
"version": "6.4.1",
"version": "6.4.2",
"description": "Generate typescript/javascript api from swagger schema",
"scripts": {
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
Expand Down
4 changes: 3 additions & 1 deletion src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ const getRouteParams = (routeInfo, pathParams) => {
};
}

if (routeParam.in === "path" && routeParam.name) {
if (routeParam.in === "path") {
if (!routeParam.name) return;

routeParam.name = _.camelCase(routeParam.name);
}

Expand Down
9 changes: 8 additions & 1 deletion templates/base/route-types.eta
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<%
const { utils, config, routes } = it;
const { utils, config, routes, modelTypes } = it;
const { _ } = utils;
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
%>

<% if (dataContracts.length) { %>
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
<% } %>

<%
/* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
%>
Expand Down
22 changes: 22 additions & 0 deletions tests/generated/v3.0/explode-param-3.0.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* ---------------------------------------------------------------
*/

export interface Floop {
info?: string;
}

export interface QueryParams {
/**
* Page number
Expand Down Expand Up @@ -223,6 +227,24 @@ export class HttpClient<SecurityDataType = unknown> {
* Documentation
*/
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
user = {
/**
* No description
*
* @name CreateFile
* @summary Some summary
* @request POST:/{user}/foos
*/
createFile: (user: string, data: { meme: string; memeType?: string }, params: RequestParams = {}) =>
this.request<Floop, any>({
path: `/${user}/foos`,
method: "POST",
body: data,
type: ContentType.Json,
format: "json",
...params,
}),
};
something = {
/**
* No description
Expand Down
37 changes: 37 additions & 0 deletions tests/schemas/v3.0/explode-param-3.0.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@ info:
description: Documentation
version: "0.1"
paths:
"/{user}/foos":
parameters:
- schema:
type: string
user: blbalbla
in: path
required: true
post:
summary: Some summary
operationId: createFile
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Floop"
requestBody:
content:
application/json:
schema:
type: object
properties:
meme:
type: string
default: ""
memeType:
type: string
required:
- meme
required: true
description: ""
/something/:
get:
operationId: gets
Expand All @@ -17,6 +49,11 @@ paths:

components:
schemas:
Floop:
type: object
properties:
info:
type: string
QueryParams:
type: object
properties:
Expand Down
216 changes: 216 additions & 0 deletions tests/spec/modular/route-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/* eslint-disable */
/* tslint:disable */
/*
* ---------------------------------------------------------------
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
* ## ##
* ## AUTHOR: acacode ##
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
* ---------------------------------------------------------------
*/

import { AuthentiqID, Claims, PushToken } from "./data-contracts";

export namespace key {
/**
* @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.
* @tags key, delete
* @name KeyRevokeNosecret
* @request DELETE:/key
*/
export namespace KeyRevokeNosecret {
export type RequestParams = {};
export type RequestQuery = { email: string; phone: string; code?: string };
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @description Register a new ID `JWT(sub, devtoken)` v5: `JWT(sub, pk, devtoken, ...)` See: https://github.com/skion/authentiq/wiki/JWT-Examples
* @tags key, post
* @name KeyRegister
* @request POST:/key
*/
export namespace KeyRegister {
export type RequestParams = {};
export type RequestQuery = {};
export type RequestBody = AuthentiqID;
export type RequestHeaders = {};
export type ResponseBody = { secret?: string; status?: string };
}
/**
* @description Revoke an Identity (Key) with a revocation secret
* @tags key, delete
* @name KeyRevoke
* @request DELETE:/key/{PK}
*/
export namespace KeyRevoke {
export type RequestParams = { pk: string };
export type RequestQuery = { secret: string };
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @description Get public details of an Authentiq ID.
* @tags key, get
* @name GetKey
* @request GET:/key/{PK}
*/
export namespace GetKey {
export type RequestParams = { pk: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { since?: string; status?: string; sub?: string };
}
/**
* @description HEAD info on Authentiq ID
* @tags key, head
* @name HeadKey
* @request HEAD:/key/{PK}
*/
export namespace HeadKey {
export type RequestParams = { pk: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = void;
}
/**
* @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
* @tags key, post
* @name KeyUpdate
* @request POST:/key/{PK}
*/
export namespace KeyUpdate {
export type RequestParams = { pk: string };
export type RequestQuery = {};
export type RequestBody = AuthentiqID;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @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
* @tags key, put
* @name KeyBind
* @request PUT:/key/{PK}
*/
export namespace KeyBind {
export type RequestParams = { pk: string };
export type RequestQuery = {};
export type RequestBody = AuthentiqID;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
}

export namespace login {
/**
* @description push sign-in request See: https://github.com/skion/authentiq/wiki/JWT-Examples
* @tags login, post
* @name PushLoginRequest
* @request POST:/login
*/
export namespace PushLoginRequest {
export type RequestParams = {};
export type RequestQuery = { callback: string };
export type RequestBody = PushToken;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @description Get a current key register
* @tags key, get
* @name KeyRegister
* @request GET:/login
*/
export namespace KeyRegister {
export type RequestParams = {};
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { secret?: string; status?: string };
}
}

export namespace scope {
/**
* @description scope verification request See: https://github.com/skion/authentiq/wiki/JWT-Examples
* @tags scope, post
* @name SignRequest
* @request POST:/scope
*/
export namespace SignRequest {
export type RequestParams = {};
export type RequestQuery = { test?: number };
export type RequestBody = Claims;
export type RequestHeaders = {};
export type ResponseBody = { job?: string; status?: string };
}
/**
* @description delete a verification job
* @tags scope, delete
* @name SignDelete
* @request DELETE:/scope/{job}
*/
export namespace SignDelete {
export type RequestParams = { job: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @description get the status / current content of a verification job
* @tags scope, get
* @name SignRetrieve
* @request GET:/scope/{job}
*/
export namespace SignRetrieve {
export type RequestParams = { job: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { exp?: number; field?: string; sub?: string };
}
/**
* @description HEAD to get the status of a verification job
* @tags scope, head
* @name SignRetrieveHead
* @request HEAD:/scope/{job}
*/
export namespace SignRetrieveHead {
export type RequestParams = { job: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = void;
}
/**
* @description this is a scope confirmation
* @tags scope, post
* @name SignConfirm
* @request POST:/scope/{job}
*/
export namespace SignConfirm {
export type RequestParams = { job: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { status?: string };
}
/**
* @description authority updates a JWT with its signature See: https://github.com/skion/authentiq/wiki/JWT-Examples
* @tags scope, put
* @name SignUpdate
* @request PUT:/scope/{job}
*/
export namespace SignUpdate {
export type RequestParams = { job: string };
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = { jwt?: string; status?: string };
}
}
1 change: 1 addition & 0 deletions tests/spec/modular/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ schemas.forEach(({ absolutePath }) => {
output: resolve(__dirname, "./"),
modular: true,
generateClient: true,
generateRouteTypes: true,
})
.then(() => {
const diagnostics = [
Expand Down

0 comments on commit 888249b

Please sign in to comment.