-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Features/inheritance and discriminator (#793)
* Add Discrimator * Fix rubocop and add test * Add Changelog * Fix spec_helper and move test * Add Readme * Point grape-swagger-entity to rubygems again * Force new test * Fix rubocop Co-authored-by: peter scholz <pscholz.le@gmail.com>
- Loading branch information
Showing
6 changed files
with
232 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'Inheritance and Discriminator' do | ||
before :all do | ||
module InheritanceTest | ||
module Entities | ||
# example from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#models-with-polymorphism-supports | ||
class Pet < Grape::Entity | ||
expose :type, documentation: { | ||
type: 'string', | ||
is_discriminator: true, | ||
required: true | ||
} | ||
expose :name, documentation: { | ||
type: 'string', | ||
required: true | ||
} | ||
end | ||
|
||
class Cat < Pet | ||
expose :huntingSkill, documentation: { | ||
type: 'string', | ||
description: 'The measured skill for hunting', | ||
default: 'lazy', | ||
values: %w[ | ||
clueless | ||
lazy | ||
adventurous | ||
aggressive | ||
] | ||
} | ||
end | ||
end | ||
class NameApi < Grape::API | ||
add_swagger_documentation models: [Entities::Pet, Entities::Cat] | ||
end | ||
end | ||
end | ||
|
||
context 'Parent model' do | ||
let(:app) { InheritanceTest::NameApi } | ||
|
||
subject do | ||
get '/swagger_doc' | ||
JSON.parse(last_response.body)['definitions'] | ||
end | ||
|
||
specify do | ||
subject['InheritanceTest::Entities::Pet'].key?('discriminator') | ||
subject['InheritanceTest::Entities::Pet']['discriminator'] = 'type' | ||
subject['InheritanceTest::Entities::Cat'].key?('allOf') | ||
end | ||
end | ||
end |