When making updates to the spec file at https://github.com/LukeHagar/plex-api-spec, I like to test those changes by generating a Ruby gem and using it in a little Ruby script.
This gist is to document how I perform that testing. You can also check out my first pull request which is the basis for this gist.
First, I edit the /pms/paths/xxx file to add a new response format, etc.
I then use the swagger-cli bundle
command to dereference the pms paths.
swagger-cli bundle --dereference pms/pms-spec.yaml -t yaml -o plex-media-server-spec-dereferenced.yaml
To prove that the Ruby SDK generation is working and includes the new changes, I am building a Ruby gem and using it in a test project.
A. Build Ruby gem files using the command:
openapi-generator generate -i plex-media-server-spec-dereferenced.yaml -g ruby -o ../pms-api-ruby
B. Create a test project folder with a Gemfile and a main.rb C. Reference the gem files in your test project Gemfile
source 'https://rubygems.org'
gem 'openapi_client', path: '/path/to/pms-api-ruby'
D. Include gem in project
# Load the gem
require 'bundler/setup'
require 'openapi_client'
E. Set up the OpenapiClient configuration
OpenapiClient.configure do |config|
config.host = '192.168.x.x:32400'
config.debugging = true
# Configure API key authorization: accessToken
config.api_key['accessToken'] = 'xxxxxxxxxxxxxxxxxxxxxx'
end
This part will vary from PR to PR, depending on what feature is being tested.
An example for checking the getLibraries endpoing might look like:
api_instance = OpenapiClient::LibraryApi.new
begin
libraries = api_instance.get_libraries
rescue OpenapiClient::ApiError => e
puts "Exception when calling LibraryApi->get_libraries: #{e}"
end
To show proof of changes, I will copy/paste before/after output of the code to show that, after the changes, the response using the Ruby gem is now updated.
An example of adding the response format for the getLibraries endpoint might look like:
Before Changes Before the change, the output showed nil for the Data value and a status code of 200
D, [2024-01-18T15:23:33.968923 #30434] DEBUG -- : Calling API: LibraryApi.get_libraries ...
GET /library/sections HTTP/1.1
HTTP/1.1 200 OK
D, [2024-01-18T15:23:34.034092 #30434] DEBUG -- : API called: LibraryApi#get_libraries
Data: nil
Status code: 200
After Changes After the change, the output showed the expected body data for the Data value and a status code of 200
D, [2024-01-18T15:23:33.968923 #30434] DEBUG -- : Calling API: LibraryApi.get_libraries ...
GET /library/sections HTTP/1.1
HTTP/1.1 200 OK
D, [2024-01-18T15:23:34.034092 #30434] DEBUG -- : API called: LibraryApi#get_libraries
Data: #<OpenapiClient::GetLibraries200Response:0x000000015944d810 @media_container=# ...... shortened for brevity, but the data is here! >
Status code: 200