-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smithy build openapi support (#1492)
This adds support for supplying a `smithy-build.json` during codegen, either by CLI or by either the SBT or Mill plugins. Initially, the only thing in this file that is supported is the OpenAPI plugin, but in future more features can be parsed and handled in codegen if so desired. Docs have been added that explain this.
- Loading branch information
Showing
21 changed files
with
534 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
20 changes: 20 additions & 0 deletions
20
modules/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/build.sbt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
lazy val root = (project in file(".")) | ||
.enablePlugins(Smithy4sCodegenPlugin) | ||
.settings( | ||
scalaVersion := "2.13.13", | ||
libraryDependencies ++= Seq( | ||
"com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value | ||
), | ||
Compile / smithyBuild := Some(baseDirectory.value / "smithy-build.json"), | ||
TaskKey[Unit]("checkOpenApi") := { | ||
val resourceDir = (Compile / smithy4sResourceDir).value | ||
val content = | ||
IO.readLines( | ||
resourceDir / "smithy4s.example.ObjectService.json" | ||
).filter(_.trim().nonEmpty) | ||
.mkString("") | ||
.trim() | ||
if (!content.contains("X-Bar") || !content.contains("3.1.0")) | ||
sys.error("OpenAPI transformation was not applied") | ||
} | ||
) |
1 change: 1 addition & 0 deletions
1
modules/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/project/build.properties
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.8.3 |
9 changes: 9 additions & 0 deletions
9
modules/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/project/plugins.sbt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sys.props.get("plugin.version") match { | ||
case Some(x) => | ||
addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % x) | ||
case _ => | ||
sys.error( | ||
"""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
modules/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/smithy-build.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": "1.0", | ||
"plugins": { | ||
"openapi": { | ||
"service": "smithy4s.example#ObjectService", | ||
"version": "3.1.0", | ||
"substitutions": { | ||
"X-Foo": "X-Bar" | ||
} | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...es/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/src/main/smithy/example.smithy
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
namespace smithy4s.example | ||
|
||
use alloy#simpleRestJson | ||
|
||
@simpleRestJson | ||
service ObjectService { | ||
version: "1.0.0", | ||
operations: [PutObject, GetObject] | ||
} | ||
|
||
|
||
@idempotent | ||
@http(method: "PUT", uri: "/{bucketName}/{key}", code: 200) | ||
operation PutObject { | ||
input: PutObjectInput, | ||
errors: [NoMoreSpace] | ||
} | ||
|
||
@readonly | ||
@http(method: "GET", uri: "/{bucketName}/{key}", code: 200) | ||
operation GetObject { | ||
input: GetObjectInput, | ||
output: GetObjectOutput | ||
} | ||
|
||
structure PutObjectInput { | ||
// Sent in the URI label named "key". | ||
@required | ||
@httpLabel | ||
key: String, | ||
|
||
// Sent in the URI label named "bucketName". | ||
@required | ||
@httpLabel | ||
bucketName: String, | ||
|
||
// Sent in the X-Foo header | ||
@httpHeader("X-Foo") | ||
foo: String, | ||
|
||
// Sent in the query string as paramName | ||
@httpQuery("paramName") | ||
someValue: String, | ||
|
||
// Sent in the body | ||
@httpPayload | ||
@required | ||
data: String | ||
} | ||
|
||
structure GetObjectInput { | ||
// Sent in the URI label named "key". | ||
@required | ||
@httpLabel | ||
key: String, | ||
|
||
// Sent in the URI label named "bucketName". | ||
@required | ||
@httpLabel | ||
bucketName: String, | ||
} | ||
|
||
structure GetObjectOutput { | ||
@httpHeader("X-Size") | ||
@required | ||
size: Integer, | ||
@httpPayload | ||
data: String | ||
} | ||
|
||
union Foo { | ||
int: Integer, | ||
str: String | ||
} | ||
|
||
@error("server") | ||
@httpError(507) | ||
structure NoMoreSpace { | ||
@required | ||
message: String, | ||
foo: Foo | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
modules/codegen-plugin/src/sbt-test/codegen-plugin/smithy-build/test
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# check if smithy4sCodegen works | ||
> compile | ||
$ exists target/scala-2.13/src_managed/main/scala/smithy4s/example/ObjectService.scala | ||
$ exists target/scala-2.13/resource_managed/main/smithy4s.example.ObjectService.json | ||
> checkOpenApi |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.