Unverified Commit d79e80c9 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Refactor smithy-json and fix several protocol tests for the new JsonSerializerGenerator (#418)

* Split out a JsonValueWriter from JsonObjectWriter/JsonArrayWriter

* Add document support to JsonSerializerGenerator

* Add operation support to JsonSerializerGenerator

* Fix some bugs found by protocol tests

* Fix struct serializer function naming bug

* Fix handling of sparse lists and maps

* CR feedback
parent 70a3526b
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -73,16 +73,6 @@ fun <T : CodeWriter> T.rust(
    this.write(contents, *args)
}

/**
 * Convenience wrapper that tells Intellij that the contents of this block are Rust
 */
fun <T : CodeWriter> T.rustInline(
    @Language("Rust", prefix = "macro_rules! foo { () =>  {{ ", suffix = "}}}") contents: String,
    vararg args: Any
) {
    this.writeInline(contents, *args)
}

/**
 * Sibling method to [rustBlock] that enables `#{variablename}` style templating
 */
+1 −2
Original line number Diff line number Diff line
@@ -152,8 +152,7 @@ class HttpTraitProtocolGenerator(
        payloadName: String,
        serializer: StructuredDataSerializerGenerator
    ): BodyMetadata {
        val targetShape = model.expectShape(member.target)
        return when (targetShape) {
        return when (val targetShape = model.expectShape(member.target)) {
            // Write the raw string to the payload
            is StringShape -> {
                if (targetShape.hasTrait<EnumTrait>()) {
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

package software.amazon.smithy.rust.codegen.smithy.protocols

import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.shapes.UnionShape
import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.util.toSnakeCase

/**
 * Creates a unique name for a serialization function.
 *
 * The prefixes will look like the following (for grep):
 * - serialize_operation
 * - serialize_structure
 * - serialize_union
 * - serialize_payload
 */
fun RustSymbolProvider.serializeFunctionName(shape: Shape): String = shapeFunctionName("serialize", shape)

private fun RustSymbolProvider.shapeFunctionName(prefix: String, shape: Shape): String {
    val symbolNameSnakeCase = toSymbol(shape).name.toSnakeCase()
    return prefix + "_" + when (shape) {
        is OperationShape -> "operation_$symbolNameSnakeCase"
        is StructureShape -> "structure_$symbolNameSnakeCase"
        is UnionShape -> "union_$symbolNameSnakeCase"
        is MemberShape -> "payload_${shape.target.name.toSnakeCase()}_${shape.container.name.toSnakeCase()}"
        else -> TODO("SerializerFunctionNamer.name: $shape")
    }
}
+172 −153

File changed.

Preview size limit exceeded, changes collapsed.

+11 −11

File changed.

Preview size limit exceeded, changes collapsed.

Loading