Output empty object response body as {} type instead of void type#250
Open
mashabow wants to merge 3 commits intoaspida:mainfrom
Open
Output empty object response body as {} type instead of void type#250mashabow wants to merge 3 commits intoaspida:mainfrom
{} type instead of void type#250mashabow wants to merge 3 commits intoaspida:mainfrom
Conversation
mashabow
commented
Oct 31, 2023
Comment on lines
18
to
23
| resBody: { | ||
| limit: number | ||
| offset: number | ||
| data: { | ||
| }[] | ||
| } |
Contributor
Author
There was a problem hiding this comment.
この部分のスキーマは以下のようになっていました。
openapi2aspida/samples/openapi.json
Lines 2732 to 2739 in e88a0f1
ここは「レスポンスボディが空オブジェクトだった場合」でなく「レスポンスボディの一部分が空オブジェクトだった場合」ですが、修正後の {}[] の方が正しく型を表しています。
mikana0918
reviewed
Jan 6, 2024
| 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.
Suggested change
| } else if (schema.type === 'object' || schema.properties || 'additionalProperties' in schema) { | |
| } else if (schema.type === 'object' || schema.properties || schema.additionalProperties) { |
@mashabow PRの確認遅くなっておりすみません。こちら他の箇所と同様に schema.additionalPropertiesとするのはいかがでしょうか? (それに関して問題等ありそうでしょうか。)もし特段の理由がなければ、ドットでのアクセスのほうが周りのコードと乖離がなく、読む際に迷いもなくなるので、いいかな?と思いました。
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Types of changes
Changes
I found that when we have an empty object for the response body, it is outputted as
voidtype instead of{}type. So, I fixed it.Since I teaked
schema2value, it might affect other parts beyond just the response body. However, based on the existing tests, everything seems okay.レスポンスボディが空オブジェクトのとき、
{}型ではなくvoid型で出力される場合があるようなので、修正してみました。schema2valueをいじったので、レスポンスボディだけでなく他の部分にも影響すると思いますが、既存のテストを見るかぎりでは悪影響はなさそうです。Additional context
Community note
Please upvote with reacting as 👍 to express your agreement.