-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
118 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: 1.0.0 | ||
title: Sample | ||
paths: | ||
"/invoices/{invoiceCategory}": | ||
get: | ||
parameters: | ||
- name: invoiceCategory | ||
in: path | ||
required: true | ||
schema: | ||
"$ref": "#/components/schemas/InvoiceCategory" | ||
components: | ||
schemas: | ||
InvoiceCategory: | ||
type: string | ||
enum: ["category-1", "category-2"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { AspidaClient } from 'aspida'; | ||
|
||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/invoices'; | ||
|
||
|
||
return { | ||
invoices: { | ||
_invoiceCategory: (val1: string) => { | ||
const prefix1 = `${PATH0}/${val1}`; | ||
|
||
return { | ||
|
||
}; | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-disable */ | ||
export type InvoiceCategory = 'category-1' | 'category-2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { AspidaClient } from 'aspida'; | ||
|
||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/invoices'; | ||
|
||
|
||
return { | ||
_invoiceCategory: (val0: string) => { | ||
const prefix0 = `${PATH0}/${val0}`; | ||
|
||
return { | ||
|
||
}; | ||
}, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* eslint-disable */ | ||
export type Methods = { | ||
get: { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import type { OpenAPIV3 } from 'openapi-types'; | ||
import { getPropertyName, isRefObject, schema2value } from './converters'; | ||
import { getPropertyName, isRefObject } from './converters'; | ||
import { resolveSchemasRef } from './resolvers'; | ||
|
||
export default ( | ||
text: string, | ||
params: OpenAPIV3.ParameterObject[], | ||
openapi: OpenAPIV3.Document, | ||
required: boolean | ||
) => { | ||
export default (text: string, params: OpenAPIV3.ParameterObject[], openapi: OpenAPIV3.Document) => { | ||
if (text === '*') return '_any'; | ||
if (!/^{/.test(text)) { | ||
return text; | ||
} | ||
if (!/^{/.test(text)) return text; | ||
|
||
const valName = text.slice(1, -1); | ||
const prefix = `_${getPropertyName(valName)}`; | ||
|
||
const schema = params.find(p => p.in === 'path' && p.name === valName)?.schema; | ||
|
||
if (!schema) return prefix; | ||
|
||
let schema = params.find(p => p.in === 'path' && p.name === valName)?.schema; | ||
if (schema && isRefObject(schema)) { | ||
if (isRefObject(schema)) { | ||
const referencedSchema = resolveSchemasRef(openapi, schema.$ref); | ||
if (referencedSchema.type === 'string' || referencedSchema.type === 'number') { | ||
schema = referencedSchema; | ||
|
||
if (referencedSchema.type === 'string') { | ||
return `${prefix}@string`; | ||
} else if (referencedSchema.type === 'number' || referencedSchema.type === 'integer') { | ||
return `${prefix}@number`; | ||
} else { | ||
return prefix; | ||
} | ||
} | ||
|
||
const schemaVal = schema2value(schema, required); | ||
|
||
return `_${getPropertyName(valName)}${ | ||
schemaVal && typeof schemaVal.value === 'string' ? `@${schemaVal.value}` : '' | ||
return `${prefix}${ | ||
schema.type === 'string' | ||
? '@string' | ||
: schema.type === 'number' || schema.type === 'integer' | ||
? '@number' | ||
: '' | ||
}`; | ||
}; |