Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 8 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@ jobs:
run: swift build --build-tests --enable-experimental-prebuilts
- name: Test
run: swift test --skip-build

xcode_15_4:
runs-on: macos-14
env:
DEVELOPER_DIR: /Applications/Xcode_15.4.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
- name: Test
run: swift test --skip-build

xcode_15_2:
runs-on: macos-14
xcode_26:
runs-on: macos-15
env:
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_26.0.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -48,22 +33,22 @@ jobs:
- name: Test
run: swift test --skip-build

linux_swift_5_10:
linux_swift_6_1:
runs-on: ubuntu-latest
container: swift:5.10
container: swift:6.1.2
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
run: swift build --build-tests --enable-experimental-prebuilts
- name: Test
run: swift test --skip-build

linux_swift_5_9:
linux_swift_6_2:
runs-on: ubuntu-latest
container: swift:5.9
container: swiftlang/swift:nightly-6.2-noble
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -73,16 +58,3 @@ jobs:
run: swift build --build-tests
- name: Test
run: swift test --skip-build

linux_swift_6_1:
runs-on: ubuntu-latest
container: swift:6.1.2
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests --enable-experimental-prebuilts
- name: Test
run: swift test --skip-build
56 changes: 53 additions & 3 deletions Macros/Tests/HTTPHandlerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
// SOFTWARE.
//

import Foundation
import FlyingFox
import FlyingFoxMacros
import XCTest
import Testing

final class HTTPHandlerMacroTests: XCTestCase {
struct HTTPHandlerMacroTests {

func testHandler() async throws {
@Test
func handler() async throws {
let handler = MacroHandler()

await AsyncAssertEqual(
Expand All @@ -55,6 +57,24 @@ final class HTTPHandlerMacroTests: XCTestCase {
try await handler.handleRequest(.make(path: "/fish")).jsonDictionaryBody,
["name": "Pickles"]
)

await AsyncAssertEqual(
try await handler.handleRequest(.make(path: "/chips")).jsonDictionaryBody,
["name": "🍟"]
)

await AsyncAssertEqual(
try await handler.handleRequest(.make(path: "/shrimp")).jsonDictionaryBody,
["name": "🦐"]
)

await AsyncAssertEqual(
try await handler.handleRequest(.make(path: "/all")).jsonArrayBody,
[
["name": "Tyger Tyger"],
["name": "Burning Bright"]
]
)
}
}

Expand All @@ -79,9 +99,29 @@ private struct MacroHandler {
Fish(name: "Pickles")
}

@JSONRoute("/chips")
func getFoo() -> MacroHandler.Chips {
MacroHandler.Chips(name: "🍟")
}

@JSONRoute("/shrimp")
func getShrimp() -> some Encodable {
MacroHandler.Chips(name: "🦐")
}

@JSONRoute("/all")
func getAll() -> [Fish] {
[
Fish(name: "Tyger Tyger"),
Fish(name: "Burning Bright")
]
}

struct Fish: Encodable {
var name: String
}

typealias Chips = Fish
}

private extension HTTPResponse {
Expand All @@ -95,4 +135,14 @@ private extension HTTPResponse {
return object as? NSDictionary
}
}

var jsonArrayBody: NSArray? {
get async {
guard let data = try? await bodyData,
let object = try? JSONSerialization.jsonObject(with: data, options: []) else {
return nil
}
return object as? NSArray
}
}
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.1

import PackageDescription
import CompilerPluginSupport
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Sources/FunctionDecl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension FunctionDecl {
parameters: [],
effects: [],
attributes: [],
returnType: .init(syntax.signature.returnClause?.type.as(IdentifierTypeSyntax.self)?.name.text)
returnType: .init(syntax.signature.returnClause?.type.trimmedDescription)
)

decl.attributes = syntax.attributes
Expand All @@ -115,7 +115,7 @@ extension FunctionDecl {
decl.effects.insert(.async)
}

if syntax.signature.effectSpecifiers?.throwsSpecifier != nil {
if syntax.signature.effectSpecifiers?.throwsClause?.throwsSpecifier != nil {
decl.effects.insert(.throws)
}

Expand Down
2 changes: 2 additions & 0 deletions Plugins/Sources/HTTPHandlerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import SwiftSyntaxBuilder
import SwiftSyntaxMacros

public enum HTTPHandlerMacro: MemberMacro {

public static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
conformingTo protocols: [TypeSyntax],
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
let memberList = declaration.memberBlock.members
Expand Down