|
| 1 | +## Upgrading grape-swagger-entity |
| 2 | + |
| 3 | +### Upgrading to >= 0.7.0 |
| 4 | + |
| 5 | +#### Entity Fields Required by Default |
| 6 | + |
| 7 | +This release changes how `grape-swagger-entity` determines if an entity field is |
| 8 | +**required** in the generated Swagger documentation. This is a **breaking change** |
| 9 | +and may require updates to your API documentation and any tools or tests that rely |
| 10 | +on the previous behavior. |
| 11 | + |
| 12 | +**Previous Behavior:** |
| 13 | +Fields were considered optional by default unless explicitly marked as `required: true` |
| 14 | +in their `documentation` options. |
| 15 | + |
| 16 | +**New Behavior:** |
| 17 | +Fields are now considered **required by default** unless one of the following |
| 18 | +conditions is met: |
| 19 | + |
| 20 | +1. **`documentation: { required: false }` is explicitly set:** If you want a field to |
| 21 | + be optional, you must now explicitly set `required: false` within its |
| 22 | + `documentation` hash. |
| 23 | + ```ruby |
| 24 | + expose :field_name, |
| 25 | + documentation: { type: String, required: false, desc: 'An optional field' } |
| 26 | + ``` |
| 27 | +2. **`if` or `unless` options are present:** If a field uses `if` or `unless` for |
| 28 | + conditional exposure, it will be considered optional. |
| 29 | + ```ruby |
| 30 | + expose :conditional_field, |
| 31 | + if: -> { some_condition? }, |
| 32 | + documentation: { type: String, desc: 'Exposed only if condition is met' } |
| 33 | + ``` |
| 34 | +3. **`expose_nil: false` is set:** If `expose_nil` is set to `false`, the field will |
| 35 | + be considered optional. |
| 36 | + ```ruby |
| 37 | + expose :non_nil_field, |
| 38 | + expose_nil: false, |
| 39 | + documentation: { type: String, desc: 'Not exposed if nil' } |
| 40 | + ``` |
| 41 | + |
| 42 | +This change aligns `grape-swagger-entity`'s behavior with `grape-entity`'s rendering |
| 43 | +logic, where fields are always exposed unless `if` or `unless` is provided. |
| 44 | + |
| 45 | +**Action Required:** |
| 46 | +Review your existing Grape entities. If you have fields that were implicitly |
| 47 | +considered optional but did not explicitly set `required: false`, `if`, `unless`, or |
| 48 | +`expose_nil: false`, they will now be marked as required in your Swagger |
| 49 | +documentation.Adjust your `documentation` options accordingly to maintain the desired |
| 50 | +optionality for these fields. |
| 51 | + |
| 52 | +For more details, refer to GitHub Pull Request |
| 53 | +[#81](https://github.com/ruby-grape/grape-swagger-entity/pull/81). |
| 54 | +```` |
0 commit comments