Unverified Commit b6b75a7f authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Support Deserializing Http Dates (#86)

* Support Deserializing Http Dates

Deserializing HTTP dates is made slightly more complex because Smithy actually supports a format _not_ outlined by the RFC where the HTTP date
uses fractional seconds. For this reason (as well as dropping the chrono dependency in the future), `httpdate` was forked and incorporated into smithy-types. At a later date, we _may_ consider inlining this dependency into the crates that actually need it.

As a side change, I'm starting to refactor the way that custom serialization works via new-types. This enables generating composable serializers
that are much easier to autogenerate.
parent e79ccb14
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -716,7 +716,6 @@ name = "smithy-types"
version = "0.0.1"
dependencies = [
 "chrono",
 "httpdate",
]

[[package]]
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ class InlineDependency(
        fun genericError() = forRustFile("GenericError", "types", "generic_error.rs", CargoDependency.Serde)
        fun errorCode() = forRustFile("error_code", "error_code", "error_code.rs", CargoDependency.Http)
        fun docJson() = forRustFile("doc_json", "doc_json", "doc_json.rs", CargoDependency.Serde)
        fun instantEpoch() = forRustFile("instant_epoch", "instant_epoch", "instant_epoch.rs", CargoDependency.Serde)
        fun instantHttpDate() = forRustFile("instant_httpdate", "instant_httpdate", "instant_httpdate.rs", CargoDependency.Serde)

        // Stub config implementation as a placeholder before one can be generated dynamically
        fun config() = forRustFile("config", "config", "config.rs", CargoDependency.Rand)
+1 −1
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ fun <T : CodeWriter> T.rust(
 * `CodeWriter` formatting: `#{name:T}`
 */
fun <T : CodeWriter> T.rustTemplate(
    @Language("Rust", prefix = "fn foo(&self) {", suffix = "}") contents: String,
    @Language("Rust", prefix = "macro_rules! foo { () =>  {{ ", suffix = "}}}") contents: String,
    vararg ctx: Pair<String, Any>
) {
    this.pushState()
+9 −1
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ fun CodegenWriterDelegator<RustWriter>.finalize(settings: RustSettings) {
            dep.renderer(it)
        }
    }
    val newDeps = loadDependencies().filterIsInstance<InlineDependency>().distinctBy { it.key() }
    newDeps.forEach { dep ->
        if (!this.writers.containsKey("src/${dep.module}.rs")) {
            this.useFileWriter("src/${dep.module}.rs", "crate::${dep.module}") {
                dep.renderer(it)
            }
        }
    }
    val cargoDependencies = loadDependencies().filterIsInstance<CargoDependency>().distinct()
    this.useFileWriter("Cargo.toml") {
        val cargoToml = CargoTomlGenerator(
@@ -51,7 +59,7 @@ fun CodegenWriterDelegator<RustWriter>.finalize(settings: RustSettings) {
        }
        LibRsGenerator(modules).render(writer)
    }
    this.flushWriters()
    flushWriters()
}

fun CodegenWriterDelegator<RustWriter>.withModule(
+0 −1
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ class CodegenVisitor(context: PluginContext, extraProtocols: ProtocolMap = mapOf
        val serviceShapes = Walker(model).walkShapes(service)
        serviceShapes.forEach { it.accept(this) }
        writers.finalize(settings)
        writers.flushWriters()
        try {
            "cargo fmt".runCommand(fileManifest.baseDir)
        } catch (_: CommandFailed) {
Loading