Skip to content

Commit

Permalink
Make protocol ZSTs match shape ID names (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber authored Oct 17, 2022
1 parent 18d969e commit 55d16b1
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class ServerAwsJsonProtocol(
override fun markerStruct(): RuntimeType {
return when (version) {
is AwsJsonVersion.Json10 -> {
ServerRuntimeType.Protocol("AwsJson10", "aws_json_10", runtimeConfig)
ServerRuntimeType.Protocol("AwsJson1_0", "aws_json_10", runtimeConfig)
}
is AwsJsonVersion.Json11 -> {
ServerRuntimeType.Protocol("AwsJson11", "aws_json_11", runtimeConfig)
ServerRuntimeType.Protocol("AwsJson1_1", "aws_json_11", runtimeConfig)
}
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ class ServerRestJsonProtocol(
fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.codegenContext)
}

override fun markerStruct() = ServerRuntimeType.Protocol("AwsRestJson1", "rest_json_1", runtimeConfig)
override fun markerStruct() = ServerRuntimeType.Protocol("RestJson1", "rest_json_1", runtimeConfig)

override fun routerType() = restRouterType(runtimeConfig)

Expand Down Expand Up @@ -240,7 +240,7 @@ class ServerRestXmlProtocol(
}
}

override fun markerStruct() = ServerRuntimeType.Protocol("AwsRestXml", "rest_xml", runtimeConfig)
override fun markerStruct() = ServerRuntimeType.Protocol("RestXml", "rest_xml", runtimeConfig)

override fun routerType() = restRouterType(runtimeConfig)

Expand Down
6 changes: 3 additions & 3 deletions design/src/rfcs/rfc0020_service_builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub struct Route {
enum Routes {
RestXml(Vec<(Route, RequestSpec)>),
RestJson1(Vec<(Route, RequestSpec)>),
AwsJson10(TinyMap<String, Route>),
AwsJson1_0(TinyMap<String, Route>),
AwsJson11(TinyMap<String, Route>),
}

Expand Down Expand Up @@ -729,8 +729,8 @@ Currently there is a single `Router` structure, described in [Router](#router),
enum Routes {
RestXml(/* Container */),
RestJson1(/* Container */),
AwsJson10(/* Container */),
AwsJson11(/* Container */),
AwsJson1_0(/* Container */),
AwsJson1_1(/* Container */),
}
```

Expand Down
20 changes: 10 additions & 10 deletions design/src/server/anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,16 @@ Note that both traits are parameterized by `Protocol`. These [protocols](https:/

```rust
/// [AWS REST JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restjson1-protocol.html).
pub struct AwsRestJson1;
pub struct RestJson1;

/// [AWS REST XML Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html).
pub struct AwsRestXml;
pub struct RestXml;

/// [AWS JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html).
pub struct AwsJson10;
pub struct AwsJson1_0;

/// [AWS JSON 1.1 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_1-protocol.html).
pub struct AwsJson11;
pub struct AwsJson1_1;
```

## Upgrading a Model Service
Expand Down Expand Up @@ -526,15 +526,15 @@ To finalize the build and construct the complete service, `PokemonService`, each
/// Constructs a [`PokemonService`] from the arguments provided to the builder.
pub fn build(self) -> PokemonService<Route>
where
Op1: Upgradable<AwsRestJson1, CheckHealth>,
Op1: Upgradable<RestJson1, CheckHealth>,
Op1::Service: tower::Service<http::Request, Error = Infallible>,

Op2: Upgradable<AwsRestJson1, DoNothing>,
Op2: Upgradable<RestJson1, DoNothing>,
Op2::Service: tower::Service<http::Request, Error = Infallible>,

/* ... */

Op6: Upgradable<AwsRestJson1, GetStorage>,
Op6: Upgradable<RestJson1, GetStorage>,
Op6::Service: tower::Service<http::Request, Error = Infallible>,
```

Expand Down Expand Up @@ -599,10 +599,10 @@ The build method then proceeds as follows:
/// Constructs a [`PokemonService`] from the arguments provided to the builder.
pub fn build(self) -> PokemonService<Route>
where
Op1: Upgradable<AwsRestJson1, CheckHealth>,
Op1: Upgradable<RestJson1, CheckHealth>,
Op1::Service: tower::Service<http::Request, Error = Infallible>,

Op2: Upgradable<AwsRestJson1, DoNothing>,
Op2: Upgradable<RestJson1, DoNothing>,
Op2::Service: tower::Service<http::Request, Error = Infallible>,

/* ... */
Expand Down Expand Up @@ -630,7 +630,7 @@ where
/// The Pokémon Service allows you to retrieve information about Pokémon species.
#[derive(Clone)]
pub struct PokemonService<S> {
router: RoutingService<RestRouter<S>, AwsRestJson1>,
router: RoutingService<RestRouter<S>, RestJson1>,
}
```

Expand Down
11 changes: 5 additions & 6 deletions rust-runtime/aws-smithy-http-server-python/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use aws_smithy_http_server::{
body::{to_boxed, BoxBody},
proto::{
aws_json_10::AwsJson10, aws_json_11::AwsJson11, rest_json_1::AwsRestJson1,
rest_xml::AwsRestXml,
aws_json_10::AwsJson1_0, aws_json_11::AwsJson1_1, rest_json_1::RestJson1, rest_xml::RestXml,
},
response::IntoResponse,
};
Expand Down Expand Up @@ -68,7 +67,7 @@ impl From<PyErr> for PyMiddlewareException {
}
}

impl IntoResponse<AwsRestJson1> for PyMiddlewareException {
impl IntoResponse<RestJson1> for PyMiddlewareException {
fn into_response(self) -> http::Response<BoxBody> {
http::Response::builder()
.status(self.status_code)
Expand All @@ -79,7 +78,7 @@ impl IntoResponse<AwsRestJson1> for PyMiddlewareException {
}
}

impl IntoResponse<AwsRestXml> for PyMiddlewareException {
impl IntoResponse<RestXml> for PyMiddlewareException {
fn into_response(self) -> http::Response<BoxBody> {
http::Response::builder()
.status(self.status_code)
Expand All @@ -89,7 +88,7 @@ impl IntoResponse<AwsRestXml> for PyMiddlewareException {
}
}

impl IntoResponse<AwsJson10> for PyMiddlewareException {
impl IntoResponse<AwsJson1_0> for PyMiddlewareException {
fn into_response(self) -> http::Response<BoxBody> {
http::Response::builder()
.status(self.status_code)
Expand All @@ -100,7 +99,7 @@ impl IntoResponse<AwsJson10> for PyMiddlewareException {
}
}

impl IntoResponse<AwsJson11> for PyMiddlewareException {
impl IntoResponse<AwsJson1_1> for PyMiddlewareException {
fn into_response(self) -> http::Response<BoxBody> {
http::Response::builder()
.status(self.status_code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl PyMiddlewares {

#[cfg(test)]
mod tests {
use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1;
use aws_smithy_http_server::proto::rest_json_1::RestJson1;
use http::HeaderValue;
use hyper::body::to_bytes;
use pretty_assertions::assert_eq;
Expand All @@ -180,7 +180,7 @@ mod tests {
#[tokio::test]
async fn request_middleware_chain_keeps_headers_changes() -> PyResult<()> {
let locals = crate::tests::initialize();
let mut middlewares = PyMiddlewares::new::<AwsRestJson1>(vec![]);
let mut middlewares = PyMiddlewares::new::<RestJson1>(vec![]);

Python::with_gil(|py| {
let middleware = PyModule::new(py, "middleware").unwrap();
Expand Down Expand Up @@ -230,7 +230,7 @@ def second_middleware(request: Request):
#[tokio::test]
async fn request_middleware_return_response() -> PyResult<()> {
let locals = crate::tests::initialize();
let mut middlewares = PyMiddlewares::new::<AwsRestJson1>(vec![]);
let mut middlewares = PyMiddlewares::new::<RestJson1>(vec![]);

Python::with_gil(|py| {
let middleware = PyModule::new(py, "middleware").unwrap();
Expand Down Expand Up @@ -265,7 +265,7 @@ def middleware(request: Request):
#[tokio::test]
async fn request_middleware_raise_middleware_exception() -> PyResult<()> {
let locals = crate::tests::initialize();
let mut middlewares = PyMiddlewares::new::<AwsRestJson1>(vec![]);
let mut middlewares = PyMiddlewares::new::<RestJson1>(vec![]);

Python::with_gil(|py| {
let middleware = PyModule::new(py, "middleware").unwrap();
Expand Down Expand Up @@ -304,7 +304,7 @@ def middleware(request: Request):
#[tokio::test]
async fn request_middleware_raise_python_exception() -> PyResult<()> {
let locals = crate::tests::initialize();
let mut middlewares = PyMiddlewares::new::<AwsRestJson1>(vec![]);
let mut middlewares = PyMiddlewares::new::<RestJson1>(vec![]);

Python::with_gil(|py| {
let middleware = PyModule::from_code(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod tests {
use super::*;

use aws_smithy_http_server::body::to_boxed;
use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1;
use aws_smithy_http_server::proto::rest_json_1::RestJson1;
use pyo3::prelude::*;
use tower::{Service, ServiceBuilder, ServiceExt};

Expand All @@ -174,7 +174,7 @@ mod tests {
#[tokio::test]
async fn request_middlewares_are_chained_inside_layer() -> PyResult<()> {
let locals = crate::tests::initialize();
let mut middlewares = PyMiddlewares::new::<AwsRestJson1>(vec![]);
let mut middlewares = PyMiddlewares::new::<RestJson1>(vec![]);

Python::with_gil(|py| {
let middleware = PyModule::new(py, "middleware").unwrap();
Expand Down Expand Up @@ -211,7 +211,7 @@ def second_middleware(request: Request):
})?;

let mut service = ServiceBuilder::new()
.layer(PyMiddlewareLayer::<AwsRestJson1>::new(middlewares, locals))
.layer(PyMiddlewareLayer::<RestJson1>::new(middlewares, locals))
.service_fn(echo);

let request = Request::get("/").body(Body::empty()).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pub mod router;

/// [AWS JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html).
pub struct AwsJson10;
pub struct AwsJson1_0;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::proto::aws_json::router::Error;
use crate::response::IntoResponse;
use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION};

use super::AwsJson10;
use super::AwsJson1_0;

pub use crate::proto::aws_json::router::*;

impl IntoResponse<AwsJson10> for Error {
impl IntoResponse<AwsJson1_0> for Error {
fn into_response(self) -> http::Response<BoxBody> {
match self {
Error::MethodNotAllowed => method_disallowed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pub mod router;

/// [AWS JSON 1.1 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_1-protocol.html).
pub struct AwsJson11;
pub struct AwsJson1_1;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::proto::aws_json::router::Error;
use crate::response::IntoResponse;
use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION};

use super::AwsJson11;
use super::AwsJson1_1;

pub use crate::proto::aws_json::router::*;

impl IntoResponse<AwsJson11> for Error {
impl IntoResponse<AwsJson1_1> for Error {
fn into_response(self) -> http::Response<BoxBody> {
match self {
Error::MethodNotAllowed => method_disallowed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pub mod router;

/// [AWS REST JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restjson1-protocol.html).
pub struct AwsRestJson1;
pub struct RestJson1;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::proto::rest::router::Error;
use crate::response::IntoResponse;
use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION};

use super::AwsRestJson1;
use super::RestJson1;

pub use crate::proto::rest::router::*;

impl IntoResponse<AwsRestJson1> for Error {
impl IntoResponse<RestJson1> for Error {
fn into_response(self) -> http::Response<BoxBody> {
match self {
Error::NotFound => http::Response::builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pub mod router;

/// [AWS REST XML Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html).
pub struct AwsRestXml;
pub struct RestXml;
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::response::IntoResponse;
use crate::routers::method_disallowed;
use crate::routers::UNKNOWN_OPERATION_EXCEPTION;

use super::AwsRestXml;
use super::RestXml;

pub use crate::proto::rest::router::*;

/// An AWS REST routing error.
impl IntoResponse<AwsRestXml> for Error {
impl IntoResponse<RestXml> for Error {
fn into_response(self) -> http::Response<BoxBody> {
match self {
Error::NotFound => http::Response::builder()
Expand All @@ -26,7 +26,7 @@ impl IntoResponse<AwsRestXml> for Error {
UNKNOWN_OPERATION_EXCEPTION.to_string(),
))
.body(empty())
.expect("invalid HTTP response for REST JSON routing error; please file a bug report under https://github.com/awslabs/smithy-rs/issues"),
.expect("invalid HTTP response for REST XML routing error; please file a bug report under https://github.com/awslabs/smithy-rs/issues"),
Error::MethodNotAllowed => method_disallowed(),
}
}
Expand Down
Loading

0 comments on commit 55d16b1

Please sign in to comment.