Skip to content

Add OpenAPI generated Power and VPC gems #8

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

Merged
merged 18 commits into from
Dec 7, 2020

Conversation

agrare
Copy link
Collaborator

@agrare agrare commented Sep 17, 2020

Use the IBM Cloud OpenAPI specifications to generate gems for the various SDKs

Similar to aws-sdk in structure, there is an ibm_cloud gem which pulls in everything and then each OpenAPI file gets its own gem e.g. ibm_cloud_vpc or ibm_cloud_power_iaas.

To build the client gems run rake openapi:generate. This will download the openapi-generator-cli, download each of the API specs, and run the openapi-generator-cli to build the client gem.

$ rake openapi:generate
Downloading openapi-generator-cli-5.0.0-beta2.jar...
Downloading openapi-generator-cli-5.0.0-beta2.jar...Complete
Downloading https://cloud.ibm.com/apidocs/power-cloud.json...
Downloading https://cloud.ibm.com/apidocs/power-cloud.json...Complete
Downloading https://cloud.ibm.com/apidocs/vpc.json...
Downloading https://cloud.ibm.com/apidocs/vpc.json...Complete
Downloading https://cloud.ibm.com/apidocs/iam-identity-token-api.json...
Downloading https://cloud.ibm.com/apidocs/iam-identity-token-api.json...Complete
Downloading https://cloud.ibm.com/apidocs/resource-controller/resource-controller.json...
Downloading https://cloud.ibm.com/apidocs/resource-controller/resource-controller.json...Complete

OpenAPI specifications:

Temporary Manual Steps:

  • ResourceController OpenAPI spec regex warnings: ibm-cloud-sdk-ruby/gems/ibm_cloud_resource_controller/lib/ibm_cloud_resource_controller/models/resource_alias_patch.rb:69: warning: character class has '-' without escape: /^([^[:ascii:]]|[a-zA-Z0-9-._: ])+$/
  • Power Network.type enum should included pub-vlan (only has [vlan, vxlan])

@agrare agrare force-pushed the openapi_power_vpc_gems branch from e5bcabf to e84735a Compare September 17, 2020 01:03
@Fryguy
Copy link
Collaborator

Fryguy commented Sep 17, 2020

@agrare I see there is some IBM Cloud Ruby client over at https://github.com/IBM/ruby-sdk-core ... any reason we can't use that one (or update it if it's missing something? Also I see https://github.ibm.com/CloudEngineering/openapi-sdkgen, which seems to be how they generate the SDKs? I'm fine with recreating from the OpenAPI definitions, but was curious if we even need to.

Use the IBM Cloud OpenAPI specifications to generate gems for the various SDKs

Do you have external links to the OpenAPI specs that you used (so we know where to get them from for future updates)? Or perhaps even better, maybe we can add a bin/rebuild sceript or something that fetches them and runs the generator.

rvm:
- 2.3
- 2.4
- 2.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be updated.

@jaywcarman
Copy link
Collaborator

@Fryguy

Do you have external links to the OpenAPI specs that you used (so we know where to get them from for future updates)? Or perhaps even better, maybe we can add a bin/rebuild sceript or something that fetches them and runs the generator.

You can get them from each API on https://cloud.ibm.com/apidocs

For example, got to the Power Cloud API and click the verticle dots next to the title:
image

@Fryguy
Copy link
Collaborator

Fryguy commented Sep 17, 2020

@jaywcarman Strangely I can't find a direct URL (it does some kind of javascript thing). If we wanted to script pulling it down and running the generator, we'd need that.

@Fryguy
Copy link
Collaborator

Fryguy commented Sep 17, 2020

Got it...good ol' Firefox Network tab: https://cloud.ibm.com/apidocs/power-cloud.json

@Fryguy
Copy link
Collaborator

Fryguy commented Sep 17, 2020

@agrare I'm wondering if we should leave the original json files out, since they are so enormous. Thoughts?

@agrare
Copy link
Collaborator Author

agrare commented Sep 17, 2020

I'm wondering if we should leave the original json files out, since they are so enormous. Thoughts?

Yeah when we script building this first step can be downloading the current spec

@agrare
Copy link
Collaborator Author

agrare commented Sep 17, 2020

I see there is some IBM Cloud Ruby client over at https://github.com/IBM/ruby-sdk-core ... any reason we can't use that one

That didn't appear to have any generated classes for Power or VPC, it looked like https://github.com/IBM/ruby-sdk-core/blob/master/lib/ibm_cloud_sdk_core/base_service.rb might allow you to manually make calls by passing in the service name but it definitely wasn't going to give us everything that doing a gem for power and vpc would. I could absolutely see using that as a "core" (hey that's even what its called) gem for authentications though.

@agrare
Copy link
Collaborator Author

agrare commented Sep 17, 2020

Stumbled on this, btw - https://github.ibm.com/arf/planning-sdk-squad/issues/1980 smile

Yes @jaywcarman was talking with them, they're planning on building gems for the Power API but nothing for ruby which is why I started doing this.

@agrare agrare force-pushed the openapi_power_vpc_gems branch 2 times, most recently from 9bcdab7 to 6c0a76c Compare September 24, 2020 13:00
@agrare agrare force-pushed the openapi_power_vpc_gems branch 3 times, most recently from 71e0bab to aed5be1 Compare September 28, 2020 22:45
@Fryguy
Copy link
Collaborator

Fryguy commented Nov 13, 2020

This rake task is really cool!


task :generate => [:download_cli, :download_openapi_specs] do
IBM_CLOUD_GEMS.each do |api_gem, openapi_json|
openapi_json.sub!("/", "-")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because https://cloud.ibm.com/apidocs/resource-controller/resource-controller.json downloads resource-controller-resource-controller.json There is probably a cleaner way of handling this but this works for now.

@agrare agrare force-pushed the openapi_power_vpc_gems branch from c005508 to 83c1f7f Compare November 13, 2020 18:01

Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == "https") do |http|
request = Net::HTTP::Get.new(uri)
request["User-Agent"] = "Not-Ruby"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL

@agrare agrare force-pushed the openapi_power_vpc_gems branch from f8cb2e5 to 4f170e0 Compare November 16, 2020 22:38
@agrare agrare changed the title [WIP] Add OpenAPI generated Power and VPC gems Add OpenAPI generated Power and VPC gems Dec 4, 2020
Rakefile Outdated
end

task :download_openapi_specs do
require "json"
Copy link
Collaborator

@Fryguy Fryguy Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor, but I don't think this line is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 you're right, I was playing with auto-fixing the vpc spec before generating the clients but now we're deferring that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Collaborator

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I dont have merge rights here.

@jaywcarman
Copy link
Collaborator

LGTM too 👍

@jaywcarman jaywcarman merged commit 16f3d23 into IBM-Cloud:master Dec 7, 2020
@agrare agrare deleted the openapi_power_vpc_gems branch December 7, 2020 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants