Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline io for examples #61

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 34 additions & 53 deletions conversion-examples/smithy-to-openapi/models/city.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,57 @@ $version: "2.0"
namespace smithy.example

resource City {
identifiers: { cityId: CityId }
properties: {
coordinates: CityCoordinates
name: String
}
identifiers: {cityId: CityId}
properties: {coordinates: CityCoordinates, name: String}
read: GetCity
create: CreateCity
resources: [Forecast]
}

@readonly
@http(
method: "GET",
uri: "/city/{cityId}"
)
@http(method: "GET", uri: "/city/{cityId}")
operation GetCity {
input: GetCityInput,
output: GetCityOutput,
errors: [NoSuchResource]
}
input := for City {
@required
@httpLabel
$cityId
}

@input
structure GetCityInput for City {
// "cityId" provides the identifier for the resource and
// has to be marked as required.
@required
@httpLabel
$cityId
}
output := for City {
// "required" is used on output to indicate if the service
// will always provide a value for the member.
@required
$name

structure GetCityOutput for City {
// "required" is used on output to indicate if the service
// will always provide a value for the member.
@required
$name
@required
$coordinates
}

@required
$coordinates
errors: [
NoSuchResource
]
}

@http(
method: "POST",
uri: "/city"
)
@http(method: "POST", uri: "/city")
operation CreateCity {
input: CreateCityInput,
output: CreateCityOutput
}

@input
structure CreateCityInput for City {
@required
$name
input := for City {
@required
$name

@required
$coordinates
}
@required
$coordinates
}

@output
structure CreateCityOutput for City {
@required
$cityId
output := for City {
@required
$cityId

@required
$name
@required
$name

@required
$coordinates
@required
$coordinates
}
}

// "pattern" is a trait that constrains the string value
Expand All @@ -84,5 +67,3 @@ structure CityCoordinates {
@required
longitude: Float
}


4 changes: 0 additions & 4 deletions conversion-examples/smithy-to-openapi/models/errors.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ $version: "2.0"

namespace smithy.example


// "error" is a trait that is used to specialize
// a structure as an error.
@error("client")
Expand All @@ -26,6 +25,3 @@ structure ServiceError {
@required
message: String
}



34 changes: 11 additions & 23 deletions conversion-examples/smithy-to-openapi/models/examples/city.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,34 @@ namespace smithy.example
// In Smithy, example values of input structure members and the
// corresponding output or error structure members for an operation
// are grouped together into one set of example values for an operation.

apply GetCity @examples(
[
{
title: "Get City Example",
documentation: "Gets a city with the ID 1234",
input: {
cityId: "1234"
},
title: "Get City Example"
documentation: "Gets a city with the ID 1234"
input: {cityId: "1234"}
output: {
name: "Seattle"
coordinates: {
latitude: 47.6,
longitude: 122.3
}
},
coordinates: {latitude: 47.6, longitude: 122.3}
}
}
]
)

apply CreateCity @examples(
[
{
title: "Create City Example",
documentation: "An example that creates a City Called Seattle",
title: "Create City Example"
documentation: "An example that creates a City Called Seattle"
input: {
name: "Seattle"
coordinates: {
latitude: 47.6,
longitude: 122.3
}
},
coordinates: {latitude: 47.6, longitude: 122.3}
}
output: {
cityId: "1234"
name: "Seattle"
coordinates: {
latitude: 47.6,
longitude: 122.3
}
},
coordinates: {latitude: 47.6, longitude: 122.3}
}
}
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ $version: "2.0"
namespace smithy.example

apply GetForecast @examples(
[
{
title: "Create City Example",
documentation: "An example that creates a City Called Seattle",
input: {
cityId: "1234"
},
output: {
rating: "SOMEWHAT_HAPPY",
forecast: {
"rain": 12.0
[
{
title: "Create City Example"
documentation: "An example that creates a City Called Seattle"
input: {cityId: "1234"}
output: {
rating: "SOMEWHAT_HAPPY"
forecast: {rain: 12.0}
}
},
}
]
}
]
)
46 changes: 18 additions & 28 deletions conversion-examples/smithy-to-openapi/models/forecast.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,38 @@ $version: "2.0"
namespace smithy.example

resource Forecast {
identifiers: { cityId: CityId },
read: GetForecast,
identifiers: {cityId: CityId}
read: GetForecast
}

@readonly
@http(
method: "GET",
uri: "/city/{cityId}/forecast"
)
@http(method: "GET", uri: "/city/{cityId}/forecast")
operation GetForecast {
input: GetForecastInput
output: GetForecastOutput
}

// "cityId" provides the only identifier for the resource since
// a Forecast doesn't have its own.
@input
structure GetForecastInput for Forecast{
@required
@httpLabel
$cityId
}

@output
structure GetForecastOutput {
rating: Rating
forecast: ForecastResult
input := for Forecast {
@required
@httpLabel
$cityId
}

output := {
rating: Rating
forecast: ForecastResult
}
}

/// How happy do we expect this forecast to make you
enum Rating {
SUPER_HAPPY,
SOMEWHAT_HAPPY,
MEH,
NOT_SO_HAPPY,
SUPER_HAPPY
SOMEWHAT_HAPPY
MEH
NOT_SO_HAPPY
UNHAPPY
}

// Unions represent a `one-of` relationship. The forecast could be
// either `rain` with a float value or `sun` with an integer value
union ForecastResult {
rain: ChanceOfRain,
rain: ChanceOfRain
sun: UVIndex
}

Expand Down
21 changes: 6 additions & 15 deletions conversion-examples/smithy-to-openapi/models/weather.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace smithy.example
use aws.protocols#restJson1

/// Provides weather forecasts
@paginated(inputToken: "nextToken", outputToken: "nextToken",
pageSize: "pageSize")
@paginated(inputToken: "nextToken", outputToken: "nextToken", pageSize: "pageSize")
@restJson1
@title("Weather Service")
service Weather {
Expand All @@ -18,18 +17,10 @@ service Weather {
}

@readonly
@http(
method: "GET",
uri: "/current-time"
)
@http(method: "GET", uri: "/current-time")
operation GetCurrentTime {
output: GetCurrentTimeOutput
output := {
@required
time: Timestamp
}
}

structure GetCurrentTimeOutput {
@required
time: Timestamp
}



Loading