Refactor Grape framework code for improved readability and consistency

This commit is contained in:
Chad Bentz
2025-09-12 19:23:15 -04:00
parent d295acc3c3
commit 738ab6fba7
3 changed files with 10 additions and 10 deletions

View File

@@ -115,7 +115,7 @@ class GrapeEndpoint extends DataFlow::CallNode {
* Grape parameters available via the `params` method within an endpoint.
*/
class GrapeParamsSource extends Http::Server::RequestInputAccess::Range {
GrapeParamsSource() {
GrapeParamsSource() {
this.asExpr().getExpr() instanceof GrapeParamsCall
}

View File

@@ -5,7 +5,7 @@ import codeql.ruby.AST
query predicate grapeAPIClasses(GrapeAPIClass api) { any() }
query predicate grapeEndpoints(GrapeAPIClass api, GrapeEndpoint endpoint, string method, string path) {
query predicate grapeEndpoints(GrapeAPIClass api, GrapeEndpoint endpoint, string method, string path) {
endpoint = api.getAnEndpoint() and
method = endpoint.getHttpMethod() and
path = endpoint.getPath()

View File

@@ -9,7 +9,7 @@ class MyAPI < Grape::API
user_agent = headers['User-Agent']
"Hello #{name}!"
end
desc 'Post endpoint with params'
params do
requires :message, type: String
@@ -18,36 +18,36 @@ class MyAPI < Grape::API
msg = params[:message]
{ status: 'received', message: msg }
end
desc 'Put endpoint accessing request'
put '/update/:id' do
id = params[:id]
body = request.body.read
{ id: id, body: body }
end
desc 'Delete endpoint'
desc 'Delete endpoint'
delete '/items/:id' do
params[:id]
end
desc 'Patch endpoint'
patch '/items/:id' do
params[:id]
end
desc 'Head endpoint'
head '/status' do
# Just return status
end
desc 'Options endpoint'
options '/info' do
headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
end
end
class AdminAPI < Grape::API
class AdminAPI < Grape::API
get '/admin' do
params[:token]
end