Unverified Commit bbe82cd2 authored by Matteo Bigoi's avatar Matteo Bigoi Committed by GitHub
Browse files

Add initial implementation of a Server example (#1222)

We are adding this example service in the aws-smithy-http-server folder to showcase the SSDK and to be able soon to run benchmarks against this example.

This change includes a new model for the Pokémon Service and all the necessary infrastructure to code generate the client and server SKDs and make them available to the runtime implementation.

A basic README has also been added with instructions on how to build, run and test the service.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
parent d4c23e3f
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -37,17 +37,20 @@ val allCodegenTests = listOf(
    CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"),
    CodegenTest("aws.protocoltests.restjson.validation#RestJsonValidation", "rest_json_validation"),
    CodegenTest("com.amazonaws.ebs#Ebs", "ebs"),
    CodegenTest("com.amazonaws.s3#AmazonS3", "s3")
    CodegenTest("com.amazonaws.s3#AmazonS3", "s3"),
    CodegenTest("com.aws.example#PokemonService", "pokemon_service_sdk")
)

task("generateSmithyBuild") {
    description = "generate smithy-build.json"
    doFirst {
        projectDir.resolve("smithy-build.json")
            .writeText(generateSmithyBuild(
            .writeText(
                generateSmithyBuild(
                    rootProject.projectDir.absolutePath,
                    pluginName,
                codegenTests(properties, allCodegenTests))
                    codegenTests(properties, allCodegenTests)
                )
            )
    }
}
+109 −0
Original line number Diff line number Diff line
$version: "1.0"

namespace com.aws.example

use aws.protocols#restJson1

/// The Pokémon Service allows you to retrieve information about Pokémon species.
@title("Pokémon Service")
@restJson1
service PokemonService {
    version: "2021-12-01",
    resources: [PokemonSpecies],
    operations: [GetServerStatistics],
}

/// A Pokémon species forms the basis for at least one Pokémon.
@title("Pokémon Species")
resource PokemonSpecies {
    identifiers: {
        name: String
    },
    read: GetPokemonSpecies,
}

/// Retrieve information about a Pokémon species.
@readonly
@http(uri: "/pokemon-species/{name}", method: "GET")
operation GetPokemonSpecies {
    input: GetPokemonSpeciesInput,
    output: GetPokemonSpeciesOutput,
    errors: [ResourceNotFoundException],
}

@input
structure GetPokemonSpeciesInput {
    @required
    @httpLabel
    name: String
}

@output
structure GetPokemonSpeciesOutput {
    /// The name for this resource.
    @required
    name: String,

    /// A list of flavor text entries for this Pokémon species.
    @required
    flavorTextEntries: FlavorTextEntries
}

/// Retrieve HTTP server statistiscs, such as calls count.
@readonly
@http(uri: "/stats", method: "GET")
operation GetServerStatistics {
    input: GetServerStatisticsInput,
    output: GetServerStatisticsOutput,
}

@input
structure GetServerStatisticsInput { }

@output
structure GetServerStatisticsOutput {
    /// The number of calls executed by the server.
    @required
    calls_count: Long,
}

list FlavorTextEntries {
    member: FlavorText
}

structure FlavorText {
    /// The localized flavor text for an API resource in a specific language.
    @required
    flavorText: String,

    /// The language this name is in.
    @required
    language: Language,
}

/// Supported languages for FlavorText entries.
@enum([
    {
        name: "ENGLISH",
        value: "en",
        documentation: "American English.",
    },
    {
        name: "SPANISH",
        value: "es",
        documentation: "Español.",
    },
    {
        name: "ITALIAN",
        value: "it",
        documentation: "Italiano.",
    },
])
string Language

@error("client")
@httpError(404)
structure ResourceNotFoundException {
    @required
    message: String,
}
+8 −5
Original line number Diff line number Diff line
@@ -83,17 +83,20 @@ val allCodegenTests = listOf(
        """
            , "codegen": { "renameErrors": false }
        """.trimIndent()
    )
    ),
    CodegenTest("com.aws.example#PokemonService", "pokemon_service_client")
)

task("generateSmithyBuild") {
    description = "generate smithy-build.json"
    doFirst {
        projectDir.resolve("smithy-build.json")
            .writeText(generateSmithyBuild(
            .writeText(
                generateSmithyBuild(
                    rootProject.projectDir.absolutePath,
                    pluginName,
                codegenTests(properties, allCodegenTests))
                    codegenTests(properties, allCodegenTests)
                )
            )
    }
}
+1 −0
Original line number Diff line number Diff line
../../codegen-server-test/model/pokemon.smithy
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
pokemon_service_client/
pokemon_service_sdk/
Loading