Skip to content

Commit 2b6ba1a

Browse files
authored
Merge pull request #76 from privy-open-source/feat/generate-schema
feat: schema code-generator (swagger)
2 parents b004364 + 2931fdd commit 2b6ba1a

21 files changed

+2646
-144
lines changed

.eslintignore

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,134 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
.output
193
dist
2-
node_modules
94+
95+
# Gatsby files
96+
.cache/
97+
# Comment in the public line in if your project uses Gatsby and not Next.js
98+
# https://nextjs.org/blog/next-9-1#public-directory-support
99+
# public
100+
101+
# vuepress build output
102+
.vuepress/dist
103+
104+
# vuepress v2.x temp and cache directory
105+
.temp
106+
.cache
107+
108+
# Docusaurus cache and generated files
109+
.docusaurus
110+
111+
# Serverless directories
112+
.serverless/
113+
114+
# FuseBox cache
115+
.fusebox/
116+
117+
# DynamoDB Local files
118+
.dynamodb/
119+
120+
# TernJS port file
121+
.tern-port
122+
123+
# Stores VSCode versions used for testing VSCode extensions
124+
.vscode-test
125+
126+
# yarn v2
127+
.yarn/cache
128+
.yarn/unplugged
129+
.yarn/build-state.yml
130+
.yarn/install-state.gz
131+
.pnp.*
132+
133+
/server.config.ts
134+
/sample.json

.github/workflows/ci.yml

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,65 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
33

44
name: CI
55

66
on:
77
push:
8-
branches: [ $default-branch ]
9-
8+
branches: [main]
109
pull_request:
11-
branches: [ $default-branch ]
10+
branches: [main]
11+
merge_group:
12+
types: [checks_requested]
1213

1314
jobs:
14-
build:
15+
analyze:
16+
runs-on: ${{ matrix.os }}
1517

16-
runs-on: ubuntu-latest
18+
permissions:
19+
actions: read
20+
contents: read
21+
security-events: write
1722

1823
strategy:
24+
fail-fast: false
1925
matrix:
26+
os:
27+
- ubuntu-latest
28+
language:
29+
- javascript
30+
31+
steps:
32+
- name: Git Checkout
33+
uses: actions/checkout@v3
34+
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v2
37+
with:
38+
languages: ${{ matrix.language }}
39+
40+
- name: Autobuild
41+
uses: github/codeql-action/autobuild@v2
42+
43+
- name: Run CodeQL Analysis
44+
uses: github/codeql-action/analyze@v2
45+
46+
build:
47+
runs-on: ${{ matrix.os }}
48+
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
os:
53+
- ubuntu-latest
2054
node-version:
21-
- 16
2255
- 18
23-
- 20
24-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2556

2657
steps:
58+
- name: Git Checkout
59+
uses: actions/checkout@v3
60+
with:
61+
submodules: "recursive"
62+
2763
- name: Get Cache Dir
2864
id: yarn-cache-dir
2965
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
@@ -33,7 +69,7 @@ jobs:
3369
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
3470
with:
3571
path: ${{ steps.yarn-cache-dir.outputs.dir }}
36-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
72+
key: ${{ runner.os }}-yarn-
3773
restore-keys: |
3874
${{ runner.os }}-yarn-
3975
@@ -46,5 +82,11 @@ jobs:
4682
- name: Install Deps
4783
run: yarn install --immutable
4884

85+
- name: Run Prepare
86+
run: yarn dev:prepare
87+
88+
- name: Build Package
89+
run: yarn build
90+
4991
- name: Run Linter
50-
run: yarn lint:ci
92+
run: yarn lint

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ dist
131131
.pnp.*
132132

133133
/server.config.ts
134+
/sample.json
135+
/api

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit "$1"

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn run lint-staged

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default defineServer([
6262
baseUrl : '/api/bin',
6363
targetUrl : 'https://httpbin.org',
6464
onProxyReq: defineEventInterceptor((proxyEvent, event) => {
65-
const token = getCookie(event, 'session/token')
65+
const token = getCookie(event, 'oauth/token')
6666

6767
if (token)
6868
setHeader(proxyEvent, 'Authorization', `Bearer ${token}`)
@@ -92,6 +92,29 @@ export default defineServer([
9292

9393
Then, you can access `/force/download?url=http://my.cdn.com/xxxxx/`
9494

95+
### Schema Code-Generator (Swagger)
96+
97+
NHP include code generator to transform OpenAPI v2 to Typescript. Just add `schemaURL` in your server then run `npx nhp schema`,
98+
99+
```ts
100+
export default defineServer([
101+
{
102+
name : 'server-b',
103+
baseUrl : '/api/server-b',
104+
// ...
105+
// Using local json
106+
schemaUrl: './path/doc.json',
107+
},
108+
{
109+
name : 'server-a',
110+
baseUrl : '/api/server-a',
111+
// ...
112+
// Using remote schema
113+
schemaUrl: 'http://server-a.dev/swagger/doc.json',
114+
},
115+
])
116+
```
117+
95118
## Contribution
96119

97120
- Clone this repository

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { extends: ['@commitlint/config-conventional'] }

package.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@
3838
"bin"
3939
],
4040
"scripts": {
41-
"prepack": "yarn build",
41+
"prepack": "yarn build && pinst --disable",
4242
"dev": "nuxi dev playground",
4343
"build": "nuxt-module-build",
4444
"lint": "eslint . --ext .js,.vue,.ts --format pretty",
4545
"fix": "yarn lint --fix",
4646
"dev:build": "nuxi build playground",
47-
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground"
47+
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
48+
"postinstall": "husky install",
49+
"postpack": "pinst --enable"
50+
},
51+
"lint-staged": {
52+
"*.(js|ts|vue)": [
53+
"eslint --fix"
54+
]
4855
},
4956
"dependencies": {
5057
"@nuxt/kit": "^3.0.0",
@@ -53,15 +60,24 @@
5360
"fs-extra": "^11.1.0",
5461
"h3": "^1.6.0",
5562
"http-proxy-middleware": "^2.0.6",
63+
"lodash-es": "^4.17.21",
5664
"meow": "^12.0.0",
57-
"ufo": "^1.1.2"
65+
"ofetch": "^1.1.1",
66+
"openapi-types": "^12.1.3",
67+
"type-fest": "^4.1.0",
68+
"ufo": "^1.1.2",
69+
"unconfig": "^0.3.10"
5870
},
5971
"devDependencies": {
72+
"@commitlint/cli": "^17.6.7",
73+
"@commitlint/config-conventional": "^17.6.7",
6074
"@nuxt/module-builder": "^0.4.0",
6175
"@nuxt/schema": "^3.0.0",
6276
"@privyid/eslint-config-persona": "^0.18.0",
77+
"@privyid/nuapi": "^0.2.1",
6378
"@types/connect": "^3.4.35",
6479
"@types/fs-extra": "^11",
80+
"@types/lodash-es": "^4.17.8",
6581
"@typescript-eslint/eslint-plugin": "^5.54.1",
6682
"@typescript-eslint/parser": "^5.54.1",
6783
"@vue/eslint-config-typescript": "^11.0.2",
@@ -76,7 +92,10 @@
7692
"eslint-plugin-unicorn": "^47.0.0",
7793
"eslint-plugin-varspacing": "^1.2.2",
7894
"eslint-plugin-vue": "^9.9.0",
95+
"husky": "^8.0.0",
96+
"lint-staged": "^13.2.3",
7997
"nuxt": "^3.0.0",
98+
"pinst": "^3.0.0",
8099
"typescript": "^5.0.0"
81100
},
82101
"publishConfig": {

0 commit comments

Comments
 (0)