Skip to content

Commit

Permalink
fix: array one of
Browse files Browse the repository at this point in the history
  • Loading branch information
toshiaki61 authored and solufa committed Jul 22, 2021
1 parent 73138f1 commit 955105f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 1 deletion.
5 changes: 5 additions & 0 deletions aspida.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
]
44 changes: 44 additions & 0 deletions samples/array-one-of.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions samples/array-one-of/$api.ts
Original file line number Diff line number Diff line change
@@ -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 = <T>({ baseURL, fetch }: AspidaClient<T>) => {
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, '')
const PATH0 = '/user'
const GET = 'GET'

return {
user: {
/**
* @returns sample
*/
get: (option?: { config?: T }) =>
fetch<Methods0['get']['resBody'], BasicHeaders, Methods0['get']['status']>(prefix, PATH0, GET, option).json(),
/**
* @returns sample
*/
$get: (option?: { config?: T }) =>
fetch<Methods0['get']['resBody'], BasicHeaders, Methods0['get']['status']>(prefix, PATH0, GET, option).json().then(r => r.body),
$path: () => `${prefix}${PATH0}`
}
}
}

// prettier-ignore
export type ApiInstance = ReturnType<typeof api>
// prettier-ignore
export default api
14 changes: 14 additions & 0 deletions samples/array-one-of/@types/index.ts
Original file line number Diff line number Diff line change
@@ -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
}
31 changes: 31 additions & 0 deletions samples/array-one-of/user/$api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable */
// prettier-ignore
import { AspidaClient, BasicHeaders } from 'aspida'
// prettier-ignore
import { Methods as Methods0 } from '.'

// prettier-ignore
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, '')
const PATH0 = '/user'
const GET = 'GET'

return {
/**
* @returns sample
*/
get: (option?: { config?: T }) =>
fetch<Methods0['get']['resBody'], BasicHeaders, Methods0['get']['status']>(prefix, PATH0, GET, option).json(),
/**
* @returns sample
*/
$get: (option?: { config?: T }) =>
fetch<Methods0['get']['resBody'], BasicHeaders, Methods0['get']['status']>(prefix, PATH0, GET, option).json().then(r => r.body),
$path: () => `${prefix}${PATH0}`
}
}

// prettier-ignore
export type ApiInstance = ReturnType<typeof api>
// prettier-ignore
export default api
13 changes: 13 additions & 0 deletions samples/array-one-of/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable */
import type * as Types from '../@types'

export type Methods = {
get: {
status: 200

/** sample */
resBody: {
user: Partial<Types.User> | null
}
}
}
2 changes: 1 addition & 1 deletion src/buildV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 955105f

Please sign in to comment.