-
Notifications
You must be signed in to change notification settings - Fork 1.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
Generate deployment client from the OpenAPI spec #1149
Conversation
uses the current OpenAPI spec and oas_parser Co-Authored-By: Mark Tareshawty <[email protected]>
oas_parser helps normalize the underlying spec
Co-Authored-By: Mark Tareshawty <[email protected]>
Co-Authored-By: Mark Tareshawty <[email protected]>
Co-Authored-By: Mark Tareshawty <[email protected]>
Co-Authored-By: Jake Wilkins <[email protected]>
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 looks ✨ I don't want to merge it yet because we need to figure out how to keep a 4.x
branch and a new 5.x
branch instead of just merging master while we develop this.
Thanks for all of your hard work @hmharvey
desc "Generate the API client files based on the OpenAPI route docs." | ||
task :generate do | ||
require_relative "lib/openapi_client_generator" | ||
OpenAPIClientGenerator::API.at(OasParser::Definition.resolve("../routes/openapi/api.github.com/index.json")) do |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.
This depends on the right path, but since we're still developing this I think it's alright.
# @param status_id [Integer] The ID of the status | ||
# @return <Sawyer::Resource> A single deployment status | ||
# @see https://developer.github.com/v3/repos/deployments/#get-a-single-deployment-status | ||
def deployment_status(repo, deployment_id, status_id, options = {}) |
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 making a note that this is a breaking change, but we're ok with that. It matches the rest of the client.
lib/openapi_client_generator.rb
Outdated
def required_params | ||
params = definition.parameters.select(&:required).reject {|param| ["owner", "accept"].include?(param.name)} | ||
if definition.request_body | ||
params += definition.request_body.properties_for_format("application/json").select { |param| definition.request_body.content["application/json"]["schema"]["required"].include? param.name } |
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 pretty long, can we make this a multiline block?
lib/openapi_client_generator.rb
Outdated
end | ||
|
||
def self.resource_for_path(path) | ||
return :unsupported unless path.include? "deployment" |
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 make this into an Array? So that we can just add more resources easier?
def self.resource_for_path(path) | ||
return :unsupported unless path.include? "deployment" | ||
path_segments = path.split("/").reject{ |segment| segment == "" } | ||
resource = path_segments[3] |
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 seems pretty magic, does this ever change?
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 definitely will, but it's pretty consistent for the paths under "repos" which was my next focus. I can look further into it, but I felt like it was good enough for now 🤔
Co-Authored-By: Mark Tareshawty <[email protected]>
resource ||= "repositories" | ||
|
||
supported_resources = ["deployments"] | ||
return (supported_resources.include? resource) ? resource : :unsupported |
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.
@tarebyte how does this look? I don't believe return :unsupported unless path.include?(["deployment"])
is valid 🤔
Definitely 👍 |
Part of #1157. An updated spike of #1010 as the underlying api spec has changed. So much thanks to
@kytrinyx
for her work and@tarebyte
for helping me get started ✨This includes a breaking change for
deployment_statuses
andcreate_deployment_status
. We're updating the parameter fromdeployment_url
to use bothrepo
anddeployment_id
as this is more consistent with other methods.This also includes a new method,
deployment_status
, that was previously unsupported.TODO: