-
Notifications
You must be signed in to change notification settings - Fork 440
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
fix(OpenAPI): Fix array syntax ambiguities #13711
Closed
Closed
Changes from all commits
Commits
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
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
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 |
---|---|---|
|
@@ -120,7 +120,7 @@ protected function getBotFromHeaders(string $token, string $message): Bot { | |
* @param string $referenceId For the message to be able to later identify it again | ||
* @param int $replyTo Parent id which this message is a reply to | ||
* @param bool $silent If sent silent the chat message will not create any notifications | ||
* @return DataResponse<Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_REQUEST_ENTITY_TOO_LARGE, array<empty>, array{}> | ||
* @return DataResponse<Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_REQUEST_ENTITY_TOO_LARGE, list<empty>, array{}> | ||
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. same here 🙈 |
||
* | ||
* 201: Message sent successfully | ||
* 400: When the replyTo is invalid or message is empty | ||
|
@@ -183,7 +183,7 @@ public function sendMessage(string $token, string $message, string $referenceId | |
* @param string $token Conversation token | ||
* @param int $messageId ID of the message | ||
* @param string $reaction Reaction to add | ||
* @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, array<empty>, array{}> | ||
* @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED|Http::STATUS_BAD_REQUEST|Http::STATUS_UNAUTHORIZED|Http::STATUS_NOT_FOUND, list<empty>, array{}> | ||
* | ||
* 200: Reaction already exists | ||
* 201: Reacted successfully | ||
|
@@ -237,7 +237,7 @@ public function react(string $token, int $messageId, string $reaction): DataResp | |
* @param string $token Conversation token | ||
* @param int $messageId ID of the message | ||
* @param string $reaction Reaction to delete | ||
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_UNAUTHORIZED, array<empty>, array{}> | ||
* @return DataResponse<Http::STATUS_OK|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_UNAUTHORIZED, list<empty>, array{}> | ||
* | ||
* 200: Reaction deleted successfully | ||
* 400: Reacting is not possible | ||
|
@@ -285,7 +285,7 @@ public function deleteReaction(string $token, int $messageId, string $reaction): | |
/** | ||
* List admin bots | ||
* | ||
* @return DataResponse<Http::STATUS_OK, TalkBotWithDetails[], array{}> | ||
* @return DataResponse<Http::STATUS_OK, list<TalkBotWithDetails>, array{}> | ||
* | ||
* 200: Bot list returned | ||
*/ | ||
|
@@ -305,7 +305,7 @@ public function adminListBots(): DataResponse { | |
/** | ||
* List bots | ||
* | ||
* @return DataResponse<Http::STATUS_OK, TalkBot[], array{}> | ||
* @return DataResponse<Http::STATUS_OK, list<TalkBot>, array{}> | ||
* | ||
* 200: Bot list returned | ||
*/ | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Really not a fan of this... it will never be a list. But we might introduce an
'error'
key like we have on many other APIs, and then the response type changes from[]
to{}
I guess it's hard to know which case is preferred technically.
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.
Yes, but even then this is a breaking change.
If you'd document it as
\stdClass
for now and later asarray{error: string}
it would be fine.I don't think this change makes it worse as it is the same JSON data in the end.
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.
IMO the cleanest way is to have it return null as then you can later add any data and you are not limited to either objects or lists.
Unfortunately I don't think we can change this as it technically is a breaking change, though no client should really be looking at this data (and openapi-extractor also skips it automatically).
Same goes for the default value in the constructor of DataResponse which should be null as well.
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.
well form
array<empty>
toarray{error? string}
it should be okay?But anyway, we will see.
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.
No, the former is
[]
in JSON and the later is{}
or{"error": ""}
in JSON and those are not compatible.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.
ah lol, nvm. the
list<empty>
on root is not added to the OpenAPI definition as a list:So I guess we are fine to start using it later either way
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.
Any disadvantage of using
array{}
🤔It does:
I guess the real problem is that the API does not return like this, so it actually creates invalid code-docs combination?
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.
I think my favorite solution for now is:
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.
You can not switch to
list<>
later without a breaking change.Yeah this should not be done, I don't think psalm or openapi-extractor can catch it.
Looks ok to me, even though I think null is still better as it allows you to use any type later without a breaking change.
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.
Well those things never should return lists directly anyway.
I made a poll for the team to give feedback if toggling to null and later on to
array{error?: string}
is problematic. If it turns out to be, we can also annotatearray{error?: string}
now already to indicate the correct way going forward.