Skip to content
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

feat: Move RPCv2CBOR generation to smithy-swift #900

Merged
merged 38 commits into from
Feb 5, 2025
Merged

Conversation

dayaffe
Copy link
Contributor

@dayaffe dayaffe commented Jan 29, 2025

Issue #

SWIFT-2276

Description of changes

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

public typealias RuntimeConfigType
= DefaultSDKRuntimeConfiguration<DefaultRetryStrategy, DefaultRetryErrorInfoProvider>

open class ClientConfigDefaultsProvider {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously only AWSClientConfigDefaultsProvider existed. This separates out code that was not AWS specific to allow for supporting protocol generation in the future.

endpointResolverBlock: @escaping (Params) throws -> Endpoint,
endpointParams: Params,
paramsBlock: @escaping (Context) throws -> Params,
resolverBlock: @escaping (Params) throws -> Endpoint,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This updates EndpointResolverMiddleware.swift in smithy-swift to include type updates made to the same class in AWSClientRuntime

import class SmithyHTTPAPI.HTTPResponse
@_spi(SmithyReadWrite) import class SmithyCBOR.Reader

public struct RpcV2CborError: BaseError {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift


import SmithyHTTPAPI

public struct CborValidateResponseHeaderMiddleware<Input, Output> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift

/**
* Generates code for EndpointResolver tests.
*/
class EndpointTestGenerator(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift as it is used by protocol generators

import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.middleware.OperationMiddleware

class SmithyHttpProtocolClientGeneratorFactory : HttpProtocolClientGeneratorFactory {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created to support protocol generators in smithy swift

const val AUTH_SCHEME_RESOLVER = "authSchemeResolver"
const val ENDPOINT_PARAMS = "endpointParams"

class SmithyServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.GenerationContext) :
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created to support SmithyHttpProtocolClientGeneratorFactory which is used in Protocol generators

import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable
import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes

class MutateHeadersMiddleware(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift

* Generates EndpointResolverMiddleware interception code.
* Including creation of EndpointParams instance and pass it as middleware param along with EndpointResolver
*/
open class OperationEndpointResolverMiddleware(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift. aws-sdk-swift now has AWSOperationEndpointResolverMiddleware which adds AWS specific logic related to account-id based & general endpoint resolution

}
}

open fun handleBuiltInParam(param: Parameter, writer: SwiftWriter): String {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored to support overriding in AWSOperationEndpointResolverMiddleware

}
}

open fun handleClientContextParam(param: Parameter, writer: SwiftWriter): String {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored to support overriding in AWSOperationEndpointResolverMiddleware

import software.amazon.smithy.swift.codegen.integration.ServiceConfig
import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes

class RpcV2CborCustomizations : DefaultHTTPProtocolCustomizations() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved from aws-sdk-swift

import software.amazon.smithy.swift.codegen.model.targetOrSelf
import software.amazon.smithy.swift.codegen.testModuleName

class RpcV2CborProtocolGenerator(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from aws-sdk-swift and directly inherits HTTPBindingProtocolGenerator rather than AWSHTTPBindingProtocolGenerator. This class adds in logic from AWSHTTPBindingProtocolGenerator directly into the protocol generator.

import software.amazon.smithy.swift.codegen.model.shapes
import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes

class CborValidateResponseHeaderIntegration : SwiftIntegration {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved from aws-sdk-swift

Copy link
Contributor

@sichanyoo sichanyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments; 1 for changing method signature & 1 that's up to you

).generateProtocolTests() + renderEndpointsTests(ctx)
}

fun renderEndpointsTests(ctx: ProtocolGenerator.GenerationContext): Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code unique to CBOR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dayaffe dayaffe merged commit d224c1d into main Feb 5, 2025
27 checks passed
@dayaffe dayaffe deleted the day/move-rpcv2 branch February 5, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants