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
Add API response types to web-api methods #1188
Conversation
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.
comments for reviewers
|
||
describe('constructor()', function () { | ||
it('should build a default client given a token', function () { | ||
require("mocha"); |
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 just applied prettier to all the files in web-api project
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.
oh, lint fails. i will update the whole changes.
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.
reverted
packages/web-api/src/methods.ts
Outdated
WebClientEvent, | ||
} from "./WebClient"; | ||
import { EventEmitter } from "eventemitter3"; | ||
import { AdminAppsApproveResponse } from "./response/AdminAppsApproveResponse"; |
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.
These files under ./response
are auto generated.
packages/web-api/src/methods.ts
Outdated
|
||
public readonly admin = { | ||
apps: { | ||
approve: bindApiCall<AdminAppsApproveArguments, WebAPICallResult>(this, 'admin.apps.approve'), | ||
approve: bindApiCall<AdminAppsApproveArguments, AdminAppsApproveResponse>( |
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.
AdminAppsApproveResponse
is a subtype of WebAPICallResult
@@ -0,0 +1,363 @@ | |||
import { WebAPICallResult } from "../WebClient"; | |||
export type ChatPostMessageResponse = WebAPICallResult & { |
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.
Probably, most of you are already familiar with this type 😄
32eabbc
to
94eb35a
Compare
codecov does not return the results but the builds passed! |
@@ -0,0 +1,8 @@ | |||
/* tslint:disable */ |
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.
Some parts of auto-generated code are not compatible with the current tslint settings. I tried to settle all of them this way but a few patterns are inevitable. You can see the result by modifying the code generator.
Let me add a few more comments for some questions about this: Q: What's the dependency to the Java SDK project? Q: Why are all fields optional? |
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 like this approach. Well done @seratch!
While auto-generated types may not be as rich as handwritten, it's better than nothing and easier to maintain.
The dependency on the Java SDK is not ideal, but okay in my mind. If it's an issue, we could create separate project to generate the types and send a PR into this project.
@seratch is it possible to switch the Ruby quicktype
for Node.js dev dependency?
npm install --save-dev quicktype
@mwbrooks Thanks for the suggestion - I've resolved it 👍 |
e7e7fce
to
40466cc
Compare
I'm very excited to use the fully-typed version of API client, but it's not released yet. The issues in 6.2 milestone has all been closed or merge, so isn't it already possible to release the new version? |
@TonalidadeHidrica Thanks for your interest! Yes, the last task in the list was completed yesterday. We are going to release a new version soon 🚀 |
Summary
This pull request adds types to
@slack/web-api
API method call results. It does not bring any breaking changes. The generated types are all subtypes ofWebAPICallResult
interface.Although the pull request #1078 applies similar changes, the changes were done by hand and the coverage is not complete. The approach in this PR utilizes the official Java SDK's integration test results for automatic code generation. Thus, we don't need to manually update the interface. Also, 100% of the API methods are covered.
We can assume the already generated fields are accurate as they surely exist in the actual API responses. If the Java SDK's tests do not cover some patterns, the fields that may be included only with a particular condition can be missing.
You can update the type definitions by running the following command at any time. The command checks out the Java SDK git repository and run quicktype code generator to update the TypeScript source code under
packages/web-api/src/response/
package.We can add the execution to the CI builds but manually running it would be enough so far.
Lastly, here are pros/cons of this pull request's approach. I'm sure it's reasonable enough to go with this way though.
Pros
[key: string]: unknown;
inWebAPICallResult
Cons
If we have to stop using quicktype in the future, we can just give up automatic generation. We are still able to manually maintain the types afterward.
Requirements (place an
x
in each[ ]
)