Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ integration suite and tracked example checks on `macos-latest`.
| --- | --- | --- |
| `-client` | generate client code | unset (`false`) |
| `-webrpcHeader` | send the standard `Webrpc` header on client requests | `true` |
| `-schemaHash=false` | omit the schema hash + version constants from generated output | `true` |
12 changes: 12 additions & 0 deletions Tests/Tests/GeneratedTests/GeneratedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import XCTest
@testable import Generated

final class GeneratedTests: XCTestCase {
func testTypeAliasResolvesToUnderlyingType() throws {
// `type UserID: uint64` in test.ridl must render a typealias to the base type.
let id: UserID = 42
XCTAssertEqual(id, UInt64(42))

// Aliases are usable wherever the base type is expected (e.g. request fields).
let request = HelperAPI.GetUser.Request(userId: id)
let body = try HelperAPI.GetUser.encodeRequest(request)
let bodyJSON = try JSONSerialization.jsonObject(with: body) as? [String: Any]
XCTAssertEqual(bodyJSON?["userId"] as? NSNumber, 42)
}

func testHelperRoundTripWorks() throws {
let request = HelperAPI.GetUser.Request(userId: 7)
let body = try HelperAPI.GetUser.encodeRequest(request)
Expand Down
4 changes: 3 additions & 1 deletion Tests/test.ridl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name = Helper
version = v1.0.0
basepath = /rpc

type UserID: uint64

struct Ledger
- amount: bigint
- amounts: []bigint
Expand All @@ -20,7 +22,7 @@ struct Box
- payload: any

service Helper
- GetUser(userId: uint64) => (code: uint32, username: string)
- GetUser(userId: UserID) => (code: uint32, username: string)
- EchoLedger(Ledger) => (Ledger)
- EchoBasket(Basket) => (Basket)
- EchoBox(Box) => (Box)
Expand Down
Loading