Skip to content

Commit

Permalink
Merge pull request #1052 from disneystreaming/remove-reserved-types
Browse files Browse the repository at this point in the history
Remove reserved types
  • Loading branch information
Baccata committed Jul 24, 2023
2 parents b6d3e0a + f042dd4 commit 56f64c3
Show file tree
Hide file tree
Showing 29 changed files with 1,069 additions and 113 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ lazy val example = projectMatrix
"smithy4s.example.imp",
"smithy4s.example.error",
"smithy4s.example.common",
"smithy4s.example.collision"
"smithy4s.example.collision",
"smithy4s.example.reservedNameOverride",
),
smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "example.smithy",
Expand All @@ -825,7 +826,8 @@ lazy val example = projectMatrix
(ThisBuild / baseDirectory).value / "sampleSpecs" / "mixins.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "defaults.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "quoted_string.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "numeric.smithy"
(ThisBuild / baseDirectory).value / "sampleSpecs" / "numeric.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "reservedNameOverride.smithy",
),
Compile / resourceDirectory := (ThisBuild / baseDirectory).value / "modules" / "example" / "resources",
isCE3 := true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lazy val root = (project in file("."))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
scalaVersion := "2.13.10",
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %% "smithy4s-aws-kernel" % smithy4sVersion.value
),
Compile / smithy4sOutputDir := baseDirectory.value / "smithy_output"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.8.2
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
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2021-2022 Disney Streaming
*
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://disneystreaming.github.io/TOST-1.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.amazonaws.dynamodb.DescribeEndpointsResponse
import com.amazonaws.dynamodb.Endpoint
import com.amazonaws.dynamodb.ListTablesInput
import com.amazonaws.dynamodb.ListTablesInputLimit
import com.amazonaws.dynamodb.TableName

object Main extends App {

val listTablesInput = new ListTablesInput(
// TableName is not flattened because it has
// @length and @pattern traits applied
exclusiveStartTableName = Some(TableName("example-table-name")),

// ListTablesInputLimit is not flattened because it has
// a @range constraint
limit = Some(ListTablesInputLimit(5))
)

val describeEndpointsResponse = List(
Endpoint(
// Endpoint address was flattened from a com.amazonaws.dynamodb#String
// to a standard String shape
address = "example-endpoint",

// CachePeriodInMinutes was flattened from a com.amazonaws.dynamodb#Long
// to a standard long
cachePeriodInMinutes = 5L
)
)


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
{
"smithy": "2.0",
"shapes": {
"com.amazonaws.dynamodb#DynamoDB_20120810": {
"type": "service",
"version": "2012-08-10",
"operations": [
{
"target": "com.amazonaws.dynamodb#DescribeEndpoints"
},
{
"target": "com.amazonaws.dynamodb#ListTables"
}
],
"traits": {
"aws.api#clientEndpointDiscovery": {
"operation": "com.amazonaws.dynamodb#DescribeEndpoints",
"error": "com.amazonaws.dynamodb#InvalidEndpointException"
},
"aws.api#service": {
"sdkId": "DynamoDB",
"arnNamespace": "dynamodb",
"cloudFormationName": "DynamoDB",
"cloudTrailEventSource": "dynamodb.amazonaws.com",
"endpointPrefix": "dynamodb"
},
"aws.auth#sigv4": {
"name": "dynamodb"
},
"aws.protocols#awsJson1_0": {},
"smithy.api#documentation": "<fullname>Amazon DynamoDB</fullname>\n\n\n <p>Amazon DynamoDB is a fully managed NoSQL database service that provides fast and\n predictable performance with seamless scalability. DynamoDB lets you offload the\n administrative burdens of operating and scaling a distributed database, so that you don't have\n to worry about hardware provisioning, setup and configuration, replication, software patching,\n or cluster scaling.</p>\n\n <p>With DynamoDB, you can create database tables that can store and retrieve any amount of\n data, and serve any level of request traffic. You can scale up or scale down your tables'\n throughput capacity without downtime or performance degradation, and use the AWS Management\n Console to monitor resource utilization and performance metrics.</p>\n\n <p>DynamoDB automatically spreads the data and traffic for your tables over a sufficient\n number of servers to handle your throughput and storage requirements, while maintaining\n consistent and fast performance. All of your data is stored on solid state disks (SSDs) and\n automatically replicated across multiple Availability Zones in an AWS region, providing\n built-in high availability and data durability. </p>",
"smithy.api#title": "Amazon DynamoDB",
"smithy.api#xmlNamespace": {
"uri": "http://dynamodb.amazonaws.com/doc/2012-08-10/"
}
}
},
"com.amazonaws.dynamodb#DescribeEndpoints": {
"type": "operation",
"input": {
"target": "com.amazonaws.dynamodb#DescribeEndpointsRequest"
},
"output": {
"target": "com.amazonaws.dynamodb#DescribeEndpointsResponse"
},
"traits": {
"smithy.api#documentation": "<p>Returns the regional endpoint information.</p>"
}
},
"com.amazonaws.dynamodb#DescribeEndpointsRequest": {
"type": "structure",
"members": {}
},
"com.amazonaws.dynamodb#DescribeEndpointsResponse": {
"type": "structure",
"members": {
"Endpoints": {
"target": "com.amazonaws.dynamodb#Endpoints",
"traits": {
"smithy.api#documentation": "<p>List of endpoints.</p>",
"smithy.api#required": {}
}
}
}
},
"com.amazonaws.dynamodb#Endpoint": {
"type": "structure",
"members": {
"Address": {
"target": "com.amazonaws.dynamodb#String",
"traits": {
"smithy.api#documentation": "<p>IP address of the endpoint.</p>",
"smithy.api#required": {}
}
},
"CachePeriodInMinutes": {
"target": "com.amazonaws.dynamodb#Long",
"traits": {
"smithy.api#default": 0,
"smithy.api#documentation": "<p>Endpoint cache time to live (TTL) value.</p>",
"smithy.api#required": {}
}
}
},
"traits": {
"smithy.api#documentation": "<p>An endpoint information details.</p>"
}
},
"com.amazonaws.dynamodb#Endpoints": {
"type": "list",
"member": {
"target": "com.amazonaws.dynamodb#Endpoint"
}
},
"com.amazonaws.dynamodb#Long": {
"type": "long",
"traits": {
"smithy.api#default": 0
}
},
"com.amazonaws.dynamodb#ErrorMessage": {
"type": "string"
},
"com.amazonaws.dynamodb#InternalServerError": {
"type": "structure",
"members": {
"message": {
"target": "com.amazonaws.dynamodb#ErrorMessage",
"traits": {
"smithy.api#documentation": "<p>The server encountered an internal error trying to fulfill the request.</p>"
}
}
},
"traits": {
"smithy.api#documentation": "<p>An error occurred on the server side.</p>",
"smithy.api#error": "server"
}
},
"com.amazonaws.dynamodb#InvalidEndpointException": {
"type": "structure",
"members": {
"Message": {
"target": "com.amazonaws.dynamodb#String"
}
},
"traits": {
"smithy.api#error": "client",
"smithy.api#httpError": 421
}
},
"com.amazonaws.dynamodb#ListTables": {
"type": "operation",
"input": {
"target": "com.amazonaws.dynamodb#ListTablesInput"
},
"output": {
"target": "com.amazonaws.dynamodb#ListTablesOutput"
},
"errors": [
{
"target": "com.amazonaws.dynamodb#InternalServerError"
},
{
"target": "com.amazonaws.dynamodb#InvalidEndpointException"
}
],
"traits": {
"aws.api#clientDiscoveredEndpoint": {
"required": false
},
"smithy.api#documentation": "<p>Returns an array of table names associated with the current account and endpoint. The output\n from <code>ListTables</code> is paginated, with each page returning a maximum of 100 table\n names.</p>",
"smithy.api#paginated": {
"inputToken": "ExclusiveStartTableName",
"outputToken": "LastEvaluatedTableName",
"items": "TableNames",
"pageSize": "Limit"
}
}
},
"com.amazonaws.dynamodb#ListTablesInput": {
"type": "structure",
"members": {
"ExclusiveStartTableName": {
"target": "com.amazonaws.dynamodb#TableName",
"traits": {
"smithy.api#documentation": "<p>The first table name that this operation will evaluate. Use the value that was returned for\n <code>LastEvaluatedTableName</code> in a previous operation, so that you can obtain the next page\n of results.</p>"
}
},
"Limit": {
"target": "com.amazonaws.dynamodb#ListTablesInputLimit",
"traits": {
"smithy.api#documentation": "<p>A maximum number of table names to return. If this parameter is not specified, the limit is 100.</p>"
}
}
},
"traits": {
"smithy.api#documentation": "<p>Represents the input of a <code>ListTables</code> operation.</p>"
}
},
"com.amazonaws.dynamodb#ListTablesInputLimit": {
"type": "integer",
"traits": {
"smithy.api#range": {
"min": 1,
"max": 100
}
}
},
"com.amazonaws.dynamodb#ListTablesOutput": {
"type": "structure",
"members": {
"TableNames": {
"target": "com.amazonaws.dynamodb#TableNameList",
"traits": {
"smithy.api#documentation": "<p>The names of the tables associated with the current account at the current endpoint. The maximum size of this array is 100.</p>\n <p>If <code>LastEvaluatedTableName</code> also appears in the output, you can use this value as the\n <code>ExclusiveStartTableName</code> parameter in a subsequent <code>ListTables</code> request and\n obtain the next page of results.</p>"
}
},
"LastEvaluatedTableName": {
"target": "com.amazonaws.dynamodb#TableName",
"traits": {
"smithy.api#documentation": "<p>The name of the last table in the current page of results. Use this value as the\n <code>ExclusiveStartTableName</code> in a new request to obtain the next page of results, until\n all the table names are returned.</p>\n <p>If you do not receive a <code>LastEvaluatedTableName</code> value in the response, this means that\n there are no more table names to be retrieved.</p>"
}
}
},
"traits": {
"smithy.api#documentation": "<p>Represents the output of a <code>ListTables</code> operation.</p>"
}
},
"com.amazonaws.dynamodb#String": {
"type": "string"
},
"com.amazonaws.dynamodb#TableName": {
"type": "string",
"traits": {
"smithy.api#length": {
"min": 3,
"max": 255
},
"smithy.api#pattern": "^[a-zA-Z0-9_.-]+$"
}
},
"com.amazonaws.dynamodb#TableNameList": {
"type": "list",
"member": {
"target": "com.amazonaws.dynamodb#TableName"
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# check if smithy4sCodegen works
> compile

# This new type was not flattened because it has range constraints
$ exists smithy_output/com/amazonaws/dynamodb/ListTablesInputLimit.scala

# Flattened and removed by the projection transformer
-$ exists smithy_output/com/amazonaws/dynamodb/Long.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
smithy4s.codegen.transformers.AwsStandardTypesTransformer
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package smithy4s.codegen
package internals

import alloy.openapi._
import smithy4s.codegen.transformers.AwsStandardTypesTransformer
import software.amazon.smithy.model.Model

import scala.jdk.CollectionConverters._
Expand All @@ -34,7 +35,7 @@ private[codegen] object CodegenImpl { self =>
args.specs.map(_.toIO).toSet,
args.dependencies,
args.repositories,
args.transformers,
withAwsTypeTransformer(args.transformers),
args.discoverModels,
args.localJars
)
Expand Down Expand Up @@ -148,12 +149,15 @@ private[codegen] object CodegenImpl { self =>
args.specs.map(_.toIO).toSet,
args.dependencies,
args.repositories,
args.transformers,
withAwsTypeTransformer(args.transformers),
discoverModels = false,
args.localJars
)

Node.prettyPrintJson(ModelSerializer.builder().build.serialize(model))
}

private def withAwsTypeTransformer(transformers: List[String]): List[String] =
transformers :+ AwsStandardTypesTransformer.name

}
Loading

0 comments on commit 56f64c3

Please sign in to comment.