Skip to content

Commit

Permalink
fix: bracket notation of path value types
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Apr 17, 2020
1 parent 861a155 commit 082a4a8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/aspida-mock/src/cli/createRouteString.ts
@@ -1,6 +1,7 @@
const createImportPath = (filePath: string, inputDir: string) =>
filePath
.replace(new RegExp(`^(.\\/)?${inputDir.replace(/^.\//, '').replace(/\/$/, '')}`), '')
.replace(/'/g, "\\'")
.replace(/\.ts$/, '')

const createCondition = (
Expand Down
4 changes: 2 additions & 2 deletions packages/aspida/samples/$api.ts
Expand Up @@ -10,7 +10,7 @@ import { Methods as Methods5 } from './v1.1/2/_hogeId@HogeId/test-4/_fugaId'
import { Methods as Methods6 } from './v1.1/2/_hogeId@HogeId/test-4/fuga aa'
import { Methods as Methods7 } from './v1.1/3.1'
import { Methods as Methods8 } from './v1.1/_articleId.json'
import { Methods as Methods9 } from './v1.1/users/_userId@number'
import { Methods as Methods9 } from './v1.1/users/_userId@User[\'id\']'
import { Methods as Methods10 } from './v2.0/index'

const api = <T>(client: AspidaClient<T>) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ const api = <T>(client: AspidaClient<T>) => {
(await client.fetch<Methods8['get']['resBody']>(prefix, `/v1.1/${val3}.json`, 'GET', option).json()).data
}),
users: {
_userId: (val4: number) => ({
_userId: (val4: ApiTypes.User['id']) => ({
get: (option: { query: Methods9['get']['query'], headers: Methods9['get']['reqHeaders'], config?: T }) =>
client.fetch<Methods9['get']['resBody']>(prefix, `/v1.1/users/${val4}`, 'GET', option).json(),
$get: async (option: { query: Methods9['get']['query'], headers: Methods9['get']['reqHeaders'], config?: T }) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/aspida/samples/$mock.ts
Expand Up @@ -3,7 +3,7 @@ import { MockClient, MockConfig } from 'aspida-mock'
import baseMiddleware from './@middleware'
import api from './$api'
import mock0 from './v2.0/index'
import mock1 from './v1.1/users/_userId@number'
import mock1 from './v1.1/users/_userId@User[\'id\']'
import mock2 from './v1.1/_articleId.json'
import mock3 from './v1.1/3.1'
import mock4 from './v1.1/2/_hogeId@HogeId/test-4/_fugaId'
Expand All @@ -13,7 +13,7 @@ import mock7 from './_sampleId.json@number'

export const mockRoutes = () => [
{ path: '/v2.0', methods: mock0 },
{ path: '/v1.1/users/_userId@number', methods: mock1 },
{ path: '/v1.1/users/_userId@User[\'id\']', methods: mock1 },
{ path: '/v1.1/_articleId.json', methods: mock2 },
{ path: '/v1.1/3.1', methods: mock3 },
{ path: '/v1.1/2/_hogeId@HogeId/test-4/_fugaId', methods: mock4 },
Expand Down
4 changes: 4 additions & 0 deletions packages/aspida/samples/@types.ts
@@ -1 +1,5 @@
export type HogeId = 'hoge' | 'fuga' | 'fizz' | 'buzz'

export interface User {
id: string
}
2 changes: 1 addition & 1 deletion packages/aspida/src/createTemplateValues.ts
Expand Up @@ -10,7 +10,7 @@ export default (input: string, trailingSlash: boolean) => {
if (!methodsInterface) return ''

const importName = `Methods${imports.length}`
imports.push(`import { Methods as ${importName} } from '${file}'`)
imports.push(`import { Methods as ${importName} } from '${file.replace(/'/g, "\\'")}'`)
return createMethods(methodsInterface, indent, importName, newUrl, trailingSlash)
}

Expand Down

0 comments on commit 082a4a8

Please sign in to comment.