-
Notifications
You must be signed in to change notification settings - Fork 109
Conversation
With this version, `mutate` is waiting for a body, it's not anymore optional :)
@@ -16,7 +16,10 @@ export interface States<TData, TError> { | |||
error?: GetState<TData, TError>["error"]; | |||
} | |||
|
|||
export type MutateMethod<TData, TRequestBody> = (data?: TRequestBody) => Promise<TData>; | |||
export type MutateMethod<TData, TRequestBody> = ( | |||
data: TRequestBody, |
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.
data
is not anymore optional, so we can define string
for DELETE operation.
This is to have a bit more type safety, mutate()
is not possible anymore if a body is required.
Generated by 🚫 dangerJS |
@@ -0,0 +1,21 @@ | |||
declare module "ibm-openapi-validator" { |
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.
Sad that it's not TS.
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.
Can we contribute this to @DefinitelyTyped?
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.
24 stars on github, I've tried but without a lot of hope 😅 I will contribute to definitelyTyped to add this later.
@@ -0,0 +1,21 @@ | |||
declare module "ibm-openapi-validator" { |
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.
Can we contribute this to @DefinitelyTyped?
*/ | ||
const validate = async (schema: OpenAPIObject) => { | ||
// tslint:disable:no-console | ||
const log = console.log; |
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.
Maybe export this from that other place you do it?
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.
It's more have only one no-console
, I prefer to not export this hack ^^ So you need to ask yourself "is it a real usecase or just a console.log for debugging?"
), | ||
); | ||
} | ||
// tslint:enable:no-console |
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.
?
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've disabled the no-console
rule for the block, so I re-enable it ^^
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.
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.
It's great for a first iteration! Let's publish on next
and use it 😍
Why
All the power of this library is the open-api generation, this permit to have auto-completion of our backend api directly in react.
I have the honor to introduce
useMutate
part of this auto-generation! now every route can be generate and use with hooks 🎉Example
For the following spec:
I will have the following components generated:
So I can do in my application:
This is of course fully typesafe, and you have autocompletion on
addPet({name: "Medor"})
💯Validator
I also use this branch to continue on our goal to improve the quality and strictness of our specifications.
Now, https://github.com/IBM/openapi-validator is integrate by default, and we can just add a
.validaterc
in any project to configure the openapi linter 😈Note: This validator is really strict! I've added a
--no-validation
flag to be able to have a more smooth migration to this dream 😅