diff --git a/aspida.config.js b/aspida.config.js index cd9665b5..b9f7fcdb 100644 --- a/aspida.config.js +++ b/aspida.config.js @@ -33,5 +33,10 @@ module.exports = [ input: 'samples/nullable-object', outputEachDir: true, openapi: { inputFile: 'samples/nullable-object.yml' } + }, + { + input: 'samples/array-one-of', + outputEachDir: true, + openapi: { inputFile: 'samples/array-one-of.yml' } } ] diff --git a/samples/array-one-of.yml b/samples/array-one-of.yml new file mode 100644 index 00000000..99699f45 --- /dev/null +++ b/samples/array-one-of.yml @@ -0,0 +1,44 @@ +openapi: 3.0.0 +info: + version: "1.0.0" + title: "Sample" +paths: + /user: + get: + responses: + "200": + description: "sample" + content: + application/json: + schema: + type: object + properties: + user: + nullable: true + anyOf: + - $ref: "#/components/schemas/User" +components: + schemas: + User: + type: object + properties: + id: + type: string + roles: + type: array + items: + oneOf: + - $ref: "#/components/schemas/RoleA" + - $ref: "#/components/schemas/RoleB" + RoleA: + type: object + properties: + name: + type: string + RoleB: + type: object + properties: + name: + type: string + authority: + type: string diff --git a/samples/array-one-of/$api.ts b/samples/array-one-of/$api.ts new file mode 100644 index 00000000..a7a7f008 --- /dev/null +++ b/samples/array-one-of/$api.ts @@ -0,0 +1,33 @@ +/* eslint-disable */ +// prettier-ignore +import { AspidaClient, BasicHeaders } from 'aspida' +// prettier-ignore +import { Methods as Methods0 } from './user' + +// prettier-ignore +const api = ({ baseURL, fetch }: AspidaClient) => { + const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, '') + const PATH0 = '/user' + const GET = 'GET' + + return { + user: { + /** + * @returns sample + */ + get: (option?: { config?: T }) => + fetch(prefix, PATH0, GET, option).json(), + /** + * @returns sample + */ + $get: (option?: { config?: T }) => + fetch(prefix, PATH0, GET, option).json().then(r => r.body), + $path: () => `${prefix}${PATH0}` + } + } +} + +// prettier-ignore +export type ApiInstance = ReturnType +// prettier-ignore +export default api diff --git a/samples/array-one-of/@types/index.ts b/samples/array-one-of/@types/index.ts new file mode 100644 index 00000000..ce3215ce --- /dev/null +++ b/samples/array-one-of/@types/index.ts @@ -0,0 +1,14 @@ +/* eslint-disable */ +export type User = { + id: string + roles: (RoleA | RoleB)[] +} + +export type RoleA = { + name: string +} + +export type RoleB = { + name: string + authority: string +} diff --git a/samples/array-one-of/user/$api.ts b/samples/array-one-of/user/$api.ts new file mode 100644 index 00000000..7a848ee5 --- /dev/null +++ b/samples/array-one-of/user/$api.ts @@ -0,0 +1,31 @@ +/* eslint-disable */ +// prettier-ignore +import { AspidaClient, BasicHeaders } from 'aspida' +// prettier-ignore +import { Methods as Methods0 } from '.' + +// prettier-ignore +const api = ({ baseURL, fetch }: AspidaClient) => { + const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, '') + const PATH0 = '/user' + const GET = 'GET' + + return { + /** + * @returns sample + */ + get: (option?: { config?: T }) => + fetch(prefix, PATH0, GET, option).json(), + /** + * @returns sample + */ + $get: (option?: { config?: T }) => + fetch(prefix, PATH0, GET, option).json().then(r => r.body), + $path: () => `${prefix}${PATH0}` + } +} + +// prettier-ignore +export type ApiInstance = ReturnType +// prettier-ignore +export default api diff --git a/samples/array-one-of/user/index.ts b/samples/array-one-of/user/index.ts new file mode 100644 index 00000000..64edb78d --- /dev/null +++ b/samples/array-one-of/user/index.ts @@ -0,0 +1,13 @@ +/* eslint-disable */ +import type * as Types from '../@types' + +export type Methods = { + get: { + status: 200 + + /** sample */ + resBody: { + user: Partial | null + } + } +} diff --git a/src/buildV3.ts b/src/buildV3.ts index 22023e74..a701a0f8 100644 --- a/src/buildV3.ts +++ b/src/buildV3.ts @@ -370,7 +370,7 @@ export default (openapi: OpenAPIV3.Document) => { ] .map(p => `\n${description2Doc(p.description, '')}export type ${p.name} = ${p.text}\n`) .join('') - .replace(/ Types\./g, ' ') + .replace(/(\W)Types\./g, '$1') : null return {