### Run the example service with sbt or mill Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/02-quickstart.md Commands to run the example service using sbt or mill build tools. ```bash sbt "example/run" ``` ```bash mill example.run ``` -------------------------------- ### Start local development server with yarn start Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/website/README.md Starts the local development server and opens a browser window. Most changes are reflected live without restarting the server. ```bash yarn start ``` -------------------------------- ### Install smithy4s CLI with coursier Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/04-cli.md Installs the smithy4s CLI using coursier. This is the recommended installation method. ```bash cs install --contrib smithy4s ``` -------------------------------- ### Copy .sbtopts.example to .sbtopts Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/README.md Copies the example sbt options file to the active one so you can adjust memory settings for sbt. ```bash cp .sbtopts.example .sbtopts ``` -------------------------------- ### Install dependencies with yarn Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/website/README.md Installs the dependencies for the Docusaurus website. ```bash yarn ``` -------------------------------- ### packagePrefix metadata example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/18-package-remapping.md Sets a prefix that is prepended to every generated package name. A shape in namespace com.example.api will be placed in package internal.generated.com.example.api. ```smithy metadata smithy4sCodegen = { packagePrefix: "internal.generated" } ``` -------------------------------- ### Full smithy4sCodegen metadata configuration Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/18-package-remapping.md Complete configuration example for package remapping using the smithy4sCodegen metadata key. All four fields are optional and can be combined freely. ```smithy $version: "2.0" metadata smithy4sCodegen = { packagePrefix: "internal.generated", packageMappings: { "com.example.special": "explicit.pkg" }, allowedNamespaces: [ "com.example.*" ], excludedNamespaces: [ "com.example.ignored" ] } ``` -------------------------------- ### Generated CLI usage output Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/06-deriving-cli.md Example output of the generated command's help text, showing the usage line, HTTP method, and options. ```text Usage: hello-world-service hello [--output ] [] HTTP POST /{name} Options and flags: --help Display this help text. --output Output mode ``` -------------------------------- ### Generic access to service product via ServiceProduct.Mirror Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/10-service-product.md Generic access to a service product using a ServiceProduct.Mirror. The example shows how to obtain the product for a service. ```scala import smithy4s.ServiceProduct def productOf[Alg[_[_, _, _, _, _]]](mirror: ServiceProduct.Mirror[Alg]) = mirror.serviceProduct // example def exampleProduct = productOf(ExampleService) ``` -------------------------------- ### Inline Smithy specification from sample file Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/05-compliance-tests.md Inline a Smithy specification from a sample file named test.smithy. This is used in the documentation to display the example specification. ```scala docs.InlineSmithyFile.fromSample("test.smithy") ``` -------------------------------- ### Use generated lenses with andThen and some Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/19-optics.md Shows how to use generated lenses: compose them with .andThen and .some, then project or replace values. The example verifies that get and set operations produce the expected results. ```scala import smithy4s.example._ val input = TestInput("test", TestBody(Some("test body"))) val lens = TestInput.optics.body.andThen(TestBody.optics.data).some val resultGet = lens.project(input) resultGet == Option("test body") // true val resultSet = lens.replace("new body")(input) val updatedInput = TestInput("test", TestBody(Some("new body"))) resultSet == updatedInput // true ``` -------------------------------- ### Static-world service call example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/dynamic.md Shows a static-world example of calling a service method with a known type, which is not possible with dynamic models. ```scala import cats.effect.IO import weather._ // imagine this comes from an interpreter val client: WeatherService[IO] = ??? : WeatherService[IO] client.getWeather(city = "hello") ``` -------------------------------- ### packageMappings metadata example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/18-package-remapping.md Maps individual namespaces to explicit package names. Overrides any packagePrefix for the matched namespace. ```smithy metadata smithy4sCodegen = { packageMappings: { "com.example.special": "explicit.pkg" } } ``` -------------------------------- ### Start http4s server with IOLocal Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/extract-request-info.md Main entry point that creates the IOLocal with Option.empty[RequestInfo] and starts the http4s Ember server on localhost:9000. The IOLocal value is never used in practice because the middleware sets it on every request. ```scala import cats.effect.IOApp import com.comcast.ip4s._ import org.http4s.ember.server.EmberServerBuilder object Main extends IOApp.Simple { def run: IO[Unit] = IOLocal(Option.empty[RequestInfo]).flatMap { local => Routes .getAll(local) .flatMap { routes => EmberServerBuilder .default[IO] .withHost(host"localhost") .withPort(port"9000") .withHttpApp(routes.orNotFound) .build } .useForever } } ``` -------------------------------- ### Encode and decode XML with smithy4s.xml.Xml Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/02.1-serialisation/xml.mdx Shows how to use the Xml entrypoint to create an encoder and decoder from a schema, encode a Person instance to an XML string, and decode it back. The example imports Person from smithy4s.example.hello and uses Blob for the decode input. ```scala import smithy4s.example.hello.Person import smithy4s.Blob import smithy4s.xml.Xml val personEncoder = Xml.encoders.fromSchema(Person.schema) val personXML = personEncoder.encode(Person(name = "John Doe")).toUTF8String val personDecoder = Xml.decoders.fromSchema(Person.schema) val maybePerson = personDecoder.decode(Blob(personXML)) ``` -------------------------------- ### Usage of static description Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/10-service-product.md Usage example for the static description implementation. Calls descriptor on a service and accesses the resulting operation description. ```scala // Usage val desc: String = descriptor(ExampleService).exampleOperation ``` -------------------------------- ### Usage of non-linear input client Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/10-service-product.md Usage example for the non-linear input client. Calls listClient with an implementation and the service product, then invokes the operation with a list of inputs. ```scala listClient(impl)( /* implicit scope problem here - TODO */ ExampleService.serviceProduct) .exampleOperation( List("a", "b", "c").map(ExampleOperationInput(_)) ) ``` -------------------------------- ### Implement service and run Ember server Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/02-quickstart.md Implements the generated HelloWorldService trait, builds HTTP routes with SimpleRestJsonBuilder, adds Swagger docs, and starts an Ember server on localhost:9000. Place this file in modules/example/src/main/scala/Main.scala (sbt) or example/src/Main.scala (mill). ```scala import smithy4s.example.hello._ import cats.effect._ import cats.implicits._ import org.http4s.implicits._ import org.http4s.ember.server._ import org.http4s._ import com.comcast.ip4s._ import smithy4s.http4s.SimpleRestJsonBuilder object HelloWorldImpl extends HelloWorldService[IO] { def hello(name: String, town: Option[String]): IO[Greeting] = IO.pure { town match { case None => Greeting(s"Hello $name!") case Some(t) => Greeting(s"Hello $name from $t!") } } } object Routes { private val example: Resource[IO, HttpRoutes[IO]] = SimpleRestJsonBuilder.routes(HelloWorldImpl).resource private val docs: HttpRoutes[IO] = smithy4s.http4s.swagger.docs[IO](HelloWorldService) val all: Resource[IO, HttpRoutes[IO]] = example.map(_ <+> docs) } object Main extends IOApp.Simple { val run = Routes.all .flatMap { routes => EmberServerBuilder .default[IO] .withPort(port"9000") .withHost(host"localhost") .withHttpApp(routes.orNotFound) .build } .use(_ => IO.never) } ``` -------------------------------- ### Surface errors into EitherT Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/cats.mdx Transforms a KVStore[IO] service into a KVStore.ErrorAware[EitherT[IO, *, *]] using EitherTTransformations.surfaceError. The example defines a KVStore implementation that raises a KeyNotFoundError for get. ```scala import cats.effect.IO import cats.data.EitherT import smithy4s.example._ import smithy4s.example.KVStore import smithy4s.interopcats.EitherTTransformations val kvStoreIO: KVStore[IO] = new KVStore[IO] { def delete(key: String): IO[Unit] = IO.unit def put(key: String, value: String): IO[Unit] = IO.unit def get(key: String): IO[Value] = IO.raiseError(KeyNotFoundError(s"Key $key wasn't found")) } val kvStoreEitherT: KVStore.ErrorAware[EitherT[IO, *, *]] = kvStoreIO.transform(EitherTTransformations.surfaceError[IO]) ``` -------------------------------- ### Absorb errors from EitherT Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/cats.mdx Transforms a KVStore.ErrorAware[EitherT[IO, *, *]] implementation back into a KVStore[IO] using EitherTTransformations.absorbError. The example defines an implementation that returns EitherT.rightT for delete and put, and EitherT.leftT for get. ```scala val kvStoreEitherTImpl: KVStore.ErrorAware[EitherT[IO, *, *]] = new KVStore.ErrorAware[EitherT[IO, *, *]] { def delete(key: String): EitherT[IO, KVStore.DeleteError, Unit] = EitherT.rightT(()) def put(key: String, value: String): EitherT[IO, KVStore.PutError, Unit] = EitherT.rightT(()) def get(key: String): EitherT[IO, KVStore.GetError, Value] = EitherT.leftT( KVStore.GetError.KeyNotFoundErrorCase( KeyNotFoundError(s"Key $key wasn't found") ) ) } val kvStoreIOAgain: KVStore[IO] = kvStoreEitherTImpl.transform(EitherTTransformations.absorbError[IO]) ``` -------------------------------- ### Use the value function on Lenses for NewTypes Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/19-optics.md Shows the value function on Prisms and Lenses to abstract over NewTypes, similar to .some for Option types. The example uses a Lens to get and replace a NewType value. ```scala import smithy4s.example._ val input = GetCityInput(CityId("test")) val cityName: smithy4s.optics.Lens[GetCityInput, String] = GetCityInput.optics.cityId.value val updated = cityName.replace("Fancy New Name")(input) val result = cityName.project(updated) Option("Fancy New Name") == result // true ``` -------------------------------- ### Show smithy4s CLI help Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/04-cli.md Displays the exhaustive listing of CLI options, including customization of output directories, skipping openapi or scala generation, and filtering allowed namespaces. ```bash smithy4s --help ``` -------------------------------- ### Access service product via ExampleServiceGen.serviceProduct Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/10-service-product.md Accesses the service product version of a service using the generated service product companion. ```scala import smithy4s.example.product._ ExampleServiceGen.serviceProduct ``` -------------------------------- ### Define Smithy service with simpleRestJson Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/02-quickstart.md Defines a HelloWorldService with a simple REST JSON protocol, a POST operation with a path label and query parameter, and required fields. Place this file in modules/example/src/main/smithy/ExampleService.smithy (sbt) or example/smithy/ExampleService.smithy (mill). ```smithy namespace smithy4s.example.hello use alloy#simpleRestJson @simpleRestJson service HelloWorldService { version: "1.0.0", operations: [Hello] } @http(method: "POST", uri: "/{name}", code: 200) operation Hello { input: Person, output: Greeting } structure Person { @httpLabel @required name: String, @httpQuery("town") town: String } structure Greeting { @required message: String } ``` -------------------------------- ### smithy4sGenerated manifest example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/18-package-remapping.md Example of the smithy4sGenerated tracking manifest that Smithy4s writes when generating code for Module A with a packagePrefix. It records the namespace-to-package mapping for cross-module remapping. ```smithy metadata smithy4sGenerated = [{ namespaces: ["com.example.api"], renderedPackages: { "com.example.api": "gen.com.example.api" } }] ``` -------------------------------- ### Deploy website using SSH Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/website/README.md Deploys the website using SSH. ```bash USE_SSH=true yarn deploy ``` -------------------------------- ### SBT setup with official AWS model artifact Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/03-aws/01-aws.md Alternative SBT setup that directly depends on the official AWS model artifact for DynamoDB. The version is sourced from the plugin's AWS object, and the artifact is under the software.amazon.api.models group. ```scala libraryDependencies ++= Seq( // version sourced from the plugin "com.disneystreaming.smithy4s" %% "smithy4s-aws-http4s" % smithy4sVersion.value, "software.amazon.api.models" % "dynamodb" % AWS.dynamodb._2 % Smithy4s ) ``` -------------------------------- ### Example usage of DynamoDB client with smithy4s Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/03-aws/01-aws.md Example usage of smithy4s AWS client for DynamoDB. Builds an HTTP client with Ember, creates an AWS environment with region US_EAST_1, and uses AwsClient to obtain a DynamoDB client. Calls listTables with a limit of 10 and prints the result. ```scala import cats.effect._ import org.http4s.ember.client.EmberClientBuilder import smithy4s.aws._ // AWS specific interpreters import com.amazonaws.dynamodb._ // Generated code from specs. object Main extends IOApp.Simple { def run = resource.use { case (dynamodb) => dynamodb .listTables(limit = Some(ListTablesInputLimit(10))) .flatMap(IO.println(_)) } val resource: Resource[IO, DynamoDB[IO]] = for { httpClient <- EmberClientBuilder.default[IO].build awsEnv <- AwsEnvironment.default(httpClient, AwsRegion.US_EAST_1) dynamodb <- AwsClient(DynamoDB, awsEnv) } yield dynamodb } ``` -------------------------------- ### Imports for server-side middleware Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/endpoint-middleware.md Imports required for the server-side middleware example, including smithy4s, cats-effect, and http4s classes. ```scala import smithy4s.example.guides.auth._ import cats.effect._ import cats.implicits._ import org.http4s._ import smithy4s.http4s.SimpleRestJsonBuilder import smithy4s._ import org.http4s.headers.Authorization import smithy4s.http4s.ServerEndpointMiddleware ``` -------------------------------- ### Build and use static client with WeatherService Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/dynamic.md Builds a static, compile-time client using the WeatherService and invokes the GetWeather operation with a Document input. Requires the `weather` package and `routes` in scope. ```scala import weather._ val clientStatic = SimpleRestJsonBuilder(WeatherService) .client(Client.fromHttpApp(routes)) .make .toTry .get run( service = WeatherService, operationName = "GetWeather", input = Document.obj("city" -> Document.fromString("London")), alg = clientStatic, ).unsafeRunSync().show ``` -------------------------------- ### Static hint binding example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/17-hint-bindings.md Shows a static hint binding that fails to compile when a new field is added to the trait. ```scala case class Foo(a: String) ``` ```scala val hints = Hints(Foo(a = "test", b = Some(2))) ``` -------------------------------- ### HelloWorld service implementation with cats.effect.IO Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/06-deriving-cli.md Scala implementation of the HelloWorldService using cats.effect.IO. The service instance is used later to derive a CLI. ```scala import smithy4s.example.hello._ import cats.effect.IO object HelloWorldServiceInstance{ val simple = new HelloWorldService[IO]{ def hello(name: String, town: Option[String]): IO[Greeting] = { IO { Greeting(s"hello $name , who hails from $town") } } } } ``` -------------------------------- ### Create documentation routes with smithy4s.swagger.docs Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/04-simple-rest-json/04-openapi.md Creates an `HttpRoutes` for docs with several options: default `/docs`, custom path, multiple services, and custom Swagger UI resources. The default documentation path is `/docs`. ```scala import org.http4s._ import cats.effect.IO // the package under which the scala code was generated import smithy4s.example.hello._ object Docs { //simplest val myDocRoutes: HttpRoutes[IO] = smithy4s.http4s.swagger.docs[IO](HelloWorldService) // documentation served at /custom-docs val customPath: HttpRoutes[IO] = smithy4s.http4s.swagger.docs.withPath("custom-docs")(HelloWorldService) // documentation served at /docs with multiple service specification defined. val multipleServices: HttpRoutes[IO] = smithy4s.http4s.swagger.docs[IO](HelloWorldService, HelloWorldService) // documentation served at /custom-docs with swagger assets from `/swagger-ui-path` // (from the classpath) being used. val customSetup = smithy4s.http4s.swagger.docs[IO] .withPath("custom-docs") .withSwaggerUiResources("/META-INF/custom-swagger-ui")(HelloWorldService) } ``` -------------------------------- ### Using Visitor.Default for default values Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/02-unions.md Shows how to implement a visitor using Visitor.Default to provide a default value for unhandled cases. Creates a Pet.DogCase, defines a Pet.Visitor.Default[String] with a default method returning "default value" and only implements the cat method. Calling myPet.accept(visitor) returns "default value" because the dog case is not explicitly handled. ```scala val myPet: Pet = Pet.DogCase(Dog(name = "Spot")) val visitor = new Pet.Visitor.Default[String] { def default: String = "default value" def cat(cat: Cat): String = s"Cat named ${cat.name}" } myPet.accept(visitor) // "default value" ``` -------------------------------- ### Compose documentation routes with service routes Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/04-simple-rest-json/04-openapi.md Composes the documentation routes with service routes using the `<+>` operator and converts the result to a `HttpApp`. Requires the `HelloWorldImpl` service implementation. ```scala import smithy4s.http4s._ import smithy4s.http4s.swagger.docs import cats.effect.IO import cats.implicits._ import org.http4s.implicits._ import smithy4s.example.hello._ // ... val docRoutes = docs[IO](HelloWorldService) val app = SimpleRestJsonBuilder .routes(HelloWorldImpl) .make .map(serviceRoutes => docRoutes <+> serviceRoutes) .map(_.orNotFound) // ... ``` -------------------------------- ### Generated enum WeatherType Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/16-binary-compatibility.md Example of a generated enum in library A v1. Adding a new value later can cause runtime MatchError in dependent libraries. ```scala sealed abstract class WeatherType object WeatherType { case object WINDY extends WeatherType case object RAINY extends WeatherType //... } ``` -------------------------------- ### Show smithy4s generate help Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/04-cli.md Shows help for the codegen command, which generates Scala code and OpenAPI specs from smithy specs. ```bash smithy4s generate --help ``` -------------------------------- ### Enter Nix development shell with Flakes Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/README.md Loads all required development packages into the shell using Nix Flakes. Requires Nix 2.4 or later. Exit with 'exit' or Ctrl+D. ```bash nix develop ``` -------------------------------- ### Enter Nix development shell without Flakes Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/README.md Alternative to 'nix develop' for users without Flakes support. Loads the development environment. ```bash nix-shell ``` -------------------------------- ### Instantiate a stub service with HelloWorldService.Default Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/07-stubs.md Creates a stub implementation of the generated HelloWorldService interface using the Default class. The constructor parameter is the value returned by any method invocation. Ascribing the type is important when using this feature. ```scala import smithy4s.example.hello._ import cats.effect._ val stubbedHelloWorld: HelloWorldService[IO] = new HelloWorldService.Default[IO](IO.stub) ``` -------------------------------- ### allowedNamespaces metadata example Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/18-package-remapping.md Restricts code generation to the listed namespaces. When set, only namespaces matching at least one of the patterns are processed. Accepts the same wildcard patterns as excludedNamespaces. ```smithy metadata smithy4sCodegen = { allowedNamespaces: ["com.example.*"] } ``` -------------------------------- ### Define RequestInfo and implement HelloWorldService Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/extract-request-info.md Defines a case class to hold extracted header values)Skip the constructor parameter that provides the RequestInfo to the service implementation. ```scala case class RequestInfo(contentType: String, userAgent: String) ``` ```scala import smithy4s.example.hello._ import cats.effect.IO import cats.effect.IOLocal final class HelloWorldServiceImpl(requestInfo: IO[RequestInfo]) extends HelloWorldService[IO] { def hello(name: String, town: Option[String]): IO[Greeting] = requestInfo.flatMap { reqInfo: RequestInfo => IO.println("REQUEST_INFO: " + reqInfo) .as(Greeting(s"Hello, $name")) } } ``` -------------------------------- ### Configure build.sbt for smithy4s codegen Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/02-quickstart.md Enables the Smithy4sCodegenPlugin in an sbt project and adds required dependencies for http4s and swagger support. This setup is needed to compile smithy4s-generated code. ```scala import smithy4s.codegen.Smithy4sCodegenPlugin ThisBuild / scalaVersion := "@SCALA_VERSION@" val example = project .in(file("modules/example")) .enablePlugins(Smithy4sCodegenPlugin) .settings( libraryDependencies ++= Seq( "com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value, "com.disneystreaming.smithy4s" %% "smithy4s-http4s-swagger" % smithy4sVersion.value, "org.http4s" %% "http4s-ember-server" % "@HTTP4S_VERSION@" ) ) ``` -------------------------------- ### Show smithy4s dump-model help Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/01-overview/04-cli.md Shows help for the dump-model command, which dumps the smithy model. ```bash smithy4s dump-model --help ``` -------------------------------- ### KVStoreOp sealed trait Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/05-design/03-services.md Shows the sealed trait that forms the initial encoding of the service interface for the KVStore example. It has type parameters for input, error, output, and streaming types. ```scala sealed trait KVStoreOp[Input, Error, Output, StreamedInput, StreamedOutput] ``` -------------------------------- ### Static description of services using mapK5 Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/04-codegen/01-customisation/10-service-product.md Implementation of a static description of a service product. Uses mapK5 and PolyFunction5 to transform each endpoint into a string description. ```scala import smithy4s.kinds.PolyFunction5 type Describe[_, _, _, _, _] = String def descriptor[Alg[_[_, _, _, _, _]]](mirror: ServiceProduct.Mirror[Alg]): mirror.Prod[Describe] = mirror .serviceProduct .mapK5( mirror.serviceProduct.endpointsProduct, new PolyFunction5[mirror.serviceProduct.service.Endpoint, Describe] { override def apply[I, E, O, SI, SO]( fa: mirror.serviceProduct.service.Endpoint[I, E, O, SI, SO] ): Describe[I, E, O, SI, SO] = s"def ${fa.name}(input: ${fa.input.shapeId.name}): ${fa.output.shapeId.name}" }, ) ``` -------------------------------- ### Derive Show instance from schema Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/06-guides/cats.mdx Derives a cats.Show instance for a type with a Smithy4s Schema using SchemaVisitorShow. The example uses Person.schema and imports the necessary cats and smithy4s classes. ```scala import cats.Show import smithy4s.example.hello.Person import smithy4s.interopcats.SchemaVisitorShow implicit val personShow: Show[Person] = SchemaVisitorShow.fromSchema(Person.schema) ``` -------------------------------- ### Deriving a standalone CLI with Smithy4sCli.standalone Source: https://github.com/disneystreaming/smithy4s/blob/series/0.19/modules/docs/resources/markdown/03-protocols/06-deriving-cli.md Wraps the service instance in an Opts and uses Smithy4sCli.standalone to create a Command[IO[Unit]]. The command can be run with CommandIOApp. ```scala import com.monovore.decline._ import smithy4s.decline.Smithy4sCli val serviceWrappedInOpts = Opts(HelloWorldServiceInstance.simple) val helloCommand: Command[IO[Unit]] = Smithy4sCli.standalone(serviceWrappedInOpts).command ```