From 5a60dee838d6d8fe9543a6ed01dd2156e8299282 Mon Sep 17 00:00:00 2001 From: Jamie Macey Date: Sat, 17 Oct 2020 14:15:41 -0700 Subject: [PATCH] Add a spec for #342 body/required --- test-app/app/controllers/stubs_controller.rb | 4 ++++ test-app/spec/integration/openapi3_spec.rb | 23 ++++++++++++++++++- test-app/swagger/v3/openapi.json | 24 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/test-app/app/controllers/stubs_controller.rb b/test-app/app/controllers/stubs_controller.rb index 7a4acd9..8b8ec8f 100644 --- a/test-app/app/controllers/stubs_controller.rb +++ b/test-app/app/controllers/stubs_controller.rb @@ -3,6 +3,10 @@ class StubsController < ApplicationController render plain: 'OK' end + def create + render plain: 'OK' + end + def show render plain: 'OK' end diff --git a/test-app/spec/integration/openapi3_spec.rb b/test-app/spec/integration/openapi3_spec.rb index 051c464..d3e5b5f 100644 --- a/test-app/spec/integration/openapi3_spec.rb +++ b/test-app/spec/integration/openapi3_spec.rb @@ -181,7 +181,28 @@ RSpec.describe 'Generated OpenApi', type: :request, swagger_doc: 'v3/openapi.jso # TODO: Common Parameters end - describe 'Request Body' + describe 'Request Body' do + path '/stubs' do + post 'body is required' do + tags 'Media Types' + consumes 'multipart/form-data' + parameter name: :file, :in => :formData, :type => :file, required: true + + let(:file) { Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/thumbnail.png")) } + + response '200', 'OK' do + run_test! + + it 'declares requestBody is required' do + pending "This output is massaged in SwaggerFormatter#stop, and isn't quite ready here to assert" + tree = swagger_doc.dig(:paths, "/stubs", :post, :requestBody) + expect(tree[:required]).to eq(true) + end + end + end + end + end + describe 'Responses' describe 'Data Models (Schemas)' describe 'Examples' diff --git a/test-app/swagger/v3/openapi.json b/test-app/swagger/v3/openapi.json index a344f69..19983c0 100644 --- a/test-app/swagger/v3/openapi.json +++ b/test-app/swagger/v3/openapi.json @@ -22,6 +22,30 @@ "in": "query" } ] + }, + "post": { + "summary": "body is required", + "tags": [ + "Media Types" + ], + "parameters": [ + + ], + "responses": { + "200": { + "description": "OK" + } + }, + "requestBody": { + "content": { + "multipart/form-data": { + "schema": { + "type": "file" + } + } + }, + "required": true + } } }, "/stubs/{a_param}": {