Skip to content

Commit 56a8e1a

Browse files
authored
Merge branch 'next' into master
2 parents 0d64c7f + 418e5cd commit 56a8e1a

File tree

221 files changed

+63491
-5653
lines changed

Some content is hidden

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

221 files changed

+63491
-5653
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TEST_FILE_NAME=github-swagger.ts
2+
TEST_SCHEMA_VERSION=v3
3+
TEST_WITH_DEBUG=true

.prettierignore renamed to .eslintignore

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
.eslintrc
2+
node_modules
3+
.husky
4+
.vscode
5+
swagger-test-cli
6+
tests
7+
*.ejs
8+
*.eta
9+
.kube
10+
.idea
11+
*.json
12+
.eslintrc.js
13+
vite.config.ts
114
tests/**/*.ts
215
tests/**/schema.js
316
tests/**/schema.ts
@@ -7,7 +20,6 @@ swagger-test-cli.*
720
templates
821
*.md
922
.github
10-
node_modules
1123
.openapi-generator
1224
.vscode
1325
assets

.eslintrc.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
parserOptions: {
3+
"ecmaVersion": "latest"
4+
},
5+
env: {
6+
"node": true,
7+
"es6": true
8+
},
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:prettier/recommended',
12+
],
13+
plugins: [
14+
'prettier',
15+
],
16+
rules: {
17+
'prettier/prettier': [
18+
'error',
19+
{
20+
endOfLine: 'auto',
21+
printWidth: 80,
22+
tabWidth: 2,
23+
trailingComma: 'all',
24+
semi: true,
25+
singleQuote: true,
26+
},
27+
],
28+
},
29+
};

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
open-pull-requests-limit: 100
6+
schedule:
7+
interval: "daily"

.github/workflows/main.yml

+84-26
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,95 @@
1-
# This is a basic workflow to help you get started with Actions
1+
name: Builds, tests & co
22

3-
name: Run tests
4-
5-
# Controls when the action will run.
63
on:
7-
# Triggers the workflow on push or pull request events but only for the master branch
8-
pull_request:
9-
branches: [ master, next ]
10-
11-
# Allows you to run this workflow manually from the Actions tab
12-
workflow_dispatch:
4+
- push
5+
- pull_request
136

14-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
157
jobs:
16-
# This workflow contains a single job called "build"
17-
build:
18-
# The type of runner that the job will run on
19-
runs-on: ubuntu-latest
8+
build-and-test:
209
strategy:
10+
fail-fast: false
2111
matrix:
22-
node-version: [11.x, 13.x, 15.x]
12+
os:
13+
- macos-latest
14+
- ubuntu-latest
15+
- windows-latest
16+
node-version:
17+
- 14.x
18+
- 16.x
19+
- 18.x
2320

24-
name: Node.js (test-all) ${{ matrix.node-version }}
21+
runs-on: ${{ matrix.os }}
2522

26-
# Steps represent a sequence of tasks that will be executed as part of the job
2723
steps:
28-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
29-
- uses: actions/checkout@v2
24+
- name: Checkout tree
25+
uses: actions/checkout@v3
26+
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
32+
- name: Install npm packages
33+
run: npm ci --ignore-scripts
34+
35+
- name: Run the tests
36+
run: npm run test-all
37+
38+
dependabot-auto-approve:
39+
name: Dependabot auto-approve
40+
41+
permissions:
42+
pull-requests: write
43+
44+
needs:
45+
- build-and-test
46+
47+
if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
48+
49+
runs-on: ubuntu-latest
3050

31-
# Runs a single command using the runners shell
32-
- name: install deps
33-
run: npm i
51+
steps:
52+
- name: Fetch Dependabot metadata
53+
id: metadata
54+
uses: dependabot/fetch-metadata@v1
55+
56+
- name: Get the PR review decision
57+
id: gh-pr-review
58+
run: echo "decision=$(gh pr view --json reviewDecision --jq '. | .reviewDecision' "$PR_URL")" >>"$GITHUB_OUTPUT"
59+
env:
60+
PR_URL: ${{ github.event.pull_request.html_url }}
61+
GITHUB_TOKEN: ${{ github.token }}
62+
63+
- name: Approve a PR
64+
if: ${{ steps.gh-pr-review.outputs.decision != 'APPROVED' && steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
65+
run: gh pr review --approve "$PR_URL"
66+
env:
67+
PR_URL: ${{ github.event.pull_request.html_url }}
68+
GITHUB_TOKEN: ${{ github.token }}
69+
70+
dependabot-auto-merge:
71+
name: Dependabot auto-merge
72+
73+
permissions:
74+
contents: write
75+
pull-requests: write
76+
77+
if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
78+
79+
needs:
80+
- build-and-test
81+
- dependabot-auto-approve
82+
83+
runs-on: ubuntu-latest
84+
85+
steps:
86+
- name: Fetch Dependabot metadata
87+
id: metadata
88+
uses: dependabot/fetch-metadata@v1
3489

35-
# Runs a set of commands using the runners shell
36-
- name: test
37-
run: npm run test-all-extended
90+
- name: Merge Dependabot PR
91+
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
92+
run: gh pr merge --auto --merge "$PR_URL"
93+
env:
94+
PR_URL: ${{ github.event.pull_request.html_url }}
95+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
.idea
44
swagger-test-cli.*
55
swagger-test-cli
6-
dist
6+
dist
7+
.env

.husky/post-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
git update-index -g

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run lint:fix

.ncurc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"upgrade": true,
3+
"reject": [
4+
"nanoid",
5+
"eta"
6+
]
7+
}

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.16.0
1+
18.16.1

.prettierrc

-5
This file was deleted.

.vscode/launch.json

-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
{
8-
"name": "Debug generate",
9-
"type": "node",
10-
"request": "launch",
11-
"cwd": "${workspaceFolder}",
12-
"runtimeExecutable": "npm",
13-
"runtimeArgs": ["run-script", "generate:debug"]
14-
},
157
{
168
"name": "Debug JSON CLI",
179
"type": "node",
@@ -60,14 +52,6 @@
6052
"runtimeExecutable": "npm",
6153
"runtimeArgs": ["run-script", "test-all"]
6254
},
63-
{
64-
"name": "Debug test-all-extended",
65-
"type": "node",
66-
"request": "launch",
67-
"cwd": "${workspaceFolder}",
68-
"runtimeExecutable": "npm",
69-
"runtimeArgs": ["run-script", "test-all-extended"]
70-
},
7155
{
7256
"name": "Debug test:--extract-request-body",
7357
"type": "node",

CHANGELOG.md

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,62 @@
1-
# next release
1+
# next release
2+
3+
BREAKING_CHANGE: change swagger-typescript-api NodeJS "generateApi" function return type
4+
internal: remove redundant internal scripts
5+
fix: critical bugs based with extract types and enums
6+
fix: sort types option (sort was not correctly work with nested or extracted types)
7+
fix: problems based with extracting enums;
8+
feat: ability to sort routes;
9+
chore: refactoring the axios imports
10+
fix: non-object custom spec extensions (#500)
11+
internal: change process with using custom templates
12+
fix(docs): input instead of output in readme
13+
BREAKING_CHANGE: remove `rawModelTypes` from output api configuration
14+
15+
```diff
16+
interface GenerateApiOutput {
17+
...
18+
- files: { name: string; content: string; declaration: { name: string; content: string } | null }[];
19+
+ files: { fileName: string; fileContent: string; fileExtension: string }[];
20+
...
21+
}
22+
```
23+
24+
internal: refactor schema parser code (preparing it for async code execution)
25+
fix: problem with filtering primitive in complex types (#459)
26+
feat: add discriminator property support (#456)
27+
internal: prepare code + templates for async code execution (next plans)
28+
fix: problems with dot in query params (hard fix) (#460)
29+
feature: ability to send custom Ts output code translator to js. Example:
30+
```ts
31+
const { Translator } = require("swagger-typescript-api/src/translators/translator");
32+
const { JavascriptTranslator } = require("swagger-typescript-api/src/translators/javascript");
33+
34+
class MyTranslator extends Translator { // or use extends JavascriptTranslator
35+
translate({ fileName, fileExtension, fileContent }) {
36+
// format ts\js code with using this codeFormatter (prettier + ts import fixer)
37+
this.codeFormatter.format(fileContent)
38+
// config of the code gen process
39+
this.config.
40+
// logger
41+
this.logger.
42+
43+
return [
44+
{
45+
fileName,
46+
fileExtension,
47+
fileContent,
48+
}
49+
]
50+
}
51+
}
52+
```
53+
54+
## 12.0.4
55+
56+
fix: onCreateRoute skip behaviour
57+
fix: problems with prefixes\suffixes for extracted requests params, enums
58+
59+
**Full Changelog**: https://github.com/acacode/swagger-typescript-api/compare/12.0.3...12.0.4
260

361
## 12.0.3
462

@@ -477,7 +535,7 @@ Features:
477535
name?: string;
478536
path?: string;
479537
}) => string
480-
formatTSContent: (content: string) => string;
538+
formatTSContent: (content: string) => Promise<string>;
481539

482540

483541
// ...

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const { generateApi, generateTemplates } = require('swagger-typescript-api');
106106
const path = require("path");
107107
const fs = require("fs");
108108

109-
/* NOTE: all fields are optional expect one of `output`, `url`, `spec` */
109+
/* NOTE: all fields are optional expect one of `input`, `url`, `spec` */
110110
generateApi({
111111
name: "MySuperbApi.ts",
112112
// set to `false` to prevent the tool from writing to disk
@@ -130,6 +130,7 @@ generateApi({
130130
toJS: false,
131131
extractRequestParams: false,
132132
extractRequestBody: false,
133+
extractEnums: false,
133134
unwrapResponseData: false,
134135
prettier: { // By default prettier config is load from your project
135136
printWidth: 120,

cli/constants.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const root_command = Symbol("root");
2-
const skip_command = Symbol("skip");
1+
const root_command = Symbol('root');
2+
const skip_command = Symbol('skip');
33

4-
const reservedOptions = ["version", "help"];
4+
const reservedOptions = ['version', 'help'];
55

66
module.exports = {
77
root_command,

0 commit comments

Comments
 (0)