Skip to content

Commit d61271f

Browse files
committed
Add type definitions for Grape and Sinatra route serializers
1 parent 9a30b09 commit d61271f

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Datadog
2+
module AppSec
3+
module APISecurity
4+
module EndpointCollection
5+
interface _GrapeRoute
6+
def request_method: () -> String
7+
def pattern: () -> _GrapeRoutePattern
8+
end
9+
10+
interface _GrapeRoutePattern
11+
def origin: () -> String
12+
end
13+
14+
class GrapeRoutesSerializer
15+
@routes: Array[_GrapeRoute]
16+
17+
@path_prefix: String
18+
19+
def initialize: (Array[_GrapeRoute] routes, ?path_prefix: String) -> void
20+
21+
def to_enum: () -> Enumerator[Core::Telemetry::Event::AppEndpointsLoaded::endpoint]
22+
23+
def serialize_route: (_GrapeRoute route) -> Core::Telemetry::Event::AppEndpointsLoaded::endpoint
24+
end
25+
end
26+
end
27+
end
28+
end

sig/datadog/appsec/api_security/endpoint_collection/rails_routes_serializer.rbs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,47 @@ module Datadog
22
module AppSec
33
module APISecurity
44
module EndpointCollection
5-
interface _Route
5+
interface _RailsRoute
66
def dispatcher?: () -> bool
77
def verb: () -> String
8-
def path: () -> _RoutePath
8+
def path: () -> _RailsRoutePath
9+
def app: () -> _RailsRouteApp
910
end
1011

11-
interface _RoutePath
12-
def spec: () -> _RouteSpec
12+
interface _RailsRoutePath
13+
def spec: () -> _RailsRouteSpec
1314
end
1415

15-
interface _RouteSpec
16+
interface _RailsRouteSpec
1617
def to_s: () -> String
1718
end
1819

20+
interface _RailsRouteApp
21+
def rack_app: () -> _RackApp
22+
end
23+
24+
interface _RackApp
25+
def is_a?: (Class) -> bool
26+
27+
def routes: () -> untyped
28+
end
29+
1930
class RailsRoutesSerializer
2031
FORMAT_SUFFIX: String
2132

22-
@routes: Array[_Route]
33+
@routes: Array[_RailsRoute]
2334

24-
def initialize: (Array[_Route] routes) -> void
35+
def initialize: (Array[_RailsRoute] routes) -> void
2536

2637
def to_enum: () -> Enumerator[Core::Telemetry::Event::AppEndpointsLoaded::endpoint]
2738

28-
def serialize_route: (_Route route) -> Core::Telemetry::Event::AppEndpointsLoaded::endpoint
39+
def serialize_route: (_RailsRoute route) -> Core::Telemetry::Event::AppEndpointsLoaded::endpoint
40+
41+
private
42+
43+
def grape_app?: (_RackApp rack_app) -> bool
44+
45+
def sinatra_app?: (_RackApp rack_app) -> bool
2946
end
3047
end
3148
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Datadog
2+
module AppSec
3+
module APISecurity
4+
module EndpointCollection
5+
interface _SinatraRoute
6+
def safe_string: () -> String
7+
end
8+
9+
class SinatraRoutesSerializer
10+
@routes: Hash[String, Array[_SinatraRoute]]
11+
12+
@path_prefix: String
13+
14+
def initialize: (Hash[String, Array[_SinatraRoute]] routes, ?path_prefix: String) -> void
15+
16+
def to_enum: () -> Enumerator[Core::Telemetry::Event::AppEndpointsLoaded::endpoint]
17+
18+
def serialize_route: (_SinatraRoute route, String method) -> Core::Telemetry::Event::AppEndpointsLoaded::endpoint
19+
end
20+
end
21+
end
22+
end
23+
end

vendor/rbs/grape/0/grape.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Grape
2+
class API
3+
end
4+
end

vendor/rbs/sinatra/0/sinatra.rbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module Sinatra
22
class Response
33
def initialize: (::Array[::String] body, ::Integer status, ::Hash[::String, ::String] headers) -> void
44
end
5+
6+
class Base
7+
end
58
end

0 commit comments

Comments
 (0)