-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
🐙 octavia-cli: generate open api client #9277
Conversation
d0c8f67
to
2afe6c2
Compare
9cb23df
to
0d5ad55
Compare
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.
only blocking because i don't understand the chnages in airbyte-api/src/main/openapi/config.yaml. otherwise it looks good! nice use of the docker open api generator container!
@@ -1944,8 +1944,10 @@ components: | |||
$ref: "#/components/schemas/Notification" | |||
firstCompletedSync: | |||
type: boolean | |||
nullable: true |
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 are you trying to achieve here? because these fields are not in the required
list above they should already be nullable and should not require the extra nullable
field.
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.
When I called the workspace endpoint with the generated API client it raises an error during serialization of the response because it expected this field to be not nullable. When I make this change in config.yaml
the problem is bypassed. I'm going to check if I can find another solution by tweaking some generator options, otherwise, I'll have to make these kinds of changes in config.yaml
for other endpoints that will be used in the future, which is not ideal.
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.
yeah. that seems like kinda big deal. swagger generation is always a little jenky around the edges, but nullable fields is a pretty core feature, so it seems like a really bad sign if the generator can't handle it because it means there will be other problems.
one thing to test is instead of using the nullable
field if instead setting type: [boolean, null]
works. I don't like this as much as the pattern we already use but if we needed to switch to this pattern it may not be the end of the world.
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 found this issue OpenAPITools/openapi-generator#4816 on OpenApiTools repo, this is for their C# generator but it looks like the exact same problem I have with the Python one. I'll continue to investigate and try type: [boolean, null]
. Let me know if you think that I should rather implement the client myself.
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 definitely don't want to implement it ourselves. my guess is the C# bug is language specific (since C# is actually a typed language)
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 tried [boolean, null]
but this is not a valid spec according to open-api-generator.
I think I found a workaround. I can disable the type validation of the response. It also disables deserialization to a model and leads us to manipulate the raw response as a python dict. It's not the most elegant solution but I prefer this rather than editing the API spec. Related commit: a586719
I also reverted my changes on airbyte-api
's config.yaml
.
octavia-cli/build.gradle
Outdated
@@ -7,3 +7,12 @@ airbytePython { | |||
moduleDirectory 'octavia_cli' | |||
} | |||
|
|||
task generateApiClient(type: Exec) { |
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.
does the caching work properly on this task? the expectation should be that if airbyte-api/src/main/openapi/config.yaml
does not change that this task does not need to run again. if that's not set up properly it will require re-executing this task and every tasks that depends on them (which is most of them).
see UP-TO-DATE
in https://docs.gradle.org/current/userguide/more_about_tasks.html
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.
Thanks for this suggestion! I realized I could use a grade plugin already used for java API client generation: org.openapitools.generator.gradle.plugin.tasks.GenerateTask
. It supports incremental builds, but I can't figure why it's not working in my context.
I did the following in b285449:
- update
octavia-cli/build.gradle
to use the GenerateTask. - exclude the generated client from the license headers checks.
- remove the script I wrote to generate the client with the docker image.
Still, I don't get why I can't see the UP-TO-DATE
flag after consequent builds.
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 finally made the FROM-CACHE
and UP-TO-DATE
mechanisms work. The solution was to use the buildDir
as output dir. Using other paths made Gradle re-run the task on each run. The generated client is now stored in octavia-cli/build/airbyte_api_client
. Related commit: e95abc9
I confirm that changes in airbyte-api/src/main/openapi/config.yaml
will trigger a regeneration of the client on SUB_BUILD=OCTAVIA_CLI ./gradlew build
.
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.
awesome!
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'd like you to present this very briefly in the dev meeting. This is something we often get wrong when using gradle, so it would be good to have a 5 minute presentation to share the knowledge with the team.
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.
ok! To be honest, I'm not understanding why using input paths for tasks that are not buildDir
does not lead to UP-TO-DATE
but it could indeed be interesting to share this finding and to open this discussion in the dev meeting.
def test_octavia(): | ||
@click.command() | ||
@click.pass_context | ||
def dumb(ctx): |
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.
looks good! don't love that we can't used the typed objects in python, but i agree with you, i can't think of another workaround.
What
We need an API client to make octavia-cli talk with Airbyte's API.
Airbyte API's uses Open API specs, making it easy to autogenerate a python client with
openapitools/openapi-generator-cli
.How
openapi-generator-cli
docker image fromairbyte-api/src/main/openapi/config.yaml
.octavia-cli/build.gradle
.airbyte-api/src/main/openapi/config.yaml
octavia-cli/airbyte_api_client
octavia
command group to retrieve the Airbyte workspace's idNow running
octavia --airbyte-url https://demo.airbyte.io list
outputs:Recommended reading order
octavia-cli/bin/generate-api-client.sh
+octavia-cli/build.gradle
> Run the API client generation on build.airbyte-api/src/main/openapi/config.yaml
declare some workspace-related field as nullable to make the generated client work.octavia-cli/setup.py
: Addairbyte_api_client
as anoctavia-cli
dependencyoctavia-cli/octavia_cli/entrypoint.py
: Make use of the client in theoctavia
command group to retrieve the workspace id and store it into the CLI context.octavia-cli/unit_tests/test_entrypoint.py
: Unit test theoctavia
command group .🚨 User Impact 🚨
No impact as the
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/SUMMARY.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesThis change is