Add Smithy server code generator for Java, Go, Rust, and C++#960
Closed
Add Smithy server code generator for Java, Go, Rust, and C++#960
Conversation
Adds a comprehensive Smithy server code generator that supports multiple target languages: - Core: Smithy JSON AST parser and model representation - Java: Service interfaces, handlers, routers with CompletableFuture - Go: Interfaces, http.Handler implementations, JSON struct tags - Rust: Async traits, Axum handlers, Serde derives - C++: Abstract classes, nlohmann/json serialization Features: - Generates structures, enums, unions, and error types - HTTP trait support for RESTful APIs - Builder pattern for all structures - Comprehensive test coverage for all generators - Bazel build rules (smithy_java_server, etc.) - Example petstore model https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
Adds WebSocket support as a custom protocol extension to the Smithy server generators for Java, Go, Rust, and C++. New traits (smithy.ws namespace): - @websocket: Marks a service as WebSocket-based - @Onconnect: Handler for connection establishment - @onDisconnect: Handler for connection termination - @OnMessage: Handler for incoming messages with route parameter - @subscribe/@publish: For pub/sub patterns Core changes: - Service.isWebSocket() to detect WebSocket services - Operation WebSocket helpers (isWebSocketConnect, getWebSocketRoute, etc.) - Trait constants for all WebSocket traits Generator updates: - Java: WebSocketHandler with session management, message routing, broadcast - Go: gorilla/websocket handler with session map, broadcast, action routing - Rust: axum WebSocket with tokio broadcast channels, futures streams - C++: Abstract WebSocketSession, handler with mutex-protected sessions Runtime additions (Java): - WebSocketSession interface with test implementation - WebSocketMessage with JSON parsing/serialization - WebSocketHandler interface for lifecycle methods Example: - chat.smithy/chat.json: Real-time chat service with rooms, messages Tests: - Java: WebSocket service detection, handler generation, runtime classes - Go: WebSocket handler generation, message routing, broadcast methods https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
…yed apps Analyzes MoonBase service patterns across Java, Go, Rust, and C++ domains and documents gaps between Smithy-generated code and production features: - Middleware/interceptor chains - gRPC support - OpenTelemetry metrics and tracing - RFC 7807 error handling - Rate limiting - Configuration management - Input validation patterns https://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a comprehensive Smithy server code generator that creates server implementations from AWS Smithy models for multiple languages (Java, Go, Rust, and C++). The implementation includes core model parsing, code generation utilities, and Bazel build rules for seamless integration.
Key Changes
SmithyModel,Service,Operation,Shape,Member, andTraitclasses to represent parsed Smithy models with full support for shapes, operations, traits, and WebSocket operationsCodeGeneratorinterface andCodeWriterutility class for language-agnostic code generation with proper indentation and formatting supportNameUtilsclass with conversion functions (camelCase, PascalCase, snake_case, kebab-case) and keyword escaping for Java, Go, Rust, and C++smithy.bzlwith rules forsmithy_java_server,smithy_go_server,smithy_rust_server, andsmithy_cpp_server, plus a combinedsmithy_servermacro for multi-language generationcore/(model and utilities),generators/(language-specific generators),runtime/(runtime libraries),bazel/(build rules), andexamples/(sample models)Notable Implementation Details
Traitclass provides helper methods for common Smithy traits (HTTP, documentation, validation, WebSocket)CodeWritersupports flexible indentation management with stack-based tracking for nested blocksNameUtilsincludes comprehensive keyword sets for all four target languages to prevent naming conflictshttps://claude.ai/code/session_018zhtbAsziUBuvMXKEkigpo