-
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
base: main
Are you sure you want to change the base?
Conversation
resBody: { | ||
limit: number | ||
offset: number | ||
data: { | ||
}[] | ||
} |
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
"schema": { | |
"required": ["data", "limit", "offset"], | |
"properties": { | |
"limit": { "type": "number" }, | |
"offset": { "type": "number" }, | |
"data": { "type": "array", "items": { "type": "object" } } | |
} | |
} |
ここは「レスポンスボディが空オブジェクトだった場合」でなく「レスポンスボディの一部分が空オブジェクトだった場合」ですが、修正後の {}[]
の方が正しく型を表しています。
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (schema.type === 'object' || schema.properties || 'additionalProperties' in schema) { | |
} else if (schema.type === 'object' || schema.properties || schema.additionalProperties) { |
@mashabow PRの確認遅くなっておりすみません。こちら他の箇所と同様に schema.additionalProperties
とするのはいかがでしょうか? (それに関して問題等ありそうでしょうか。)もし特段の理由がなければ、ドットでのアクセスのほうが周りのコードと乖離がなく、読む際に迷いもなくなるので、いいかな?と思いました。
Types of changes
Changes
I found that when we have an empty object for the response body, it is outputted as
void
type 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.