From d090516f481dc5ee4037b51294adedbaac861621 Mon Sep 17 00:00:00 2001 From: Jamie Macey Date: Tue, 13 Oct 2020 16:24:51 -0700 Subject: [PATCH] properly list servers for openapi v3 --- test-app/spec/integration/openapi3_spec.rb | 69 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/test-app/spec/integration/openapi3_spec.rb b/test-app/spec/integration/openapi3_spec.rb index 7515ef1..051c464 100644 --- a/test-app/spec/integration/openapi3_spec.rb +++ b/test-app/spec/integration/openapi3_spec.rb @@ -20,22 +20,77 @@ RSpec.describe 'Generated OpenApi', type: :request, swagger_doc: 'v3/openapi.jso let(:swagger_doc) do { # That which would be defined in swagger_helper.rb openapi: api_openapi, - basePath: api_base_path, - schemes: api_schemes, - host: api_host, + info: {}, + servers: api_servers, produces: api_produces, components: api_components } end let(:api_openapi) { '3.0.3' } - let(:api_base_path) { '/foo' } - let(:api_schemes) { ['https'] } - let(:api_host) { 'api.example.com' } + let(:api_servers) {[{ url: "https://api.example.com/foo" }]} let(:api_produces) { ['application/json'] } let(:api_components) { {} } describe 'Basic Structure' - describe 'API Server and Base Path' + + describe 'API Server and Base Path' do + path '/stubs' do + get 'a summary' do + tags 'Server and Path' + + response '200', 'OK' do + run_test! + + it 'lists server' do + tree = swagger_doc.dig(:servers) + expect(tree).to eq([ + { url: "https://api.example.com/foo" } + ]) + end + + context "multiple" do + let(:api_servers) {[ + { url: "https://api.example.com/foo" }, + { url: "http://api.example.com/foo" }, + ]} + + it 'lists servers' do + tree = swagger_doc.dig(:servers) + expect(tree).to eq([ + { url: "https://api.example.com/foo" }, + { url: "http://api.example.com/foo" } + ]) + end + end + + context "with variables" do + let(:api_servers) {[{ + url: "https://{defaultHost}/foo", + variables: { + defaultHost: { + default: "api.example.com" + } + } + }]} + + it 'lists server and variables' do + tree = swagger_doc.dig(:servers) + expect(tree).to eq([{ + url: "https://{defaultHost}/foo", + variables: { + defaultHost: { + default: "api.example.com" + } + } + }]) + end + end + + # TODO: Enum variables, defaults, override at path/operation + end + end + end + end describe 'Media Types' do path '/stubs' do