-
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
8 changed files
with
148 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: 1.0.0 | ||
title: Sample | ||
paths: | ||
/ping: | ||
get: | ||
responses: | ||
'200': | ||
description: OK | ||
headers: | ||
X-Simple: | ||
$ref: '#/components/headers/X-Simple' | ||
X-Description: | ||
$ref: '#/components/headers/X-Description' | ||
X-Ref: | ||
$ref: '#/components/headers/X-Ref' | ||
content: | ||
application/json: | ||
schema: | ||
type: string | ||
example: pong | ||
components: | ||
headers: | ||
X-Simple: | ||
schema: | ||
type: string | ||
X-Description: | ||
schema: | ||
type: integer | ||
description: This header has a description. | ||
X-Ref: | ||
$ref: '#/components/headers/X-Simple' |
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,27 @@ | ||
import type { AspidaClient } from 'aspida'; | ||
import type { Methods as Methods0 } from './ping'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/ping'; | ||
const GET = 'GET'; | ||
|
||
return { | ||
ping: { | ||
/** | ||
* @returns OK | ||
*/ | ||
get: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['get']['resBody'], Methods0['get']['resHeaders'], Methods0['get']['status']>(prefix, PATH0, GET, option).text(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$get: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['get']['resBody'], Methods0['get']['resHeaders'], Methods0['get']['status']>(prefix, PATH0, GET, option).text().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}, | ||
}; | ||
}; | ||
|
||
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,7 @@ | ||
/* eslint-disable */ | ||
export type X_Simple = string | ||
|
||
/** This header has a description. */ | ||
export type X_Description = number | ||
|
||
export type X_Ref = X_Simple |
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,25 @@ | ||
import type { AspidaClient } from 'aspida'; | ||
import type { Methods as Methods0 } from '.'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/ping'; | ||
const GET = 'GET'; | ||
|
||
return { | ||
/** | ||
* @returns OK | ||
*/ | ||
get: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['get']['resBody'], Methods0['get']['resHeaders'], Methods0['get']['status']>(prefix, PATH0, GET, option).text(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$get: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['get']['resBody'], Methods0['get']['resHeaders'], Methods0['get']['status']>(prefix, PATH0, GET, option).text().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}; | ||
}; | ||
|
||
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,16 @@ | ||
/* eslint-disable */ | ||
import type * as Types from '../@types' | ||
|
||
export type Methods = { | ||
get: { | ||
status: 200 | ||
/** OK */ | ||
resBody: string | ||
|
||
resHeaders: { | ||
'X-Simple': Types.X_Simple | ||
'X-Description': Types.X_Description | ||
'X-Ref': Types.X_Ref | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { OpenAPIV3 } from 'openapi-types'; | ||
import { $ref2Type, defKey2defName, isRefObject, schema2value } from './converters'; | ||
import type { PropValue } from './props2String'; | ||
|
||
export type Header = { name: string; value: string | PropValue }; | ||
|
||
export default (headers: OpenAPIV3.ComponentsObject['headers']) => | ||
headers && | ||
Object.keys(headers) | ||
.map(defKey => { | ||
const target = headers[defKey]; | ||
let value: Header['value']; | ||
|
||
if (isRefObject(target)) { | ||
value = $ref2Type(target.$ref); | ||
} else { | ||
const result = schema2value(target.schema, false); | ||
if (!result) return null; | ||
value = { ...result, description: target.description ?? null }; | ||
} | ||
|
||
return { name: defKey2defName(defKey), value }; | ||
}) | ||
.filter((v): v is Header => !!v); |