Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3a91aac
WIP, schemas compile
jbelkins Dec 24, 2024
c754545
Protocol tests compile
jbelkins Dec 24, 2024
1063698
Full SDK compiled
jbelkins Dec 26, 2024
e2df562
All but 9 protocol tests pass
jbelkins Dec 27, 2024
b5708e9
Schema simplified, some tests failing
jbelkins Dec 27, 2024
72efe11
9 protocol test fails
jbelkins Jan 4, 2025
e8e3fd2
Merge branch 'main' into jbe/sbs
jbelkins Jan 4, 2025
37f013c
All protocol tests pass
jbelkins Jan 5, 2025
2e9ef4e
Remove Unit associated type from union members, provide prelude schemas
jbelkins Jan 5, 2025
1dbd2a2
Replace DeserializableShape with factory block
jbelkins Jan 5, 2025
704fae4
Codegen cleanup
jbelkins Jan 6, 2025
13bf7f7
Fix codegen tests & lint
jbelkins Jan 6, 2025
b29d75b
Merge branch 'main' into jbe/sbs
jbelkins Jan 6, 2025
aabbad7
Eliminate enum & int enum member schemas
jbelkins Jan 6, 2025
086b99a
Fix ktlint
jbelkins Jan 6, 2025
bd9bfdf
Clean up respectsJSONName propagation
jbelkins Jan 7, 2025
8ba8b28
Merge branch 'main' into jbe/sbs
jbelkins Jan 7, 2025
a833881
Revert SwiftWriter changes
jbelkins Jan 8, 2025
5721d02
Remove default value from endpoint generator
jbelkins Jan 8, 2025
4636512
Merge branch 'main' into jbe/sbs
jbelkins Jan 8, 2025
9c4d161
Merge branch 'main' into jbe/sbs
jbelkins Jan 9, 2025
34de074
Merge branch 'main' into jbe/sbs
jbelkins Jan 14, 2025
9d4cb51
Merge remote-tracking branch 'origin/main' into jbe/sbs
jbelkins Jan 16, 2025
eee76b0
Merge remote-tracking branch 'origin/main' into jbe/sbs
jbelkins Jan 21, 2025
c4dd341
Merge branch 'main' into jbe/sbs
jbelkins Jan 29, 2025
93fe720
Merge branch 'main' into jbe/sbs
jbelkins Feb 5, 2025
c68c761
Merge branch 'main' into jbe/sbs
jbelkins Feb 6, 2025
b65a726
Merge branch 'main' into jbe/sbs
jbelkins Jul 4, 2025
a05990a
Fix build, run ktlint
jbelkins Jul 4, 2025
69469d2
Merge branch 'main' into jbe/sbs
jbelkins Aug 29, 2025
7d00770
Merge branch 'main' into jbe/sbs
jbelkins Sep 16, 2025
f0ed0e2
Fix NullDocument protocol tests
jbelkins Sep 16, 2025
4da3b59
fix ktlint
jbelkins Sep 16, 2025
7d694a0
Merge branch 'main' into jbe/sbs
jbelkins Sep 17, 2025
e6e0d27
Merge remote-tracking branch 'origin/main' into jbe/sbs
jbelkins Sep 17, 2025
1048017
Convert traits to free-form
jbelkins Sep 18, 2025
207921b
Cleanup
jbelkins Sep 18, 2025
ed8312b
Moved Node to Smithy module
jbelkins Sep 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public struct BigDecimalDocument: SmithyDocument {
return int
}

public func asLong() throws -> Int64 {
guard let long = Int64(exactly: value) else {
public func asLong() throws -> Int {
guard let long = Int(exactly: value) else {
throw DocumentError.numberOverflow("BigDecimal \(value) overflows long")
}
return long
Expand Down
27 changes: 27 additions & 0 deletions Sources/Smithy/Document/Node+Document.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

@_spi(SmithyNodeImpl)
extension Node {

public func toDocument() -> (any SmithyDocument)? {
switch self {
case .object(let value):
return StringMapDocument(value: value.compactMapValues { $0.toDocument() })
case .list(let value):
return ListDocument(value: value.compactMap { $0.toDocument() })
case .string(let value):
return StringDocument(value: value)
case .number(let value):
return DoubleDocument(value: value)
case .boolean(let value):
return BooleanDocument(value: value)
case .null:
return nil
}
}
}
109 changes: 109 additions & 0 deletions Sources/Smithy/Document/Node.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

/// Contains the value of a Smithy Node.
///
/// Smithy node data is basically the same as the data that can be stored in JSON.
/// The root of a Smithy node may be of any case, i.e. unlike JSON, the root element is not limited to object or list.
///
/// See the definition of node value in the Smithy spec: https://smithy.io/2.0/spec/model.html#node-values
public enum Node: Sendable {
case object([String: Node])
case list([Node])
case string(String)
case number(Double)
case boolean(Bool)
case null
}

public extension Node {

Check failure on line 24 in Sources/Smithy/Document/Node.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
/// Returns the object dictionary if this Node is `.object`, else returns `nil`.
var object: [String: Node]? {
guard case .object(let value) = self else { return nil }
return value
}

/// Returns the array of `Node` if this node is `.list`, else returns `nil`.
var list: [Node]? {
guard case .list(let value) = self else { return nil }
return value
}

/// Returns the string if this node is `.string`, else returns `nil`.
var string: String? {
guard case .string(let value) = self else { return nil }
return value
}

/// Returns the Double if this node is `.number`, else returns `nil`.
var number: Double? {
guard case .number(let value) = self else { return nil }
return value
}

/// Returns the `Bool` value if this node is `.boolean`, else returns `nil`.
var boolean: Bool? {
guard case .boolean(let value) = self else { return nil }
return value
}

/// Returns `true` if this node is `.null`, else returns `false`.
var null: Bool {
guard case .null = self else { return false }
return true
}
}

extension Node: ExpressibleByDictionaryLiteral {

public init(dictionaryLiteral elements: (String, Node)...) {
self = .object(Dictionary(uniqueKeysWithValues: elements))
}
}

extension Node: ExpressibleByArrayLiteral {

public init(arrayLiteral elements: Node...) {
self = .list(elements)
}
}

extension Node: ExpressibleByStringLiteral {

public init(stringLiteral value: String) {
self = .string(value)
}
}

extension Node: ExpressibleByIntegerLiteral {

public init(integerLiteral value: IntegerLiteralType) {
self = .number(Double(value))
}
}

extension Node: ExpressibleByFloatLiteral {

public init(floatLiteral value: FloatLiteralType) {
self = .number(Double(value))
}
}

extension Node: ExpressibleByBooleanLiteral {

public init(booleanLiteral value: BooleanLiteralType) {
self = .boolean(value)
}
}

extension Node: ExpressibleByNilLiteral {

public init(nilLiteral: ()) {
self = .null
}
}
22 changes: 22 additions & 0 deletions Sources/Smithy/Document/ShapeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
/// Reproduces the cases in Smithy `ShapeType`.
/// https://github.com/smithy-lang/smithy/blob/main/smithy-model/src/main/java/software/amazon/smithy/model/shapes/ShapeType.java
public enum ShapeType {

public enum Category {
case simple
case aggregate
case service
case member
}

case blob
case boolean
case string
Expand All @@ -32,4 +40,18 @@ public enum ShapeType {
case service
case resource
case operation

public var category: Category {
switch self {
case .blob, .boolean, .string, .timestamp, .byte, .short, .integer, .long,
.float, .document, .double, .bigDecimal, .bigInteger, .enum, .intEnum:
return .simple
case .list, .set, .map, .structure, .union:
return .aggregate
case .service, .resource, .operation:
return .service
case .member:
return .member
}
}
}
Loading
Loading