From b3955959b55874355eb423b517bc642b0645cc9d Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Tue, 30 Jan 2024 16:27:43 +0100 Subject: [PATCH 1/3] Pass extension documentation into schema --- lib/grape-swagger/entity/attribute_parser.rb | 1 + spec/grape-swagger/entities/response_model_spec.rb | 3 ++- spec/support/shared_contexts/this_api.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/grape-swagger/entity/attribute_parser.rb b/lib/grape-swagger/entity/attribute_parser.rb index f4118bd..49de15b 100644 --- a/lib/grape-swagger/entity/attribute_parser.rb +++ b/lib/grape-swagger/entity/attribute_parser.rb @@ -19,6 +19,7 @@ def call(entity_options) entity_model_type = entity_model_type(name, entity_options) return entity_model_type unless documentation + add_extension_documentation(entity_model_type, documentation) add_array_documentation(entity_model_type, documentation) if documentation[:is_array] entity_model_type diff --git a/spec/grape-swagger/entities/response_model_spec.rb b/spec/grape-swagger/entities/response_model_spec.rb index 6ad4b34..16b8894 100644 --- a/spec/grape-swagger/entities/response_model_spec.rb +++ b/spec/grape-swagger/entities/response_model_spec.rb @@ -60,7 +60,8 @@ def app '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.' }, + 'relation' => { '$ref' => '#/definitions/ThisApi_Entities_Relation', 'description' => 'A related model.', + 'x-other' => 'stuff' }, 'code' => { 'type' => 'string', 'description' => 'Error code' }, 'message' => { 'type' => 'string', 'description' => 'Error message' }, 'attr' => { 'type' => 'string', 'description' => 'Attribute' } }, diff --git a/spec/support/shared_contexts/this_api.rb b/spec/support/shared_contexts/this_api.rb index 0ca3142..9ba3a88 100644 --- a/spec/support/shared_contexts/this_api.rb +++ b/spec/support/shared_contexts/this_api.rb @@ -36,7 +36,7 @@ class Something < Grape::Entity expose :kind3, using: ThisApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' } expose :tags, using: ThisApi::Entities::Tag, documentation: { desc: 'Tags.', is_array: true } expose :relation, using: ThisApi::Entities::Relation, - documentation: { type: 'ThisApi::Relation', desc: 'A related model.' } + documentation: { type: 'ThisApi::Relation', desc: 'A related model.', x: { other: 'stuff' } } expose :merged_attribute, using: ThisApi::Entities::Nested, merge: true end end From 21a6f62de8669b4573c6d2151b741367eb78ddde Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Wed, 31 Jan 2024 15:38:03 +0100 Subject: [PATCH 2/3] Fix rubocop offenses --- lib/grape-swagger/entity/attribute_parser.rb | 2 +- spec/support/shared_contexts/this_api.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/grape-swagger/entity/attribute_parser.rb b/lib/grape-swagger/entity/attribute_parser.rb index 49de15b..600fa58 100644 --- a/lib/grape-swagger/entity/attribute_parser.rb +++ b/lib/grape-swagger/entity/attribute_parser.rb @@ -75,7 +75,7 @@ def ambiguous_model_type?(type) def data_type_from(documentation) documented_type = documentation[:type] - documented_type ||= (documentation[:documentation] && documentation[:documentation][:type]) + documented_type ||= documentation[:documentation] && documentation[:documentation][:type] data_type = GrapeSwagger::DocMethods::DataType.call(documented_type) diff --git a/spec/support/shared_contexts/this_api.rb b/spec/support/shared_contexts/this_api.rb index 9ba3a88..21cc91f 100644 --- a/spec/support/shared_contexts/this_api.rb +++ b/spec/support/shared_contexts/this_api.rb @@ -36,7 +36,11 @@ class Something < Grape::Entity expose :kind3, using: ThisApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' } expose :tags, using: ThisApi::Entities::Tag, documentation: { desc: 'Tags.', is_array: true } expose :relation, using: ThisApi::Entities::Relation, - documentation: { type: 'ThisApi::Relation', desc: 'A related model.', x: { other: 'stuff' } } + documentation: { + type: 'ThisApi::Relation', + desc: 'A related model.', + x: { other: 'stuff' } + } expose :merged_attribute, using: ThisApi::Entities::Nested, merge: true end end From 7245469aad87d52c081541cc3df3032870a794a4 Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Wed, 31 Jan 2024 17:36:38 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d52097f..839bfa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ #### Features * Your contribution here. +* [#64](https://github.com/ruby-grape/grape-swagger-entity/pull/64): Pass extension documentation into schema - [@numbata](https://github.com/numbata). #### Fixes @@ -14,7 +15,6 @@ * [#60](https://github.com/ruby-grape/grape-swagger-entity/pull/60): Examples on arrays should be directly on the property, not on the item - [@collinsauve](https://github.com/collinsauve). * [#61](https://github.com/ruby-grape/grape-swagger-entity/pull/61): Migrate from Travis to GHA for CI - [@mscrivo](https://github.com/mscrivo). -* Your contribution here. ### 0.5.1 (2020/06/30)