opensearch-project / opensearch-ruby

Ruby Client for OpenSearch
Apache License 2.0
93 stars 47 forks source link

Update code generator to use new version of OpenAPI specification #233

Open Xtansia opened 6 months ago

Xtansia commented 6 months ago

The https://github.com/opensearch-project/opensearch-api-specification repository has been updated to be written natively in OpenAPI, rather than being built from Smithy. This means that some structure and details of the specification has changed. The code generator should be updated to use this new version of the specification. Any changes to the generated output should be validated to confirm if the changes are correct by cross referencing with the OpenSearch implementation & documentation. Any errors found in the specification should be reported on the specification repository.

dblock commented 2 months ago

The existing ruby OpenAPI parser seems not to support OpenAPI 3.1, but I was still able to load our spec.

require 'open-uri'
require 'openapi3_parser'

openapi_url = "https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml"
openapi_path = "opensearch-openapi.yaml"
File.write(openapi_path, URI.open(openapi_url).read) unless File.exists?(openapi_path)
puts "Loading #{openapi_path} (#{File.size(openapi_path)} byte(s)) ..."

doc = Openapi3Parser.load_file(openapi_path)
puts "Loaded #{openapi_url} with #{doc.paths.size} path(s)."

doc.paths.keys.each do |key|
   puts key
end