Skip to content

Commit

Permalink
Examples on arrays should be directly on the property, not on the item (
Browse files Browse the repository at this point in the history
ruby-grape#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]>
  • Loading branch information
collinsauve and mscrivo authored Jul 6, 2023
1 parent 407afcb commit 79f937f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/danger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
ruby-version: 2.7
bundler-cache: true
rubygems: latest
- name: Run Danger
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 5000`
# on 2023-07-06 17:02:48 UTC using RuboCop version 1.42.0.
# on 2023-07-06 20:16:40 UTC using RuboCop version 1.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down
33 changes: 17 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

#### Fixes

* [#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 (June 30, 2020)
### 0.5.1 (2020/06/30)

#### 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)
### 0.4.0 (2020/05/30)

#### Features

Expand All @@ -26,81 +27,81 @@

* [#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).

### 0.3.4 (January 9, 2020)
### 0.3.4 (2020/01/09)

#### Features

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

### 0.3.3 (February 22, 2019)
### 0.3.3 (2019/02/22)

#### Features

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

### 0.3.2 (January 15, 2019)
### 0.3.2 (2019/01/15)

#### Features

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

### 0.3.1 (November 26, 2018)
### 0.3.1 (2018/11/26)

#### Features

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

### 0.3.0 (August 22, 2018)
### 0.3.0 (2018/08/22)

#### Features

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

### 0.2.5 (April 26, 2018)
### 0.2.5 (2018/04/26)

#### Features

* [#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).

### 0.2.4 (April 3, 2018)
### 0.2.4 (2018/04/03)

#### Fixes

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

### 0.2.3 (November 19, 2017)
### 0.2.3 (2017/11/19)

#### Fixes

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

### 0.2.2 (November 3, 2017)
### 0.2.2 (2017/11/3)

#### Features

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

### 0.2.1 (Jule 5, 2017)
### 0.2.1 (2017/07/05)

#### Features

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

### 0.2.0 (March 2, 2017)
### 0.2.0 (2017/03/02)

#### Features

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

### 0.1.6 (February 3, 2017)
### 0.1.6 (2017/02/03)

#### Features

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

### 0.1.5 (November 21, 2016)
### 0.1.5 (2016/11/21)

#### Features

Expand All @@ -112,7 +113,7 @@
* [#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).
* [#15](https://github.com/ruby-grape/grape-swagger-entity/pull/15): Support grape entity 0.6.x and later - [@Bugagazavr](https://github.com/Bugagazavr).

### 0.1.4 (June 7, 2016)
### 0.1.4 (2016/06/07)

#### Fixes

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
[![Gem Version](https://badge.fury.io/rb/grape-swagger-entity.svg)](https://badge.fury.io/rb/grape-swagger-entity)
[![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)

## Table of Contents

- [What is grape-swagger-entity?](#what-is-grape-swagger-entity)
- [Installation](#installation)
- [Development](#development)
- [Contributing](#contributing)
- [License](#license)


## What is grape-swagger-entity?

A simple grape-swagger adapter to allow parse representers as response model

## Installation
Expand Down
6 changes: 3 additions & 3 deletions lib/grape-swagger/entity/attribute_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def call(entity_options)
param = data_type_from(entity_options)
return param unless documentation

add_attribute_sample(param, documentation, :default)
add_attribute_sample(param, documentation, :example)

if (values = documentation[:values]) && values.is_a?(Array)
param[:enum] = values
end
Expand All @@ -38,6 +35,9 @@ def call(entity_options)
add_array_documentation(param, documentation)
end

add_attribute_sample(param, documentation, :default)
add_attribute_sample(param, documentation, :example)

add_attribute_documentation(param, documentation)

add_extension_documentation(param, documentation)
Expand Down
8 changes: 8 additions & 0 deletions spec/grape-swagger/entity/attribute_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
it { is_expected.to include(type: :array) }
it { is_expected.to include(items: { type: 'string' }) }

context 'when it contains example' do
let(:entity_options) do
{ documentation: { type: 'string', desc: 'Colors', is_array: true, example: %w[green blue] } }
end

it { is_expected.to include(example: %w[green blue]) }
end

context 'when it contains min_items' do
let(:entity_options) { { documentation: { type: 'string', desc: 'Colors', is_array: true, min_items: 1 } } }

Expand Down

0 comments on commit 79f937f

Please sign in to comment.