Skip to content

Commit 43b5678

Browse files
committed
chore: add api dir
1 parent 865b34e commit 43b5678

32 files changed

+646
-8
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
target-branch: "develop"
13+
versioning-strategy: "increase"
14+
commit-message:
15+
prefix: "fix"
16+
prefix-development: "chore"

.github/workflows/nodejs.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Node.js CI
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
name: "Test on Node:${{ matrix.node-version }} OS:${{ matrix.os }}"
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
node-version: [12, 14]
12+
os: [windows-latest, ubuntu-latest]
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: setup Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: Get yarn cache directory path
20+
id: yarn-cache-dir-path
21+
run: echo "::set-output name=dir::$(yarn cache dir)"
22+
- uses: actions/cache@v2
23+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
24+
with:
25+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
26+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-yarn-
29+
- run: yarn --frozen-lockfile
30+
- run: yarn lint
31+
if: matrix.os != 'windows-latest'
32+
- run: yarn typecheck
33+
- run: yarn test --coverage
34+
- run: npx codecov
35+
if: github.ref == 'refs/heads/master' && matrix.os == 'ubuntu-latest' && matrix.node-version == 14
36+
env:
37+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
38+
39+
release:
40+
runs-on: ubuntu-latest
41+
needs: test
42+
if: contains(github.ref, 'tags/v')
43+
steps:
44+
- uses: actions/checkout@v2
45+
- name: Use Node.js
46+
uses: actions/setup-node@v1
47+
with:
48+
node-version: "12.x"
49+
registry-url: "https://registry.npmjs.org"
50+
- name: Get yarn cache directory path
51+
id: yarn-cache-dir-path
52+
run: echo "::set-output name=dir::$(yarn cache dir)"
53+
- uses: actions/cache@v2
54+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
55+
with:
56+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
57+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
58+
restore-keys: |
59+
${{ runner.os }}-yarn-
60+
- run: yarn --frozen-lockfile
61+
- run: yarn build
62+
- run: npm publish
63+
env:
64+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.versionrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"types": [
3+
{ "type": "build", "hidden": true },
4+
{ "type": "chore", "hidden": true },
5+
{ "type": "ci", "hidden": true },
6+
{ "type": "docs", "section": "Documentation" },
7+
{ "type": "feat", "section": "Features" },
8+
{ "type": "fix", "section": "Bug Fixes" },
9+
{ "type": "perf", "section": "Performance Improvements" },
10+
{ "type": "refactor", "section": "Refactors" },
11+
{ "type": "style", "hidden": true },
12+
{ "type": "test", "section": "Tests" }
13+
]
14+
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"eslint.run": "onSave",
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
},
6+
"typescript.tsdk": "node_modules/typescript/lib"
7+
}

__tests__/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import mockClient from '../../aspida-axios/src/mockClient'
1+
import mockClient from '@aspida/axios/dist/mockClient'
22
import { MockRoute } from '../src'
3-
import api from '../../aspida/sample1/$api'
3+
import api from '../api/$api'
44

55
describe('initialize', () => {
66
const adapter = mockClient()

api/$api.ts

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
/* eslint-disable */
2+
import { AspidaClient, BasicHeaders, dataToURLString } from 'aspida'
3+
import * as ApiTypes from './@types'
4+
import { Methods as Methods0 } from '.'
5+
import { Methods as Methods1 } from './_sampleId.json@number'
6+
import { Methods as Methods2 } from './v1.1'
7+
import { Methods as Methods3 } from './v1.1/2/_hogeId@HogeId/entries.json'
8+
import { Methods as Methods4 } from './v1.1/2/_hogeId@HogeId/test-4'
9+
import { Methods as Methods5 } from './v1.1/2/_hogeId@HogeId/test-4/_fugaId'
10+
import { Methods as Methods6 } from './v1.1/2/_hogeId@HogeId/test-4/fuga aa'
11+
import { Methods as Methods7 } from './v1.1/2/_hogeId@number'
12+
import { Methods as Methods8 } from './v1.1/3.1'
13+
import { Methods as Methods9 } from './v1.1/_articleId.json'
14+
import { Methods as Methods10 } from './v1.1/users/_userId@User[\'id\']'
15+
import { Methods as Methods11 } from './v2.0'
16+
17+
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
18+
const prefix = (baseURL === undefined ? 'https://example.com/api/' : baseURL).replace(/\/$/, '')
19+
const PATH0 = '/v1.1'
20+
const PATH1 = '/v1.1/2'
21+
const PATH2 = '/entries.json'
22+
const PATH3 = '/test-4'
23+
const PATH4 = '/test-4/fuga aa'
24+
const PATH5 = '/v1.1/3.1'
25+
const PATH6 = '/v1.1/users'
26+
const PATH7 = '/v2.0'
27+
const GET = 'GET'
28+
const POST = 'POST'
29+
const PUT = 'PUT'
30+
const DELETE = 'DELETE'
31+
32+
return {
33+
_sampleId_json: (val0: number) => {
34+
const prefix0 = `/${val0}.json`
35+
36+
return {
37+
get: (option?: { config?: T }) =>
38+
fetch<Methods1['get']['resBody']>(prefix, prefix0, GET, option).json(),
39+
$get: (option?: { config?: T }) =>
40+
fetch<Methods1['get']['resBody']>(prefix, prefix0, GET, option).json().then(r => r.body),
41+
$path: () => `${prefix}${prefix0}`
42+
}
43+
},
44+
v1_1: {
45+
$2: {
46+
_hogeId_0: (val1: ApiTypes.HogeId) => {
47+
const prefix1 = `${PATH1}/${val1}`
48+
49+
return {
50+
entries_json: {
51+
get: (option?: { config?: T }) =>
52+
fetch<Methods3['get']['resBody']>(prefix, `${prefix1}${PATH2}`, GET, option).json(),
53+
$get: (option?: { config?: T }) =>
54+
fetch<Methods3['get']['resBody']>(prefix, `${prefix1}${PATH2}`, GET, option).json().then(r => r.body),
55+
$path: () => `${prefix}${prefix1}${PATH2}`
56+
},
57+
test_4: {
58+
_fugaId: (val2: number | string) => {
59+
const prefix2 = `${prefix1}${PATH3}/${val2}`
60+
61+
return {
62+
get: (option?: { query?: Methods5['get']['query'], config?: T }) =>
63+
fetch<Methods5['get']['resBody']>(prefix, prefix2, GET, option).json(),
64+
$get: (option?: { query?: Methods5['get']['query'], config?: T }) =>
65+
fetch<Methods5['get']['resBody']>(prefix, prefix2, GET, option).json().then(r => r.body),
66+
post: (option: { body?: Methods5['post']['reqBody'], query: Methods5['post']['query'], config?: T }) =>
67+
fetch<Methods5['post']['resBody']>(prefix, prefix2, POST, option).json(),
68+
$post: (option: { body?: Methods5['post']['reqBody'], query: Methods5['post']['query'], config?: T }) =>
69+
fetch<Methods5['post']['resBody']>(prefix, prefix2, POST, option).json().then(r => r.body),
70+
put: (option: { query: Methods5['put']['query'], config?: T }) =>
71+
fetch<Methods5['put']['resBody']>(prefix, prefix2, PUT, option).json(),
72+
$put: (option: { query: Methods5['put']['query'], config?: T }) =>
73+
fetch<Methods5['put']['resBody']>(prefix, prefix2, PUT, option).json().then(r => r.body),
74+
delete: (option: { query: Methods5['delete']['query'], config?: T }) =>
75+
fetch<Methods5['delete']['resBody']>(prefix, prefix2, DELETE, option).json(),
76+
$delete: (option: { query: Methods5['delete']['query'], config?: T }) =>
77+
fetch<Methods5['delete']['resBody']>(prefix, prefix2, DELETE, option).json().then(r => r.body),
78+
$path: (option?: { method?: 'get'; query: Methods5['get']['query'] } | { method: 'post'; query: Methods5['post']['query'] } | { method: 'put'; query: Methods5['put']['query'] } | { method: 'delete'; query: Methods5['delete']['query'] }) =>
79+
`${prefix}${prefix2}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
80+
}
81+
},
82+
fuga_aa: {
83+
get: (option: { query: Methods6['get']['query'], config?: T }) =>
84+
fetch<Methods6['get']['resBody']>(prefix, `${prefix1}${PATH4}`, GET, option).json(),
85+
$get: (option: { query: Methods6['get']['query'], config?: T }) =>
86+
fetch<Methods6['get']['resBody']>(prefix, `${prefix1}${PATH4}`, GET, option).json().then(r => r.body),
87+
post: (option: { body?: Methods6['post']['reqBody'], query: Methods6['post']['query'], config?: T }) =>
88+
fetch<Methods6['post']['resBody']>(prefix, `${prefix1}${PATH4}`, POST, option).json(),
89+
$post: (option: { body?: Methods6['post']['reqBody'], query: Methods6['post']['query'], config?: T }) =>
90+
fetch<Methods6['post']['resBody']>(prefix, `${prefix1}${PATH4}`, POST, option).json().then(r => r.body),
91+
put: (option: { query: Methods6['put']['query'], config?: T }) =>
92+
fetch<Methods6['put']['resBody']>(prefix, `${prefix1}${PATH4}`, PUT, option).json(),
93+
$put: (option: { query: Methods6['put']['query'], config?: T }) =>
94+
fetch<Methods6['put']['resBody']>(prefix, `${prefix1}${PATH4}`, PUT, option).json().then(r => r.body),
95+
delete: (option: { body: Methods6['delete']['reqBody'], query: Methods6['delete']['query'], config?: T }) =>
96+
fetch<Methods6['delete']['resBody']>(prefix, `${prefix1}${PATH4}`, DELETE, option).json(),
97+
$delete: (option: { body: Methods6['delete']['reqBody'], query: Methods6['delete']['query'], config?: T }) =>
98+
fetch<Methods6['delete']['resBody']>(prefix, `${prefix1}${PATH4}`, DELETE, option).json().then(r => r.body),
99+
$path: (option?: { method?: 'get'; query: Methods6['get']['query'] } | { method: 'post'; query: Methods6['post']['query'] } | { method: 'put'; query: Methods6['put']['query'] } | { method: 'delete'; query: Methods6['delete']['query'] }) =>
100+
`${prefix}${prefix1}${PATH4}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
101+
},
102+
get: (option: { query: Methods4['get']['query'], config?: T }) =>
103+
fetch<void>(prefix, `${prefix1}${PATH3}`, GET, option).send(),
104+
$get: (option: { query: Methods4['get']['query'], config?: T }) =>
105+
fetch<void>(prefix, `${prefix1}${PATH3}`, GET, option).send().then(r => r.body),
106+
post: (option?: { body?: Methods4['post']['reqBody'], query?: Methods4['post']['query'], config?: T }) =>
107+
fetch<void>(prefix, `${prefix1}${PATH3}`, POST, option).send(),
108+
$post: (option?: { body?: Methods4['post']['reqBody'], query?: Methods4['post']['query'], config?: T }) =>
109+
fetch<void>(prefix, `${prefix1}${PATH3}`, POST, option).send().then(r => r.body),
110+
put: (option?: { query?: Methods4['put']['query'], config?: T }) =>
111+
fetch<Methods4['put']['resBody']>(prefix, `${prefix1}${PATH3}`, PUT, option).json(),
112+
$put: (option?: { query?: Methods4['put']['query'], config?: T }) =>
113+
fetch<Methods4['put']['resBody']>(prefix, `${prefix1}${PATH3}`, PUT, option).json().then(r => r.body),
114+
delete: (option: { query: Methods4['delete']['query'], config?: T }) =>
115+
fetch<Methods4['delete']['resBody']>(prefix, `${prefix1}${PATH3}`, DELETE, option).json(),
116+
$delete: (option: { query: Methods4['delete']['query'], config?: T }) =>
117+
fetch<Methods4['delete']['resBody']>(prefix, `${prefix1}${PATH3}`, DELETE, option).json().then(r => r.body),
118+
$path: (option?: { method?: 'get'; query: Methods4['get']['query'] } | { method: 'post'; query: Methods4['post']['query'] } | { method: 'put'; query: Methods4['put']['query'] } | { method: 'delete'; query: Methods4['delete']['query'] }) =>
119+
`${prefix}${prefix1}${PATH3}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
120+
}
121+
}
122+
},
123+
_hogeId_1: (val3: number) => {
124+
const prefix3 = `${PATH1}/${val3}`
125+
126+
return {
127+
get: (option: { query?: Methods7['get']['query'], headers: Methods7['get']['reqHeaders'], config?: T }) =>
128+
fetch<Methods7['get']['resBody']>(prefix, prefix3, GET, option).json(),
129+
$get: (option: { query?: Methods7['get']['query'], headers: Methods7['get']['reqHeaders'], config?: T }) =>
130+
fetch<Methods7['get']['resBody']>(prefix, prefix3, GET, option).json().then(r => r.body),
131+
$path: (option?: { method?: 'get'; query: Methods7['get']['query'] }) =>
132+
`${prefix}${prefix3}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
133+
}
134+
}
135+
},
136+
$3_1: {
137+
get: (option: { query?: Methods8['get']['query'], headers: Methods8['get']['reqHeaders'], config?: T }) =>
138+
fetch<Methods8['get']['resBody']>(prefix, PATH5, GET, option).json(),
139+
$get: (option: { query?: Methods8['get']['query'], headers: Methods8['get']['reqHeaders'], config?: T }) =>
140+
fetch<Methods8['get']['resBody']>(prefix, PATH5, GET, option).json().then(r => r.body),
141+
post: (option: { body?: Methods8['post']['reqBody'], query: Methods8['post']['query'], config?: T }) =>
142+
fetch<Methods8['post']['resBody']>(prefix, PATH5, POST, option, 'URLSearchParams').json(),
143+
$post: (option: { body?: Methods8['post']['reqBody'], query: Methods8['post']['query'], config?: T }) =>
144+
fetch<Methods8['post']['resBody']>(prefix, PATH5, POST, option, 'URLSearchParams').json().then(r => r.body),
145+
$path: (option?: { method?: 'get'; query: Methods8['get']['query'] } | { method: 'post'; query: Methods8['post']['query'] }) =>
146+
`${prefix}${PATH5}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
147+
},
148+
_articleId_json: (val4: number | string) => {
149+
const prefix4 = `${PATH0}/${val4}.json`
150+
151+
return {
152+
get: (option?: { config?: T }) =>
153+
fetch<Methods9['get']['resBody']>(prefix, prefix4, GET, option).json(),
154+
$get: (option?: { config?: T }) =>
155+
fetch<Methods9['get']['resBody']>(prefix, prefix4, GET, option).json().then(r => r.body),
156+
$path: () => `${prefix}${prefix4}`
157+
}
158+
},
159+
users: {
160+
_userId: (val5: ApiTypes.User['id']) => {
161+
const prefix5 = `${PATH6}/${val5}`
162+
163+
return {
164+
get: (option: { query: Methods10['get']['query'], headers: Methods10['get']['reqHeaders'], config?: T }) =>
165+
fetch<Methods10['get']['resBody']>(prefix, prefix5, GET, option).json(),
166+
$get: (option: { query: Methods10['get']['query'], headers: Methods10['get']['reqHeaders'], config?: T }) =>
167+
fetch<Methods10['get']['resBody']>(prefix, prefix5, GET, option).json().then(r => r.body),
168+
post: (option: { query: Methods10['post']['query'], config?: T }) =>
169+
fetch<Methods10['post']['resBody']>(prefix, prefix5, POST, option).json(),
170+
$post: (option: { query: Methods10['post']['query'], config?: T }) =>
171+
fetch<Methods10['post']['resBody']>(prefix, prefix5, POST, option).json().then(r => r.body),
172+
$path: (option?: { method?: 'get'; query: Methods10['get']['query'] } | { method: 'post'; query: Methods10['post']['query'] }) =>
173+
`${prefix}${prefix5}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
174+
}
175+
}
176+
},
177+
get: (option?: { query?: Methods2['get']['query'], config?: T }) =>
178+
fetch<Methods2['get']['resBody'], BasicHeaders, Methods2['get']['status']>(prefix, PATH0, GET, option).json(),
179+
$get: (option?: { query?: Methods2['get']['query'], config?: T }) =>
180+
fetch<Methods2['get']['resBody'], BasicHeaders, Methods2['get']['status']>(prefix, PATH0, GET, option).json().then(r => r.body),
181+
$path: (option?: { method?: 'get'; query: Methods2['get']['query'] }) =>
182+
`${prefix}${PATH0}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
183+
},
184+
v2_0: {
185+
get: (option: { query: Methods11['get']['query'], headers: Methods11['get']['reqHeaders'], config?: T }) =>
186+
fetch<Methods11['get']['resBody'], Methods11['get']['resHeaders'], Methods11['get']['status']>(prefix, PATH7, GET, option).text(),
187+
$get: (option: { query: Methods11['get']['query'], headers: Methods11['get']['reqHeaders'], config?: T }) =>
188+
fetch<Methods11['get']['resBody'], Methods11['get']['resHeaders'], Methods11['get']['status']>(prefix, PATH7, GET, option).text().then(r => r.body),
189+
$path: (option?: { method?: 'get'; query: Methods11['get']['query'] }) =>
190+
`${prefix}${PATH7}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
191+
},
192+
get: (option?: { query?: Methods0['get']['query'], headers?: Methods0['get']['reqHeaders'], config?: T }) =>
193+
fetch<Methods0['get']['resBody']>(prefix, '', GET, option).formData(),
194+
$get: (option?: { query?: Methods0['get']['query'], headers?: Methods0['get']['reqHeaders'], config?: T }) =>
195+
fetch<Methods0['get']['resBody']>(prefix, '', GET, option).formData().then(r => r.body),
196+
post: (option: { body: Methods0['post']['reqBody'], query: Methods0['post']['query'], headers?: Methods0['post']['reqHeaders'], config?: T }) =>
197+
fetch<Methods0['post']['resBody']>(prefix, '', POST, option).arrayBuffer(),
198+
$post: (option: { body: Methods0['post']['reqBody'], query: Methods0['post']['query'], headers?: Methods0['post']['reqHeaders'], config?: T }) =>
199+
fetch<Methods0['post']['resBody']>(prefix, '', POST, option).arrayBuffer().then(r => r.body),
200+
put: (option: { query: Methods0['put']['query'], config?: T }) =>
201+
fetch<Methods0['put']['resBody'], Methods0['put']['resHeaders'], Methods0['put']['status']>(prefix, '', PUT, option).json(),
202+
$put: (option: { query: Methods0['put']['query'], config?: T }) =>
203+
fetch<Methods0['put']['resBody'], Methods0['put']['resHeaders'], Methods0['put']['status']>(prefix, '', PUT, option).json().then(r => r.body),
204+
delete: (option: { query: Methods0['delete']['query'], config?: T }) =>
205+
fetch<void, Methods0['delete']['resHeaders'], Methods0['delete']['status']>(prefix, '', DELETE, option).send(),
206+
$delete: (option: { query: Methods0['delete']['query'], config?: T }) =>
207+
fetch<void, Methods0['delete']['resHeaders'], Methods0['delete']['status']>(prefix, '', DELETE, option).send().then(r => r.body),
208+
$path: (option?: { method?: 'get'; query: Methods0['get']['query'] } | { method: 'post'; query: Methods0['post']['query'] } | { method: 'put'; query: Methods0['put']['query'] } | { method: 'delete'; query: Methods0['delete']['query'] }) =>
209+
`${prefix}${''}${option?.query ? `?${dataToURLString(option.query)}` : ''}`
210+
}
211+
}
212+
213+
export type ApiInstance = ReturnType<typeof api>
214+
export default api

0 commit comments

Comments
 (0)