diff --git a/CHANGELOG.md b/CHANGELOG.md index b426c1b..237f2e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ #### Features * Your contribution here. + +#### Fixes + +* Your contribution here. + +### 0.5.1 (June 30, 2020) + +#### Features + * [#50](https://github.com/ruby-grape/grape-swagger-entity/pull/50): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY). ### 0.4.0 (May 30, 2020) diff --git a/grape-swagger-entity.gemspec b/grape-swagger-entity.gemspec index 1031cf2..46ed2cd 100644 --- a/grape-swagger-entity.gemspec +++ b/grape-swagger-entity.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.4' s.add_runtime_dependency 'grape-entity', '>= 0.6.0' - s.add_runtime_dependency 'grape-swagger', '>= 1.0.0' + s.add_runtime_dependency 'grape-swagger', '>= 1.2.0' end diff --git a/lib/grape-swagger/entity/version.rb b/lib/grape-swagger/entity/version.rb index 33c56e4..f90cf75 100644 --- a/lib/grape-swagger/entity/version.rb +++ b/lib/grape-swagger/entity/version.rb @@ -2,6 +2,6 @@ module GrapeSwagger module Entity - VERSION = '0.4.0' + VERSION = '0.5.1' end end diff --git a/spec/grape-swagger/entities/response_model_spec.rb b/spec/grape-swagger/entities/response_model_spec.rb index 9a6308b..355f91b 100644 --- a/spec/grape-swagger/entities/response_model_spec.rb +++ b/spec/grape-swagger/entities/response_model_spec.rb @@ -20,7 +20,7 @@ def app 'description' => 'OK', 'schema' => { 'type' => 'array', - 'items' => { '$ref' => '#/definitions/ThisApi::Entities::Something' } + 'items' => { '$ref' => '#/definitions/ThisApi_Entities_Something' } } } ) @@ -30,15 +30,15 @@ def app expect(subject['paths']['/something/{id}']['get']['responses']).to eq( '200' => { 'description' => 'OK', - 'schema' => { '$ref' => '#/definitions/ThisApi::Entities::Something' } + 'schema' => { '$ref' => '#/definitions/ThisApi_Entities_Something' } }, '403' => { 'description' => 'Refused to return something', - 'schema' => { '$ref' => '#/definitions/ThisApi::Entities::Error' } + 'schema' => { '$ref' => '#/definitions/ThisApi_Entities_Error' } } ) - expect(subject['definitions'].keys).to include 'ThisApi::Entities::Error' - expect(subject['definitions']['ThisApi::Entities::Error']).to eq( + expect(subject['definitions'].keys).to include 'ThisApi_Entities_Error' + expect(subject['definitions']['ThisApi_Entities_Error']).to eq( 'type' => 'object', 'description' => 'This returns something or an error', 'properties' => { @@ -47,36 +47,36 @@ def app } ) - expect(subject['definitions'].keys).to include 'ThisApi::Entities::Something' - expect(subject['definitions']['ThisApi::Entities::Something']).to eq( + expect(subject['definitions'].keys).to include 'ThisApi_Entities_Something' + expect(subject['definitions']['ThisApi_Entities_Something']).to eq( 'type' => 'object', 'description' => 'This returns something', 'properties' => { 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, 'colors' => { 'type' => 'array', 'items' => { 'type' => 'string' }, 'description' => 'Colors' }, - 'kind' => { '$ref' => '#/definitions/ThisApi::Entities::Kind', 'description' => 'The kind of this something.' }, - 'kind2' => { '$ref' => '#/definitions/ThisApi::Entities::Kind', 'description' => 'Secondary kind.' }, - 'kind3' => { '$ref' => '#/definitions/ThisApi::Entities::Kind', 'description' => 'Tertiary kind.' }, - 'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/ThisApi::Entities::Tag' }, 'description' => 'Tags.' }, - 'relation' => { '$ref' => '#/definitions/ThisApi::Entities::Relation', 'description' => 'A related model.' }, + 'kind' => { '$ref' => '#/definitions/ThisApi_Entities_Kind', 'description' => 'The kind of this something.' }, + 'kind2' => { '$ref' => '#/definitions/ThisApi_Entities_Kind', 'description' => 'Secondary kind.' }, + 'kind3' => { '$ref' => '#/definitions/ThisApi_Entities_Kind', 'description' => 'Tertiary kind.' }, + 'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/ThisApi_Entities_Tag' }, 'description' => 'Tags.' }, + 'relation' => { '$ref' => '#/definitions/ThisApi_Entities_Relation', 'description' => 'A related model.' }, 'code' => { 'type' => 'string', 'description' => 'Error code' }, 'message' => { 'type' => 'string', 'description' => 'Error message' }, 'attr' => { 'type' => 'string', 'description' => 'Attribute' } }, 'required' => ['attr'] ) - expect(subject['definitions'].keys).to include 'ThisApi::Entities::Kind' - expect(subject['definitions']['ThisApi::Entities::Kind']).to eq( + expect(subject['definitions'].keys).to include 'ThisApi_Entities_Kind' + expect(subject['definitions']['ThisApi_Entities_Kind']).to eq( 'type' => 'object', 'properties' => { 'title' => { 'type' => 'string', 'description' => 'Title of the kind.' }, 'content' => { 'description' => 'Content', 'type' => 'string', 'x-some' => 'stuff' } } ) - expect(subject['definitions'].keys).to include 'ThisApi::Entities::Relation' - expect(subject['definitions']['ThisApi::Entities::Relation']).to eq( + expect(subject['definitions'].keys).to include 'ThisApi_Entities_Relation' + expect(subject['definitions']['ThisApi_Entities_Relation']).to eq( 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } ) - expect(subject['definitions'].keys).to include 'ThisApi::Entities::Tag' - expect(subject['definitions']['ThisApi::Entities::Tag']).to eq( + expect(subject['definitions'].keys).to include 'ThisApi_Entities_Tag' + expect(subject['definitions']['ThisApi_Entities_Tag']).to eq( 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } ) end @@ -140,11 +140,11 @@ class Polymorphic < Grape::Entity class SomeEntity < Grape::Entity expose :text, documentation: { type: 'string', desc: 'Content of something.' } - expose :kind, using: Kind, documentation: { type: 'TheseApi::Kind', desc: 'The kind of this something.' } + expose :kind, using: Kind, documentation: { type: 'TheseApi_Kind', desc: 'The kind of this something.' } expose :kind2, using: Kind, documentation: { desc: 'Secondary kind.' } expose :kind3, using: TheseApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' } expose :tags, using: TheseApi::Entities::Tag, documentation: { desc: 'Tags.', is_array: true } - expose :relation, using: TheseApi::Entities::Relation, documentation: { type: 'TheseApi::Relation', desc: 'A related model.' } + expose :relation, using: TheseApi::Entities::Relation, documentation: { type: 'TheseApi_Relation', desc: 'A related model.' } expose :values, using: TheseApi::Entities::Values, documentation: { desc: 'Tertiary kind.' } expose :nested, using: TheseApi::Entities::Nested, documentation: { desc: 'Nested object.' } expose :polymorphic, using: TheseApi::Entities::Polymorphic, documentation: { desc: 'Polymorphic Model' } @@ -177,14 +177,14 @@ def app end it 'prefers entity over other `using` values' do - expect(subject['TheseApi::Entities::Values']).to eql( + expect(subject['TheseApi_Entities_Values']).to eql( 'type' => 'object', 'properties' => { 'guid' => { 'type' => 'string', 'enum' => %w[a b c], 'default' => 'c', 'description' => 'Some values' }, 'uuid' => { 'type' => 'string', 'format' => 'own', 'description' => 'customer uuid', 'example' => 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' } } ) - expect(subject['TheseApi::Entities::Kind']).to eql( + expect(subject['TheseApi_Entities_Kind']).to eql( 'type' => 'object', 'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'id of the kind.', 'enum' => [1, 2], 'readOnly' => true }, @@ -192,13 +192,13 @@ def app 'type' => { 'type' => 'string', 'description' => 'Type of the kind.', 'readOnly' => true } } ) - expect(subject['TheseApi::Entities::Tag']).to eql( + expect(subject['TheseApi_Entities_Tag']).to eql( 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name', 'example' => 'random_tag' } } ) - expect(subject['TheseApi::Entities::Relation']).to eql( + expect(subject['TheseApi_Entities_Relation']).to eql( 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } ) - expect(subject['TheseApi::Entities::Nested']).to eq( + expect(subject['TheseApi_Entities_Nested']).to eq( 'properties' => { 'nested' => { 'type' => 'object', @@ -250,30 +250,30 @@ def app }, 'type' => 'object' ) - expect(subject['TheseApi::Entities::Polymorphic']).to eql( + expect(subject['TheseApi_Entities_Polymorphic']).to eql( 'type' => 'object', 'properties' => { - 'kind' => { '$ref' => '#/definitions/TheseApi::Entities::Kind', 'description' => 'Polymorphic Kind' }, - 'values' => { '$ref' => '#/definitions/TheseApi::Entities::Values', 'description' => 'Polymorphic Values' }, + 'kind' => { '$ref' => '#/definitions/TheseApi_Entities_Kind', 'description' => 'Polymorphic Kind' }, + 'values' => { '$ref' => '#/definitions/TheseApi_Entities_Values', 'description' => 'Polymorphic Values' }, 'str' => { 'type' => 'string', 'description' => 'Polymorphic String' }, 'num' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Polymorphic Number' } } ) - expect(subject['TheseApi::Entities::SomeEntity']).to eql( + expect(subject['TheseApi_Entities_SomeEntity']).to eql( 'type' => 'object', 'properties' => { 'text' => { 'type' => 'string', 'description' => 'Content of something.' }, - 'kind' => { '$ref' => '#/definitions/TheseApi::Entities::Kind', 'description' => 'The kind of this something.' }, - 'kind2' => { '$ref' => '#/definitions/TheseApi::Entities::Kind', 'description' => 'Secondary kind.' }, - 'kind3' => { '$ref' => '#/definitions/TheseApi::Entities::Kind', 'description' => 'Tertiary kind.' }, - 'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/TheseApi::Entities::Tag' }, 'description' => 'Tags.' }, - 'relation' => { '$ref' => '#/definitions/TheseApi::Entities::Relation', 'description' => 'A related model.' }, - 'values' => { '$ref' => '#/definitions/TheseApi::Entities::Values', 'description' => 'Tertiary kind.' }, - 'nested' => { '$ref' => '#/definitions/TheseApi::Entities::Nested', 'description' => 'Nested object.' }, + 'kind' => { '$ref' => '#/definitions/TheseApi_Entities_Kind', 'description' => 'The kind of this something.' }, + 'kind2' => { '$ref' => '#/definitions/TheseApi_Entities_Kind', 'description' => 'Secondary kind.' }, + 'kind3' => { '$ref' => '#/definitions/TheseApi_Entities_Kind', 'description' => 'Tertiary kind.' }, + 'tags' => { 'type' => 'array', 'items' => { '$ref' => '#/definitions/TheseApi_Entities_Tag' }, 'description' => 'Tags.' }, + 'relation' => { '$ref' => '#/definitions/TheseApi_Entities_Relation', 'description' => 'A related model.' }, + 'values' => { '$ref' => '#/definitions/TheseApi_Entities_Values', 'description' => 'Tertiary kind.' }, + 'nested' => { '$ref' => '#/definitions/TheseApi_Entities_Nested', 'description' => 'Nested object.' }, 'code' => { 'type' => 'string', 'description' => 'Error code' }, 'message' => { 'type' => 'string', 'description' => 'Error message' }, - 'polymorphic' => { '$ref' => '#/definitions/TheseApi::Entities::Polymorphic', 'description' => 'Polymorphic Model' }, + 'polymorphic' => { '$ref' => '#/definitions/TheseApi_Entities_Polymorphic', 'description' => 'Polymorphic Model' }, 'attr' => { 'type' => 'string', 'description' => 'Attribute' } }, 'required' => %w[attr],