-
Notifications
You must be signed in to change notification settings - Fork 1.1k
(WIP) Openapi client gen #144
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
Open
Stonelinks
wants to merge
11
commits into
abetlen:main
Choose a base branch
from
Stonelinks:openapi-client-gen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or 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
e12101d
to
4f89e2f
Compare
Fixed up the last commit to include examples that:
|
453226d
to
b2233fe
Compare
b2233fe
to
68f1b57
Compare
68f1b57
to
5dafdab
Compare
The README says to run `python3 setup.py develop` to build the library, however on a blank install this fails because scikit-build is not installed. This adds it to the dev dependencies so that it is installed.
Its cleaner to keep the virtualenv in the project directory, and poetry makes it easy to do that via this config.
Give folks options + explicit instructions for installing with poetry or pip.
…y are unsupported but there for API compatibility with openai
This script is used to download the openapi json from the server and save it to a file. In the next commit this file is then used by the client to generate the client code. This script is meant to be invoked from the root of the repository, i.e. `./bin/save-openapi-json`.
I tried a bunch of generators - they all had issues. Some generated thousands of lines of unintelligible code. Others generated code that had errors, failed because of our spec or made weird assumptions about library structure. Others I didn't even bother with since they seemed abandoned. I eventually settled on https://github.com/Azure/autorest by Microsoft. Its got some things going for it: - It works! - Its tested and documented - It gives decent configuration options for the generator - It allows for decent customization by users and consumers of the client - It can (eventually) support streaming responses from the server - The only dependency is docker - Its actually supported by a large organization / number of developers - It could be trivially extended to generate clients for multiple languages besides python The downsides: - Its still generating a lot of code that isn't very idiomatic python (but its still reasonable to follow) - It depends on some Microsoft / Azure libraries for basic things instead... they're probably fine but its still a bit weird to be using msrest and azure-core instead of like... pydantic and requests. - The docker container is slow to start since it always downloads the latest version of autorest Overall the pros outweigh the cons IMO... Going to go forward with this.
Result of running ./bin/generate_api_client
Includes examples that: - Synchronously use the openapi client to make requests - Asynchronously use the openapi client to make requests - Make a streaming asynchronous request (just uses the autogenerated models for now)
5dafdab
to
2d6ef25
Compare
@Stonelinks I found this too, so I co-founded a company to generate idiomatic client code. Check out Fern as an easy way to pass in your OpenAPI spec and get a Python client that supports for sync and async clients out of the box. Read more about the Python generator |
8c93cf8
to
cc0fe43
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Putting this up for feedback, but this is the autogenerated openapi client for the server.
There's a lot of commits in here since this branch is based on:
So the changes will be easier to review if / when those make it into master.
But the last 5 or 6 commits are what this PR is ultimately for: infrastructure to autogenerate a client based on the openapi specification.
At a high level here's what these commits do:
Missing:
Maybe the most controversial part of this is the decision to go with autorest when there are other codegen solutions out there for openapi clients. I wrote a long commit message about this (which i'll copy-paste here) but here are my thoughts on the matter:
Its got some things going for it:
The downsides: