grape-oas 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +59 -0
  3. data/README.md +27 -10
  4. data/UPGRADING.md +104 -0
  5. data/grape-oas.gemspec +2 -1
  6. data/lib/grape_oas/api_model/api.rb +6 -1
  7. data/lib/grape_oas/api_model/schema.rb +2 -2
  8. data/lib/grape_oas/api_model_builder.rb +3 -2
  9. data/lib/grape_oas/api_model_builders/concerns/content_type_resolver.rb +30 -1
  10. data/lib/grape_oas/api_model_builders/concerns/oas_utilities.rb +13 -0
  11. data/lib/grape_oas/api_model_builders/concerns/route_validations.rb +26 -0
  12. data/lib/grape_oas/api_model_builders/concerns/type_resolver.rb +7 -8
  13. data/lib/grape_oas/api_model_builders/operation.rb +3 -4
  14. data/lib/grape_oas/api_model_builders/path.rb +33 -6
  15. data/lib/grape_oas/api_model_builders/request.rb +29 -22
  16. data/lib/grape_oas/api_model_builders/request_params.rb +83 -3
  17. data/lib/grape_oas/api_model_builders/request_params_support/nested_params_builder.rb +1 -1
  18. data/lib/grape_oas/api_model_builders/request_params_support/param_location_resolver.rb +7 -2
  19. data/lib/grape_oas/api_model_builders/request_params_support/param_schema_builder.rb +4 -0
  20. data/lib/grape_oas/api_model_builders/request_params_support/schema_enhancer.rb +14 -9
  21. data/lib/grape_oas/api_model_builders/response.rb +28 -4
  22. data/lib/grape_oas/constants.rb +22 -1
  23. data/lib/grape_oas/documentation_extension.rb +7 -9
  24. data/lib/grape_oas/exporter/concerns/schema_indexer.rb +14 -3
  25. data/lib/grape_oas/exporter/oas2/operation.rb +4 -2
  26. data/lib/grape_oas/exporter/oas2/parameter.rb +74 -13
  27. data/lib/grape_oas/exporter/oas2/paths.rb +1 -0
  28. data/lib/grape_oas/exporter/oas2/response.rb +6 -4
  29. data/lib/grape_oas/exporter/oas2/schema.rb +85 -38
  30. data/lib/grape_oas/exporter/oas2_schema.rb +7 -5
  31. data/lib/grape_oas/exporter/oas3/operation.rb +5 -3
  32. data/lib/grape_oas/exporter/oas3/parameter.rb +8 -3
  33. data/lib/grape_oas/exporter/oas3/paths.rb +1 -0
  34. data/lib/grape_oas/exporter/oas3/request_body.rb +5 -8
  35. data/lib/grape_oas/exporter/oas3/response.rb +6 -9
  36. data/lib/grape_oas/exporter/oas3/schema.rb +273 -117
  37. data/lib/grape_oas/exporter/oas31/schema.rb +12 -2
  38. data/lib/grape_oas/exporter/oas31_schema.rb +1 -1
  39. data/lib/grape_oas/exporter/oas3_schema.rb +3 -2
  40. data/lib/grape_oas/introspectors/entity_introspector.rb +7 -2
  41. data/lib/grape_oas/introspectors/entity_introspector_support/exposure_processor.rb +55 -20
  42. data/lib/grape_oas/introspectors/entity_introspector_support/inheritance_builder.rb +1 -1
  43. data/lib/grape_oas/introspectors/entity_introspector_support/property_extractor.rb +2 -8
  44. data/lib/grape_oas/introspectors/entity_introspector_support/type_schema_resolver.rb +4 -20
  45. data/lib/grape_oas/introspectors/entity_introspector_support.rb +24 -0
  46. data/lib/grape_oas/range_utils.rb +25 -2
  47. data/lib/grape_oas/type_resolvers/array_resolver.rb +54 -22
  48. data/lib/grape_oas/type_resolvers/base.rb +2 -2
  49. data/lib/grape_oas/type_resolvers/default_resolver.rb +23 -0
  50. data/lib/grape_oas/type_resolvers/dry_type_resolver.rb +1 -1
  51. data/lib/grape_oas/type_resolvers/primitive_resolver.rb +29 -46
  52. data/lib/grape_oas/type_resolvers/registry.rb +31 -15
  53. data/lib/grape_oas/version.rb +1 -1
  54. data/lib/grape_oas.rb +37 -7
  55. metadata +5 -4
  56. data/CONTRIBUTING.md +0 -87
  57. data/RELEASING.md +0 -109
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeOAS
4
- VERSION = "1.3.0"
4
+ VERSION = "1.5.0"
5
5
  end
data/lib/grape_oas.rb CHANGED
@@ -46,6 +46,29 @@ module GrapeOAS
46
46
  # Used by the default logger and the test capture helper.
47
47
  LOG_FORMATTER = proc { |_severity, _datetime, _progname, msg| "[grape-oas] #{msg}\n" }
48
48
 
49
+ # Default mapping from a schema's canonical class name to its OAS component/definition ref name.
50
+ # Replaces Ruby's `::` module separator with `_` so ref names are valid across tooling that rejects colons.
51
+ DEFAULT_SCHEMA_REF_NAME = ->(name) { name.gsub("::", "_") }
52
+
53
+ # Configurable callable that derives the OAS component/definition ref name
54
+ # from a schema's canonical class name. Applied to every `$ref` target and
55
+ # every component/definition key so custom mangling stays consistent.
56
+ #
57
+ # @return [#call(String) -> String]
58
+ def schema_ref_name
59
+ @schema_ref_name ||= DEFAULT_SCHEMA_REF_NAME
60
+ end
61
+
62
+ # @param value [#call, nil] a callable receiving the canonical name,
63
+ # or nil to reset to the default mangler
64
+ def schema_ref_name=(value)
65
+ raise ArgumentError, "schema_ref_name must respond to :call (got #{value.class})" if value && !value.respond_to?(:call)
66
+
67
+ @schema_ref_name = value
68
+ end
69
+
70
+ module_function :schema_ref_name, :schema_ref_name=
71
+
49
72
  # Configurable logger for schema generation warnings.
50
73
  # Defaults to Logger on $stderr. Set to Rails.logger or Logger.new(File::NULL).
51
74
  #
@@ -144,11 +167,11 @@ module GrapeOAS
144
167
  @type_resolvers ||= begin
145
168
  registry = TypeResolvers::Registry.new
146
169
  # Register built-in resolvers in order of precedence
147
- # ArrayResolver handles "[Type]" patterns first
170
+ # ArrayResolver handles "[Type]" / "Array[Type, ...]" patterns first
148
171
  registry.register(TypeResolvers::ArrayResolver)
149
172
  # DryTypeResolver handles Dry::Types (standalone, not arrays)
150
173
  registry.register(TypeResolvers::DryTypeResolver)
151
- # PrimitiveResolver is the fallback for basic types
174
+ # PrimitiveResolver handles known Ruby primitives
152
175
  registry.register(TypeResolvers::PrimitiveResolver)
153
176
  registry
154
177
  end
@@ -192,11 +215,18 @@ module GrapeOAS
192
215
  # # Only includes paths like /users, /users/{id}, etc.
193
216
  #
194
217
  def generate(app:, schema_type: :oas3, **options)
195
- if options[:nullable_strategy].nil? && options.key?(:nullable_keyword) && %i[oas3 oas30].include?(schema_type)
196
- options[:nullable_strategy] = if options[:nullable_keyword] == false
197
- Constants::NullableStrategy::TYPE_ARRAY
198
- else
199
- Constants::NullableStrategy::KEYWORD
218
+ if options[:nullable_strategy].nil? && options.key?(:nullable_keyword)
219
+ options[:nullable_strategy] = case schema_type
220
+ when :oas2
221
+ Constants::NullableStrategy::OAS2_DEFAULT
222
+ when :oas3, :oas30
223
+ if options[:nullable_keyword] == false
224
+ Constants::NullableStrategy::TYPE_ARRAY
225
+ else
226
+ Constants::NullableStrategy::OAS3_DEFAULT
227
+ end
228
+ when :oas31
229
+ Constants::NullableStrategy::OAS31_DEFAULT
200
230
  end
201
231
  end
202
232
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-oas
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Subbota
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-27 00:00:00.000000000 Z
11
+ date: 2026-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -47,10 +47,9 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - CHANGELOG.md
50
- - CONTRIBUTING.md
51
50
  - LICENSE.txt
52
51
  - README.md
53
- - RELEASING.md
52
+ - UPGRADING.md
54
53
  - grape-oas.gemspec
55
54
  - lib/grape-oas.rb
56
55
  - lib/grape_oas.rb
@@ -66,6 +65,7 @@ files:
66
65
  - lib/grape_oas/api_model_builder.rb
67
66
  - lib/grape_oas/api_model_builders/concerns/content_type_resolver.rb
68
67
  - lib/grape_oas/api_model_builders/concerns/oas_utilities.rb
68
+ - lib/grape_oas/api_model_builders/concerns/route_validations.rb
69
69
  - lib/grape_oas/api_model_builders/concerns/type_resolver.rb
70
70
  - lib/grape_oas/api_model_builders/operation.rb
71
71
  - lib/grape_oas/api_model_builders/path.rb
@@ -133,6 +133,7 @@ files:
133
133
  - lib/grape_oas/schema_constraints.rb
134
134
  - lib/grape_oas/type_resolvers/array_resolver.rb
135
135
  - lib/grape_oas/type_resolvers/base.rb
136
+ - lib/grape_oas/type_resolvers/default_resolver.rb
136
137
  - lib/grape_oas/type_resolvers/dry_type_resolver.rb
137
138
  - lib/grape_oas/type_resolvers/primitive_resolver.rb
138
139
  - lib/grape_oas/type_resolvers/registry.rb
data/CONTRIBUTING.md DELETED
@@ -1,87 +0,0 @@
1
- # Contributing to Grape::OAS
2
-
3
- We welcome contributions to Grape::OAS! This document provides guidelines for contributing.
4
-
5
- ## Getting Started
6
-
7
- 1. **Fork the repository** on GitHub
8
-
9
- 2. **Clone your fork**:
10
- ```bash
11
- git clone https://github.com/YOUR_USERNAME/grape-oas.git
12
- cd grape-oas
13
- ```
14
-
15
- 3. **Set up upstream remote**:
16
- ```bash
17
- git remote add upstream https://github.com/numbata/grape-oas.git
18
- ```
19
-
20
- 4. **Install dependencies**:
21
- ```bash
22
- bin/setup
23
- ```
24
-
25
- ## Development Workflow
26
-
27
- 1. **Create a topic branch**:
28
- ```bash
29
- git checkout -b my-feature
30
- ```
31
-
32
- 2. **Write tests** for your changes in `test/`
33
-
34
- 3. **Implement your feature or fix**
35
-
36
- 4. **Run the test suite**:
37
- ```bash
38
- bundle exec rake test
39
- ```
40
-
41
- 5. **Run RuboCop**:
42
- ```bash
43
- bundle exec rubocop
44
- ```
45
-
46
- 6. **Run all checks**:
47
- ```bash
48
- bundle exec rake
49
- ```
50
-
51
- ## Submitting Changes
52
-
53
- 1. **Update CHANGELOG.md** under "Unreleased" section
54
-
55
- 2. **Write clear commit messages** describing what and why
56
-
57
- 3. **Push to your fork**:
58
- ```bash
59
- git push origin my-feature
60
- ```
61
-
62
- 4. **Open a Pull Request** against the `main` branch
63
-
64
- ## Pull Request Guidelines
65
-
66
- - Keep PRs focused on a single change
67
- - Include tests for new functionality
68
- - Update documentation if needed
69
- - Ensure CI passes before requesting review
70
-
71
- ## Code Style
72
-
73
- - Follow existing code conventions
74
- - RuboCop enforces style - run it before committing
75
- - Use descriptive variable and method names
76
-
77
- ## Testing
78
-
79
- - Write tests for all new functionality
80
- - Ensure existing tests pass
81
- - Aim for good coverage of edge cases
82
-
83
- ## Questions?
84
-
85
- Open an issue for questions or discussions about potential changes.
86
-
87
- Thank you for contributing!
data/RELEASING.md DELETED
@@ -1,109 +0,0 @@
1
- # Releasing Grape::OAS
2
-
3
- This document describes the release process for the grape-oas gem.
4
-
5
- ## Pre-Release Checks
6
-
7
- Before releasing, ensure:
8
-
9
- 1. All tests pass locally and in CI:
10
- ```bash
11
- bundle install
12
- bundle exec rake
13
- ```
14
-
15
- 2. The CHANGELOG.md is up to date with all changes since the last release.
16
-
17
- 3. The version number in `lib/grape_oas/version.rb` is correct.
18
-
19
- ## Release Steps
20
-
21
- ### Automated Release Process
22
-
23
- 1. **Update the version** in `lib/grape_oas/version.rb` to the release version
24
-
25
- 2. **Prepare the CHANGELOG**:
26
- ```bash
27
- bundle exec rake release:prerelease
28
- ```
29
- This task will:
30
- - Replace "Unreleased" with the version number and today's date
31
- - Remove any "Your contribution here" placeholder lines
32
- - Commit with message "Preparing for release vX.X.X"
33
-
34
- **Note**: The task is idempotent - safe to run multiple times.
35
-
36
- 3. **Push and create the release**:
37
- ```bash
38
- git push origin main
39
- bundle exec rake release
40
- ```
41
- This will:
42
- - Build the gem
43
- - Create a git tag
44
- - Push the tag to GitHub
45
- - Push the gem to RubyGems.org
46
-
47
- <details>
48
- <summary>Manual Release Steps (if needed)</summary>
49
-
50
- 1. **Update CHANGELOG.md**
51
- - Change "Unreleased" to the version number and date
52
- - Remove any "Your contribution here" placeholder lines
53
-
54
- 2. **Commit the release preparation**:
55
- ```bash
56
- git add CHANGELOG.md
57
- git commit -m "Preparing for release v0.x.x"
58
- git push origin main
59
- ```
60
-
61
- 3. **Create and push the release**:
62
- ```bash
63
- bundle exec rake release
64
- ```
65
- This will:
66
- - Build the gem
67
- - Create a git tag
68
- - Push the tag to GitHub
69
- - Push the gem to RubyGems.org
70
- </details>
71
-
72
- ## Post-Release
73
-
74
- You can automate the post-release preparation with:
75
-
76
- ```bash
77
- bundle exec rake release:postrelease
78
- git push origin main
79
- ```
80
-
81
- This task will:
82
- - Bump the patch version in `lib/grape_oas/version.rb`
83
- - Ensure CHANGELOG.md has an "Unreleased" section with "* Your contribution here" placeholder
84
- - Commit the changes with message "Prepare for next development iteration"
85
-
86
- **Note**: The task is idempotent - safe to run multiple times without duplicating work.
87
-
88
- <details>
89
- <summary>Manual Post-Release Steps (if needed)</summary>
90
-
91
- 1. **Prepare for next development cycle**:
92
- - Add "Unreleased" section to CHANGELOG.md with "* Your contribution here" placeholder
93
- - Bump version in `lib/grape_oas/version.rb`
94
-
95
- 2. **Commit post-release changes**:
96
- ```bash
97
- git add CHANGELOG.md lib/grape_oas/version.rb
98
- git commit -m "Prepare for next development iteration"
99
- git push origin main
100
- ```
101
- </details>
102
-
103
- ## Versioning
104
-
105
- This project follows [Semantic Versioning](https://semver.org/):
106
-
107
- - **MAJOR**: Incompatible API changes
108
- - **MINOR**: New functionality in a backward compatible manner
109
- - **PATCH**: Backward compatible bug fixes