-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output empty object response body as {}
type instead of void
type
#250
Open
mashabow
wants to merge
3
commits into
aspida:main
Choose a base branch
from
mashabow:empty-res-body
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 @@ | ||
openapi: 3.0.0 | ||
info: | ||
version: 1.0.0 | ||
title: Sample | ||
paths: | ||
/without-additional-properties: | ||
delete: | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
/with-additional-properties-true: | ||
delete: | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
additionalProperties: true | ||
/with-additional-properties-false: | ||
delete: | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
additionalProperties: false |
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,57 @@ | ||
import type { AspidaClient, BasicHeaders } from 'aspida'; | ||
import type { Methods as Methods0 } from './with-additional-properties-false'; | ||
import type { Methods as Methods1 } from './with-additional-properties-true'; | ||
import type { Methods as Methods2 } from './without-additional-properties'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/with-additional-properties-false'; | ||
const PATH1 = '/with-additional-properties-true'; | ||
const PATH2 = '/without-additional-properties'; | ||
const DELETE = 'DELETE'; | ||
|
||
return { | ||
with_additional_properties_false: { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}, | ||
with_additional_properties_true: { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods1['delete']['resBody'], BasicHeaders, Methods1['delete']['status']>(prefix, PATH1, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods1['delete']['resBody'], BasicHeaders, Methods1['delete']['status']>(prefix, PATH1, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH1}`, | ||
}, | ||
without_additional_properties: { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH2}`, | ||
}, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
25 changes: 25 additions & 0 deletions
25
samples/empty-object-response-body/with-additional-properties-false/$api.ts
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, BasicHeaders } from 'aspida'; | ||
import type { Methods as Methods0 } from '.'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/with-additional-properties-false'; | ||
const DELETE = 'DELETE'; | ||
|
||
return { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
10 changes: 10 additions & 0 deletions
10
samples/empty-object-response-body/with-additional-properties-false/index.ts
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,10 @@ | ||
/* eslint-disable */ | ||
export type Methods = { | ||
delete: { | ||
status: 200 | ||
|
||
/** OK */ | ||
resBody: { | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
samples/empty-object-response-body/with-additional-properties-true/$api.ts
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, BasicHeaders } from 'aspida'; | ||
import type { Methods as Methods0 } from '.'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/with-additional-properties-true'; | ||
const DELETE = 'DELETE'; | ||
|
||
return { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
11 changes: 11 additions & 0 deletions
11
samples/empty-object-response-body/with-additional-properties-true/index.ts
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,11 @@ | ||
/* eslint-disable */ | ||
export type Methods = { | ||
delete: { | ||
status: 200 | ||
|
||
/** OK */ | ||
resBody: { | ||
[key: string]: any | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
samples/empty-object-response-body/without-additional-properties/$api.ts
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, BasicHeaders } from 'aspida'; | ||
import type { Methods as Methods0 } from '.'; | ||
|
||
const api = <T>({ baseURL, fetch }: AspidaClient<T>) => { | ||
const prefix = (baseURL === undefined ? '' : baseURL).replace(/\/$/, ''); | ||
const PATH0 = '/without-additional-properties'; | ||
const DELETE = 'DELETE'; | ||
|
||
return { | ||
/** | ||
* @returns OK | ||
*/ | ||
delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(), | ||
/** | ||
* @returns OK | ||
*/ | ||
$delete: (option?: { config?: T | undefined } | undefined) => | ||
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body), | ||
$path: () => `${prefix}${PATH0}`, | ||
}; | ||
}; | ||
|
||
export type ApiInstance = ReturnType<typeof api>; | ||
export default api; |
10 changes: 10 additions & 0 deletions
10
samples/empty-object-response-body/without-additional-properties/index.ts
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,10 @@ | ||
/* eslint-disable */ | ||
export type Methods = { | ||
delete: { | ||
status: 200 | ||
|
||
/** OK */ | ||
resBody: { | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,8 @@ export type Methods = { | |
resBody: { | ||
limit: number | ||
offset: number | ||
data: { | ||
}[] | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -18,6 +18,8 @@ export type Methods = { | |
resBody: { | ||
limit: number | ||
offset: number | ||
data: { | ||
}[] | ||
} | ||
} | ||
|
||
|
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 | ||||
---|---|---|---|---|---|---|
|
@@ -123,11 +123,11 @@ export const schema2value = ( | |||||
} else if (isArraySchema(schema)) { | ||||||
isArray = true; | ||||||
value = schema2value(schema.items); | ||||||
} else if (schema.properties || schema.additionalProperties) { | ||||||
} else if (schema.type === 'object' || schema.properties || 'additionalProperties' in schema) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
@mashabow PRの確認遅くなっておりすみません。こちら他の箇所と同様に |
||||||
value = object2value(schema); | ||||||
} else if (schema.format === 'binary') { | ||||||
value = isResponse ? 'Blob' : BINARY_TYPE; | ||||||
} else if (schema.type !== 'object') { | ||||||
} else { | ||||||
value = schema.type | ||||||
? { | ||||||
integer: 'number', | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この部分のスキーマは以下のようになっていました。
openapi2aspida/samples/openapi.json
Lines 2732 to 2739 in e88a0f1
ここは「レスポンスボディが空オブジェクトだった場合」でなく「レスポンスボディの一部分が空オブジェクトだった場合」ですが、修正後の
{}[]
の方が正しく型を表しています。