-
Notifications
You must be signed in to change notification settings - Fork 478
Ruby 3.4 and refactor swagger documentation modules #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
moskvin
wants to merge
13
commits into
ruby-grape:master
Choose a base branch
from
moskvin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
443245f
Update TargetRubyVersion to 3.4 in .rubocop.yml
moskvin dea80a8
Rename Grape::Entity classes for clarity and update documentation ref…
moskvin ca5fdb2
[cop] Add SwaggerRouting and SwaggerDocumentationAdder modules
moskvin 30b65e2
Update CHANGELOG for Ruby 3.4 and refactor of swagger documentation m…
moskvin 93c4886
Enhance route parameter handling with fallback support and add unit t…
moskvin 3ea5f11
Add fallback handling for path param extraction errors in route specs
moskvin bc01086
Add deprecation warning for additionalProperties option in parse_para…
moskvin 7b7a033
Enhance path parameter extraction with fallback support and add unit …
moskvin 5913ba7
Add handling for ignored fallback path parameters and enhance route s…
moskvin c46756f
:ambulance: Remove weird fallback path parameter handling and clean u…
moskvin 12822ca
Remove outdated Ruby and Grape version combinations from CI matrix
moskvin 85509fc
Update CI matrix with new Ruby and Grape version combinations
moskvin 983db7f
:sparkles: Add tests for fulfilling path parameters with symbol and s…
moskvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,8 @@ def fulfill_params(path_params) | |
| next if param.is_a?(String) && accum.key?(key) | ||
|
|
||
| defined_options = definition.is_a?(Hash) ? definition : {} | ||
| value = (path_params[param] || {}).merge(defined_options) | ||
| path_options = path_params[param] || path_params[param.to_s] || path_params[param.to_sym] || {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about: alt = param.is_a?(Symbol) ? param.to_s : param.to_sym
path_options = path_params[param] || path_params[alt] || {}or normalize keys once in |
||
| value = path_options.merge(defined_options) | ||
| accum[key] = value.empty? ? DEFAULT_PARAM_TYPE : value | ||
| end | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module SwaggerDocumentationAdder | ||
| attr_accessor :combined_namespaces, :combined_routes, :combined_namespace_routes | ||
|
|
||
| include SwaggerRouting | ||
|
|
||
| def add_swagger_documentation(options = {}) | ||
| documentation_class = create_documentation_class | ||
|
|
||
| version_for(options) | ||
| options = { target_class: self }.merge(options) | ||
| @target_class = options[:target_class] | ||
| auth_wrapper = options[:endpoint_auth_wrapper] || Class.new | ||
|
|
||
| use auth_wrapper if auth_wrapper.method_defined?(:before) && !middleware.flatten.include?(auth_wrapper) | ||
|
|
||
| documentation_class.setup(options) | ||
| mount(documentation_class) | ||
|
|
||
| combined_routes = combine_routes(@target_class, documentation_class) | ||
| combined_namespaces = combine_namespaces(@target_class) | ||
| combined_namespace_routes = combine_namespace_routes(combined_namespaces, combined_routes) | ||
| exclusive_route_keys = combined_routes.keys - combined_namespaces.keys | ||
| @target_class.combined_namespace_routes = combined_namespace_routes.merge( | ||
| combined_routes.slice(*exclusive_route_keys) | ||
| ) | ||
| @target_class.combined_routes = combined_routes | ||
| @target_class.combined_namespaces = combined_namespaces | ||
|
|
||
| documentation_class | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def version_for(options) | ||
| options[:version] = version if version | ||
| end | ||
|
|
||
| def combine_namespaces(app) | ||
| combined_namespaces = {} | ||
| endpoints = app.endpoints.clone | ||
|
|
||
| while endpoints.any? | ||
| endpoint = endpoints.shift | ||
|
|
||
| endpoints.push(*endpoint.options[:app].endpoints) if endpoint.options[:app] | ||
| namespace_stackable = endpoint.inheritable_setting.namespace_stackable | ||
| ns = (namespace_stackable[:namespace] || []).last | ||
| next unless ns | ||
|
|
||
| # use the full namespace here (not the latest level only) | ||
| # and strip leading slash | ||
| mount_path = (namespace_stackable[:mount_path] || []).join('/') | ||
| full_namespace = (mount_path + endpoint.namespace).sub(/\/{2,}/, '/').sub(/^\//, '') | ||
| combined_namespaces[full_namespace] = ns | ||
| end | ||
|
|
||
| combined_namespaces | ||
| end | ||
|
|
||
| def create_documentation_class | ||
| Class.new(GrapeInstance) do | ||
| extend GrapeSwagger::DocMethods | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gemspec declares grape >= 1.7, but this PR replaces all matrix entries for Grape 1.8.0–2.2.0 with 2.4.0+. As the minimum requirement is being raised to 2.4.0, could you update the gemspec and README?