Skip to content

Commit 57d2cba

Browse files
authored
Merge pull request #1 from connor-ricks/feature/route-modifiers
✨ Add support for route modifiers.
2 parents 0976dce + 7aa0eb5 commit 57d2cba

31 files changed

+452
-112
lines changed

.swiftlint.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# SwiftLint configuration file for the Storybook repository.
2+
# Run `swiftlint --fix` at the root of the repository to format all code.
3+
4+
# MARK: - Settings
5+
6+
#included:
7+
# - *.swift
8+
excluded:
9+
- "**/.build"
10+
11+
# If true, SwiftLint will not fail if no lintable files are found.
12+
allow_zero_lintable_files: false
13+
14+
# If true, SwiftLint will treat all warnings as errors.
15+
strict: true
16+
17+
# If true, SwiftLint will check for updates after linting or analyzing.
18+
check_for_updates: true
19+
20+
# reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging, summary)
21+
reporter: "xcode"
22+
23+
# MARK: - Rules
24+
25+
disabled_rules:
26+
- class_delegate_protocol
27+
- cyclomatic_complexity
28+
- discouraged_direct_init
29+
- duplicate_enum_cases
30+
- function_parameter_count
31+
- inclusive_language
32+
- large_tuple
33+
- line_length
34+
- multiple_closures_with_trailing_closure
35+
- nesting
36+
- non_optional_string_data_conversion
37+
- notification_center_detachment
38+
- shorthand_operator
39+
- todo
40+
- type_body_length
41+
- type_name
42+
- void_function_in_ternary
43+
44+
opt_in_rules:
45+
- closure_end_indentation
46+
- closure_spacing
47+
- collection_alignment
48+
- comma_inheritance
49+
- contains_over_filter_count
50+
- contains_over_filter_is_empty
51+
- contains_over_first_not_nil
52+
- contains_over_range_nil_comparison
53+
- convenience_type
54+
- discarded_notification_center_observer
55+
- discouraged_none_name
56+
- discouraged_object_literal
57+
- discouraged_optional_boolean
58+
- discouraged_optional_collection
59+
- empty_collection_literal
60+
- empty_count
61+
- empty_string
62+
- explicit_init
63+
- fatal_error_message
64+
- file_name_no_space
65+
- first_where
66+
- identical_operands
67+
- implicit_return
68+
- indentation_width
69+
- joined_default_parameter
70+
- last_where
71+
- legacy_multiple
72+
- literal_expression_end_indentation
73+
- lower_acl_than_parent
74+
- modifier_order
75+
- multiline_arguments
76+
- multiline_arguments_brackets
77+
- multiline_literal_brackets
78+
- multiline_parameters
79+
- multiline_parameters_brackets
80+
- number_separator
81+
- operator_usage_whitespace
82+
- optional_enum_case_matching
83+
- overridden_super_call
84+
- override_in_extension
85+
- prefer_self_type_over_type_of_self
86+
- prefer_zero_over_explicit_init
87+
- private_swiftui_state
88+
- raw_value_for_camel_cased_codable_enum
89+
- redundant_nil_coalescing
90+
- return_value_from_void_function
91+
- shorthand_optional_binding
92+
- sorted_enum_cases
93+
- sorted_first_last
94+
- sorted_imports
95+
- toggle_bool
96+
- unhandled_throwing_task
97+
- unneeded_parentheses_in_closure_argument
98+
- unowned_variable_capture
99+
- vertical_parameter_alignment_on_call
100+
- vertical_whitespace_closing_braces
101+
- yoda_condition
102+
103+
analyzer_rules:
104+
- unused_declaration
105+
- unused_import
106+
107+
# MARK: - Config
108+
109+
file_length:
110+
warning: 750
111+
error: 1500
112+
ignore_comment_only_lines: true
113+
force_cast:
114+
severity: warning
115+
force_try:
116+
severity: warning
117+
function_body_length:
118+
warning: 100
119+
error: 200
120+
identifier_name:
121+
min_length: 0
122+
opening_brace:
123+
- ignore_multiline_statement_conditions
124+
trailing_comma:
125+
mandatory_comma: true
126+
unused_declaration:
127+
severity: warning

Package.resolved

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,46 @@ import PackageDescription
2727
let package = Package(
2828
name: "swift-vapor-route-builder",
2929
platforms: [
30-
.macOS(.v15)
30+
.macOS(.v10_15)
3131
],
3232
products: [
3333
.library(name: "VaporRouteBuilder", targets: ["VaporRouteBuilder"])
3434
],
3535
dependencies: [
36-
.package(url: "https://github.com/vapor/vapor.git", from: "4.105.2")
36+
.package(url: "https://github.com/vapor/vapor.git", from: "4.105.2"),
37+
// TODO: <Connor> This can probably be removed once Swift 6 is officially released.
38+
.package(url: "https://github.com/apple/swift-testing", from: "0.12.0"),
3739
],
3840
targets: [
3941
.target(name: "VaporRouteBuilder", dependencies: [.product(name: "Vapor", package: "vapor")]),
4042
.testTarget(
4143
name: "VaporRouteBuilderTests",
4244
dependencies: [
4345
"VaporRouteBuilder",
44-
.product(name: "XCTVapor", package: "vapor")
46+
.product(name: "XCTVapor", package: "vapor"),
4547
]
46-
)
48+
),
4749
]
4850
)
51+
52+
#if os(macOS) // Only add SwiftLint on supported platforms.
53+
package.dependencies.append(contentsOf: [
54+
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.56.2"),
55+
])
56+
#endif
57+
58+
for target in package.targets where target.type != .system {
59+
#if os(macOS) // Only add SwiftLint on supported platforms.
60+
target.plugins = target.plugins ?? []
61+
target.plugins?.append(contentsOf: [
62+
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
63+
])
64+
#endif
65+
66+
if case .test = target.type {
67+
target.dependencies.append(contentsOf: [
68+
// TODO: <Connor> This can probably be removed once Swift 6 is officially released.
69+
.product(name: "Testing", package: "swift-testing"),
70+
])
71+
}
72+
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Build Vapor routes using a declarative syntax langauge similar to how you would
66

77
- [Confirmed] Add README usage docs.
88
- [Confirmed] Implement Websocket support
9-
- [Confirmed] Implement RouteModifier support
109
- [Maybe] Implement EnvironmentObject style support.
1110
- [Maybe] Implement Service support
1211

Sources/VaporRouteBuilder/Route+Convenience.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ extension Route {
6161
_ = try await request.eventLoop.flatSubmit {
6262
request.body.collect(max: max?.value ?? request.application.routes.defaultMaxBodySize.value)
6363
}.get()
64-
6564
}
6665
return try await closure(request).encodeResponse(for: request)
6766
}

Sources/VaporRouteBuilder/RouteBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public enum RouteBuilder {
5252
public static func buildEither<TrueContent: RouteComponent, FalseContent: RouteComponent>(
5353
first content: TrueContent
5454
) -> Conditional<TrueContent, FalseContent> {
55-
return Conditional.first(content)
55+
Conditional.first(content)
5656
}
5757

5858
@inlinable
5959
static func buildEither<TrueContent: RouteComponent, FalseContent: RouteComponent>(
6060
second content: FalseContent
6161
) -> Conditional<TrueContent, FalseContent> {
62-
return Conditional.second(content)
62+
Conditional.second(content)
6363
}
6464

6565
// MARK: buildOptional

Sources/VaporRouteBuilder/RouteComponents/Groups/Group+Middleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import Vapor
2424

2525
extension Group {
26-
/// Creates a group of content under a path.
26+
/// Groups content under the provided middleware.
2727
///
2828
/// See ``Group.init(middleware:content:)`` for more info.
2929
public struct Middleware<Middlewares: Collection<any Vapor.Middleware>>: RouteComponent {

Sources/VaporRouteBuilder/RouteComponents/Groups/Group+Path.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import Vapor
2424

2525
extension Group {
26-
/// Creates a group of content under a path.
26+
/// Groups content under a provided path.
2727
///
2828
/// See ``Group.init(path:content:)`` for more info.
2929
public struct Path<Path: Collection<PathComponent>>: RouteComponent {

Sources/VaporRouteBuilder/RouteComponents/Groups/Group.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ public struct Group<Content: RouteComponent>: RouteComponent {
205205
public func boot(routes: any RoutesBuilder) throws {
206206
try content.boot(routes: routes)
207207
}
208-
209208
}
210209

211210
// MARK: - RouteComponents + Group

Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/DELETE.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct DELETE: RouteComponent {
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
4646
public init<Path: Collection, Response: ResponseEncodable>(
47-
path: Path,
47+
_ path: Path,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
5050
) where Path.Element == PathComponent {
@@ -59,7 +59,7 @@ public struct DELETE: RouteComponent {
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
6161
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
path: Path,
62+
_ path: Path,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
6565
) where Path.Element == PathComponent {
@@ -74,7 +74,7 @@ public struct DELETE: RouteComponent {
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
7676
public init<Response: ResponseEncodable>(
77-
path: PathComponent...,
77+
_ path: PathComponent...,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
8080
) {
@@ -89,7 +89,7 @@ public struct DELETE: RouteComponent {
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
9191
public init<Response: AsyncResponseEncodable>(
92-
path: PathComponent...,
92+
_ path: PathComponent...,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
9595
) {

0 commit comments

Comments
 (0)