-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Add operation and type registry codegen #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: epic/sbs
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,11 @@ public let allSupportedTraits = Set([ | |
| ErrorTrait.id, | ||
| InputTrait.id, | ||
| OutputTrait.id, | ||
| RequiredTrait.id, | ||
| SensitiveTrait.id, | ||
| SparseTrait.id, | ||
| TimestampFormatTrait.id, | ||
| UnitTypeTrait.id, // UnitTypeTrait will only ever appear in Prelude.unitSchema | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above, new trait types are added to the runtime "allow list". |
||
|
|
||
| // Synthetic traits | ||
| TargetsUnitTrait.id, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| public struct RequiredTrait: Trait { | ||
| public static var id: ShapeID { .init("smithy.api", "required") } | ||
|
|
||
| public var node: Node { [:] } | ||
|
|
||
| public init(node: Node) throws {} | ||
|
|
||
| public init() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| public struct TimestampFormatTrait: Trait { | ||
|
|
||
| public enum Format: String { | ||
| case dateTime = "date-time" | ||
| case httpDate = "http-date" | ||
| case epochSeconds = "epoch-seconds" | ||
| } | ||
|
|
||
| public static var id: ShapeID { .init("smithy.api", "timestampFormat") } | ||
|
|
||
| public let format: Format | ||
|
|
||
| public init(node: Node) throws { | ||
| guard let formatString = node.string else { | ||
| throw TraitError("TimestampFormatTrait does not have string value") | ||
| } | ||
| guard let format = Format(rawValue: formatString) else { | ||
| throw TraitError("TimestampFormatTrait string value is not valid") | ||
| } | ||
| self.format = format | ||
| } | ||
|
|
||
| public var node: Node { .string(format.rawValue) } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // Copyright Amazon.com Inc. or its affiliates. | ||
| // All Rights Reserved. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| public struct UnitTypeTrait: Trait { | ||
| public static var id: ShapeID { .init("smithy.api", "Unit") } | ||
|
|
||
| public var node: Node { [:] } | ||
|
|
||
| public init(node: Node) throws {} | ||
|
|
||
| public init() {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import ArgumentParser | ||
| import Foundation | ||
| import struct SmithyCodegenCore.CodeGenerator | ||
| import struct SmithyCodegenCore.SwiftSettings | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file adds new params to support various new code generator features, plus the operations & type registry Swift files. |
||
|
|
||
| @main | ||
| struct SmithyCodegenCLI: AsyncParsableCommand { | ||
|
|
@@ -18,6 +19,15 @@ struct SmithyCodegenCLI: AsyncParsableCommand { | |
| @Argument(help: "The full or relative path to read the JSON AST model input file.") | ||
| var modelPath: String | ||
|
|
||
| @Option(help: "The sdkId used by the Smithy-based code generator") | ||
| var sdkId: String? | ||
|
|
||
| @Option(help: "Set this to true if the client to be generated should be internal-scoped.") | ||
| var `internal` = false | ||
|
|
||
| @Option(help: "The comma-separated list of operation IDs to be included in the client.") | ||
| var operations: String? | ||
|
|
||
| @Option(help: "The full or relative path to write the Schemas output file.") | ||
| var schemasPath: String? | ||
|
|
||
|
|
@@ -27,12 +37,26 @@ struct SmithyCodegenCLI: AsyncParsableCommand { | |
| @Option(help: "The full or relative path to write the Deserialize output file.") | ||
| var deserializePath: String? | ||
|
|
||
| @Option(help: "The full or relative path to write the TypeRegistry output file.") | ||
| var typeRegistryPath: String? | ||
|
|
||
| @Option(help: "The full or relative path to write the Operations output file.") | ||
| var operationsPath: String? | ||
|
|
||
| func run() async throws { | ||
|
|
||
| let start = Date() | ||
|
|
||
| let currentWorkingDirectoryFileURL = currentWorkingDirectoryFileURL() | ||
|
|
||
| let operations = (operations ?? "").split(separator: ",").map(String.init) | ||
| let settings = try SwiftSettings( | ||
| service: service, | ||
| sdkId: sdkId, | ||
| internal: `internal`, | ||
| operations: operations | ||
| ) | ||
|
|
||
| // Create the model file URL | ||
| let modelFileURL = URL(fileURLWithPath: modelPath, relativeTo: currentWorkingDirectoryFileURL) | ||
| guard FileManager.default.fileExists(atPath: modelFileURL.path) else { | ||
|
|
@@ -48,13 +72,21 @@ struct SmithyCodegenCLI: AsyncParsableCommand { | |
| // If --deserialize-path was supplied, create the Deserialize file URL | ||
| let deserializeFileURL = resolve(path: deserializePath) | ||
|
|
||
| // If --type-registry-path was supplied, create the TypeRegistry file URL | ||
| let typeRegistryFileURL = resolve(path: typeRegistryPath) | ||
|
|
||
| // If --operations-path was supplied, create the Operations file URL | ||
| let operationsFileURL = resolve(path: operationsPath) | ||
|
|
||
| // Use resolved file URLs to run code generator | ||
| try CodeGenerator( | ||
| service: service, | ||
| settings: settings, | ||
| modelFileURL: modelFileURL, | ||
| schemasFileURL: schemasFileURL, | ||
| serializeFileURL: serializeFileURL, | ||
| deserializeFileURL: deserializeFileURL | ||
| deserializeFileURL: deserializeFileURL, | ||
| typeRegistryFileURL: typeRegistryFileURL, | ||
| operationsFileURL: operationsFileURL | ||
| ).run() | ||
|
|
||
| let duration = Date().timeIntervalSince(start) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the
UnitTypeTraitto thesmithy.api#Unitschema.