-
Notifications
You must be signed in to change notification settings - Fork 29
SDK Generation #28
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
SDK Generation #28
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.
Some really great progress here! 💪
@gkoberger @domharrington I decided to sleep on it and I'm going to stick with the arg format as A major portion of API requests will only constitute |
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.
Just a few comments on the README.md — haven't taken a look at the code yet!
@@ -1,2 +1,125 @@ | |||
# api | |||
# 🚀 api |
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.
whoooooosh
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.
We need an astronaut Owlbert.
Co-authored-by: Kanad Gupta <kanad@readme.io>
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.
What's support for Proxy like?
This is incredible. Ran it locally and it worked like a charm by fetching the spec file and everything. I wasn't sure if Proxy would be possible, and I still don't completely understand how it works but it's amazing.
Really hyped for the release of this! 💪
run: npm ci | ||
|
||
- name: tests | ||
- name: Run tests |
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 get code coverage sent up to codecov.io?
|
||
expect.extend({ | ||
// Custom matcher so we can easily test that dereferencing of OpenAPI files is working as expected. | ||
toBeDereferenced(received) { |
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.
This is really nifty!
}; | ||
} | ||
|
||
return async function (...args) { |
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.
@domharrington Proxy is supported currently in Node 6+, every non-IE browser, and Safari (though it doesn't support |
🧰 What's being changed?
This completely rewrites the existing
api
module to focus on the autogeneration of SDKs from an OpenAPI 3.x document. For example:📓 How does it work?
Proxies! Proxies are a recent addition to JS that allows for one to create wildcard-y object accessors. With this we can create an SDK proxy that has the base methods all SDKs have (like
.auth()
), and then automatically allow for the end-user to access operations like.getChangelogs()
or.get()
on the chain.What'll happen when a user first makes a request via
.getChangelogs()
is that we'll fetch the OpenAPI definition they supplied, process it, cache it intonode_modules/.cache/api
, and run through the definition to add any present operation IDs as chainable methods (like.getChangelogs()
on the Proxy. On subsequent requests, the OpenAPI definition is re-fetched from the local cache, and re-added to the Proxy.It's like magic.
🎙How do I make requests?
With the chained operation IDs, or HTTP verb methods like GET or POST, that are automatically generated onto the SDK, you can pass them parameters and request body payloads by supplying either a
body
object or array, and/or ametadata
(parameters) object. The SDK will then determine, according to the OpenAPI definition, what goes where. For example:metadata
:sdk.showPetById({ petId: 1234 }).then(...)
body
:sdk.createPets({ name: 'Buster' }).then(...)
sdk.updatePet({ name: 'Buster 2' }, { petId: 1234 }).then(...)
🧪 Testing
To test out the SDK, give it an OpenAPI URL or local file and go wild.