Skip to content

Commit 79f937f

Browse files
collinsauvemscrivo
andauthored
Examples on arrays should be directly on the property, not on the item (#60)
* Examples on arrays should directly on the property, not on the item * update CHANGELOG.md * Rubocop updates * Try using 2.7 to fix error * Update README * Fix typo * Try to make danger happy * Add test to exercise fix * Rubocop fixes --------- Co-authored-by: Michael Scrivo <[email protected]>
1 parent 407afcb commit 79f937f

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

.github/workflows/danger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Set up Ruby
1212
uses: ruby/setup-ruby@v1
1313
with:
14-
ruby-version: 3.2
14+
ruby-version: 2.7
1515
bundler-cache: true
1616
rubygems: latest
1717
- name: Run Danger

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000`
3-
# on 2023-07-06 17:02:48 UTC using RuboCop version 1.42.0.
3+
# on 2023-07-06 20:16:40 UTC using RuboCop version 1.42.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new

CHANGELOG.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
#### Fixes
88

9+
* [#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).
910
* [#61](https://github.com/ruby-grape/grape-swagger-entity/pull/61): Migrate from Travis to GHA for CI - [@mscrivo](https://github.com/mscrivo).
1011
* Your contribution here.
1112

12-
### 0.5.1 (June 30, 2020)
13+
### 0.5.1 (2020/06/30)
1314

1415
#### Features
1516

1617
* [#50](https://github.com/ruby-grape/grape-swagger-entity/pull/50): Features/inheritance and discriminator - [@MaximeRDY](https://github.com/MaximeRDY).
1718

18-
### 0.4.0 (May 30, 2020)
19+
### 0.4.0 (2020/05/30)
1920

2021
#### Features
2122

@@ -26,81 +27,81 @@
2627

2728
* [#46](https://github.com/ruby-grape/grape-swagger-entity/pull/46): Fixed issue where a boolean example value of false would not display in swagger file - [@drewnichols](https://github.com/drewnichols).
2829

29-
### 0.3.4 (January 9, 2020)
30+
### 0.3.4 (2020/01/09)
3031

3132
#### Features
3233

3334
* [#40](https://github.com/ruby-grape/grape-swagger-entity/pull/40): Add support for minLength and maxLength - [@fotos](https://github.com/fotos).
3435

35-
### 0.3.3 (February 22, 2019)
36+
### 0.3.3 (2019/02/22)
3637

3738
#### Features
3839

3940
* [#39](https://github.com/ruby-grape/grape-swagger-entity/pull/39): Fix to avoid conflict with polymorphic model - [@kinoppyd](https://github.com/kinoppyd).
4041

41-
### 0.3.2 (January 15, 2019)
42+
### 0.3.2 (2019/01/15)
4243

4344
#### Features
4445

4546
* [#38](https://github.com/ruby-grape/grape-swagger-entity/pull/38): Added support for hidden option for documentation - [@vitoravelino](https://github.com/vitoravelino).
4647

47-
### 0.3.1 (November 26, 2018)
48+
### 0.3.1 (2018/11/26)
4849

4950
#### Features
5051

5152
* [#37](https://github.com/ruby-grape/grape-swagger-entity/pull/37): Add support for minItems, maxItems and uniqueItems - [@fotos](https://github.com/fotos).
5253

53-
### 0.3.0 (August 22, 2018)
54+
### 0.3.0 (2018/08/22)
5455

5556
#### Features
5657

5758
* [#35](https://github.com/ruby-grape/grape-swagger-entity/pull/35): Support for required attributes - [@Bugagazavr](https://github.com/Bugagazavr).
5859

59-
### 0.2.5 (April 26, 2018)
60+
### 0.2.5 (2018/04/26)
6061

6162
#### Features
6263

6364
* [#33](https://github.com/ruby-grape/grape-swagger-entity/pull/33): Update parser to respect merge option for entities - [@b-boogaard](https://github.com/b-boogaard).
6465

65-
### 0.2.4 (April 3, 2018)
66+
### 0.2.4 (2018/04/03)
6667

6768
#### Fixes
6869

6970
* [#32](https://github.com/ruby-grape/grape-swagger-entity/pull/32): Fix issue with read_only fields - [@mcfilib](https://github.com/mcfilib).
7071

71-
### 0.2.3 (November 19, 2017)
72+
### 0.2.3 (2017/11/19)
7273

7374
#### Fixes
7475

7576
* [#30](https://github.com/ruby-grape/grape-swagger-entity/pull/30): Fix nested exposures with an alias - [@Kukunin](https://github.com/Kukunin).
7677
* [#31](https://github.com/ruby-grape/grape-swagger-entity/pull/31): Respect `required: true` for nested attributes as well - [@Kukunin](https://github.com/Kukunin).
7778

78-
### 0.2.2 (November 3, 2017)
79+
### 0.2.2 (2017/11/3)
7980

8081
#### Features
8182

8283
* [#27](https://github.com/ruby-grape/grape-swagger-entity/pull/27): Add support for attribute examples - [@Kukunin](https://github.com/Kukunin).
8384

84-
### 0.2.1 (Jule 5, 2017)
85+
### 0.2.1 (2017/07/05)
8586

8687
#### Features
8788

8889
* [#26](https://github.com/ruby-grape/grape-swagger-entity/pull/26): Add support for read only field - [@FChaack](https://github.com/FChaack).
8990

90-
### 0.2.0 (March 2, 2017)
91+
### 0.2.0 (2017/03/02)
9192

9293
#### Features
9394

9495
* [#22](https://github.com/ruby-grape/grape-swagger-entity/pull/22): Nested exposures - [@Bugagazavr](https://github.com/Bugagazavr).
9596

96-
### 0.1.6 (February 3, 2017)
97+
### 0.1.6 (2017/02/03)
9798

9899
#### Features
99100

100101
* [#21](https://github.com/ruby-grape/grape-swagger-entity/pull/21): Adds support for own format - [@LeFnord](https://github.com/LeFnord).
101102
* [#19](https://github.com/ruby-grape/grape-swagger-entity/pull/19): Adds support for default value - [@LeFnord](https://github.com/LeFnord).
102103

103-
### 0.1.5 (November 21, 2016)
104+
### 0.1.5 (2016/11/21)
104105

105106
#### Features
106107

@@ -112,7 +113,7 @@
112113
* [#8](https://github.com/ruby-grape/grape-swagger-entity/pull/8): Generate enum property if values key is passed in documentation - [@lordnibbler](https://github.com/lordnibbler).
113114
* [#15](https://github.com/ruby-grape/grape-swagger-entity/pull/15): Support grape entity 0.6.x and later - [@Bugagazavr](https://github.com/Bugagazavr).
114115

115-
### 0.1.4 (June 7, 2016)
116+
### 0.1.4 (2016/06/07)
116117

117118
#### Fixes
118119

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
[![Gem Version](https://badge.fury.io/rb/grape-swagger-entity.svg)](https://badge.fury.io/rb/grape-swagger-entity)
44
[![Build Status](https://github.com/ruby-grape/grape-swagger-entity/workflows/test/badge.svg?branch=master)](https://github.com/ruby-grape/grape-swagger-entity/actions)
55

6+
## Table of Contents
7+
8+
- [What is grape-swagger-entity?](#what-is-grape-swagger-entity)
9+
- [Installation](#installation)
10+
- [Development](#development)
11+
- [Contributing](#contributing)
12+
- [License](#license)
13+
14+
15+
## What is grape-swagger-entity?
16+
617
A simple grape-swagger adapter to allow parse representers as response model
718

819
## Installation

lib/grape-swagger/entity/attribute_parser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ def call(entity_options)
2626
param = data_type_from(entity_options)
2727
return param unless documentation
2828

29-
add_attribute_sample(param, documentation, :default)
30-
add_attribute_sample(param, documentation, :example)
31-
3229
if (values = documentation[:values]) && values.is_a?(Array)
3330
param[:enum] = values
3431
end
@@ -38,6 +35,9 @@ def call(entity_options)
3835
add_array_documentation(param, documentation)
3936
end
4037

38+
add_attribute_sample(param, documentation, :default)
39+
add_attribute_sample(param, documentation, :example)
40+
4141
add_attribute_documentation(param, documentation)
4242

4343
add_extension_documentation(param, documentation)

spec/grape-swagger/entity/attribute_parser_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
it { is_expected.to include(type: :array) }
8282
it { is_expected.to include(items: { type: 'string' }) }
8383

84+
context 'when it contains example' do
85+
let(:entity_options) do
86+
{ documentation: { type: 'string', desc: 'Colors', is_array: true, example: %w[green blue] } }
87+
end
88+
89+
it { is_expected.to include(example: %w[green blue]) }
90+
end
91+
8492
context 'when it contains min_items' do
8593
let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', is_array: true, min_items: 1 } } }
8694

0 commit comments

Comments
 (0)