Skip to content

Commit 3fffff6

Browse files
authored
Add Smithy IDL code generator (#1522) (#3898)
* Smithy parser impl (#1522) * Add Smithy code generator for zio-http Endpoints Implement SmithyEndpointGen that generates zio-http Endpoint definitions from Smithy IDL models. This complements the Smithy parser added in the previous commit. Features: - Generate case classes from Smithy structure shapes - Generate sealed traits from union shapes - Generate enums from enum shapes - Generate Endpoint definitions from operations with @http traits - Support for path parameters (@httpLabel) - Support for query parameters (@httpQuery) - Support for header bindings (@HTTPHeader) - Support for request/response body (@httpPayload) - Comprehensive type mapping from Smithy to Scala types Tests: 22 Smithy-specific tests (14 parser + 8 generator) All 110 zio-http-gen tests pass. * Add filesystem support for Smithy code generation Add convenience methods to read and process Smithy files: - fromString: Parse Smithy IDL string and generate code - fromFile: Read a single .smithy file and generate code - fromDirectory: Read all .smithy files from a directory - generate: Full pipeline from source dir to target dir - generateFromFile: Full pipeline from single file to target dir - mergeModels: Combine multiple SmithyModels into one This allows users to easily integrate Smithy code generation into their build process by pointing to a directory of .smithy files. * Add streaming, documentation, and auth trait support Enhance the Smithy code generator with additional features: Parser improvements: - Add @streaming trait for streaming blob payloads - Add @eventstream trait for event streams - Add auth traits (@httpBasicAuth, @httpDigestAuth, @httpBearerAuth, @httpApiKeyAuth, @auth) - Parse /// doc comments as @documentation traits Code generation improvements: - Detect streaming inputs/outputs and set streaming flag - Extract documentation from @documentation traits - Use @mediaType trait when available - Include error documentation in generated endpoints Tests: 29 Smithy-specific tests, 117 total zio-http-gen tests * Add comprehensive Smithy model validation Add SmithyValidation module with: - Shape reference validation (undefined references) - HTTP trait validation (methods, status codes, path params) - Constraint trait validation (@Length, @range, @pattern) - Operation validation (input/output must be structures) - Service validation (operations, resources, version) - Enum and union validation (non-empty, no duplicates) - 40 new validation tests Integrate validation into SmithyEndpointGen with optional validate parameter for all generation methods. * Add SmithyConfig for code generation options - Create SmithyConfig with field normalization enabled by default - Update SmithyEndpointGen to accept and use SmithyConfig - Add config options: validation, companion objects, endpoints object, etc. - Add 7 tests for config options (76 total Smithy tests pass) * Format Smithy code with scalafmt (#1522) * Apply sbt fmt (#1522) * Fix unmoored doc comment in Smithy parser (#1522) * Add comprehensive .smithy example files and tests (#1522) Add three real-world Smithy IDL example files covering: - Pet store API with CRUD operations, pagination, enums, validation - Auth service with bearer tokens, login/logout, user management - Order service with resources, nested types, money, addresses Add tests to parse all example files and verify shape extraction. * Add Alternator support to RichTextCodec | operator (#1522) Enhance RichTextCodec's | operator to use Alternator typeclass, unifying same-type alternatives without nested Either types. This matches the behavior of HttpCodec's | operator. Changes: - RichTextCodec: Use Alternator in | operator for type-unified alternatives - Header.scala: Simplify code by removing unnecessary .transform/.merge - Add SmithyCodecs with primitive codecs demonstrating the enhancement - Add SmithyCodecsSpec with 30 tests for the primitive codecs * Fix Scala 2.12 compatibility for RichTextCodec | operator (#1522) Wrap dependent-type method references in explicit lambdas for Scala 2.12 compatibility. Add MIMA exclusion for the | method signature change. * Fix scaladoc error by escaping $ in doc comment (#1522) * Remove unused zio-parser dependency (#1522)
1 parent db58f27 commit 3fffff6

File tree

20 files changed

+6084
-14
lines changed

20 files changed

+6084
-14
lines changed

project/Dependencies.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ object Dependencies {
77
val ZioVersion = "2.1.23"
88
val ZioCliVersion = "0.7.3"
99
val ZioJsonVersion = "0.7.45"
10-
val ZioParserVersion = "0.1.10"
1110
val ZioSchemaVersion = "1.7.5"
1211
val SttpVersion = "3.3.18"
1312
val ZioConfigVersion = "4.0.5"

project/MimaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ object MimaSettings {
4343
ProblemFilters.exclude[MissingClassProblem]("zio.http.netty.NettyHeaderEncoding"),
4444
ProblemFilters.exclude[MissingClassProblem]("zio.http.netty.NettyHeaderEncoding$"),
4545
exclude[Problem]("zio.http.template2.*"),
46+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.codec.RichTextCodec.|")
4647
),
4748
mimaFailOnProblem := failOnProblem,
4849
)

0 commit comments

Comments
 (0)