-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1213 from disneystreaming/endpoint-host-label
Endpoint Host Prefix
- Loading branch information
Showing
18 changed files
with
487 additions
and
33 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
21 changes: 0 additions & 21 deletions
21
modules/bootstrapped/src/generated/smithy4s/example/HeadRequestOutput.scala
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
modules/bootstrapped/src/generated/smithy4s/example/HostLabelEnum.scala
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,34 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Enumeration | ||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.EnumTag | ||
import smithy4s.schema.Schema.enumeration | ||
|
||
sealed abstract class HostLabelEnum(_value: String, _name: String, _intValue: Int, _hints: Hints) extends Enumeration.Value { | ||
override type EnumType = HostLabelEnum | ||
override val value: String = _value | ||
override val name: String = _name | ||
override val intValue: Int = _intValue | ||
override val hints: Hints = _hints | ||
override def enumeration: Enumeration[EnumType] = HostLabelEnum | ||
@inline final def widen: HostLabelEnum = this | ||
} | ||
object HostLabelEnum extends Enumeration[HostLabelEnum] with ShapeTag.Companion[HostLabelEnum] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "HostLabelEnum") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
case object THING1 extends HostLabelEnum("THING1", "THING1", 0, Hints()) | ||
case object THING2 extends HostLabelEnum("THING2", "THING2", 1, Hints()) | ||
|
||
val values: List[HostLabelEnum] = List( | ||
THING1, | ||
THING2, | ||
) | ||
val tag: EnumTag[HostLabelEnum] = EnumTag.ClosedStringEnum | ||
implicit val schema: Schema[HostLabelEnum] = enumeration(tag, values).withId(id).addHints(hints) | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/bootstrapped/src/generated/smithy4s/example/HostLabelInput.scala
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,23 @@ | ||
package smithy4s.example | ||
|
||
import smithy4s.Hints | ||
import smithy4s.Schema | ||
import smithy4s.ShapeId | ||
import smithy4s.ShapeTag | ||
import smithy4s.schema.Schema.string | ||
import smithy4s.schema.Schema.struct | ||
|
||
final case class HostLabelInput(label1: String, label2: String, label3: HostLabelEnum) | ||
object HostLabelInput extends ShapeTag.Companion[HostLabelInput] { | ||
val id: ShapeId = ShapeId("smithy4s.example", "HostLabelInput") | ||
|
||
val hints: Hints = Hints.empty | ||
|
||
implicit val schema: Schema[HostLabelInput] = struct( | ||
string.required[HostLabelInput]("label1", _.label1).addHints(smithy.api.HostLabel()), | ||
string.required[HostLabelInput]("label2", _.label2).addHints(smithy.api.HostLabel()), | ||
HostLabelEnum.schema.required[HostLabelInput]("label3", _.label3).addHints(smithy.api.HostLabel()), | ||
){ | ||
HostLabelInput.apply | ||
}.withId(id).addHints(hints) | ||
} |
52 changes: 52 additions & 0 deletions
52
modules/bootstrapped/test/src/smithy4s/http/HostPrefixSpec.scala
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,52 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package smithy4s | ||
package http | ||
|
||
import smithy4s.example.DummyServiceOperation.DummyHostPrefix | ||
import smithy4s.example.HostLabelInput | ||
import internals.HostPrefixSegment | ||
|
||
class HostPrefixSpec() extends munit.FunSuite { | ||
|
||
test("Parse host prefix pattern into host prefix segments") { | ||
val result = internals.hostPrefixSegments("{head}--foo{tail}") | ||
val expected = | ||
Vector( | ||
HostPrefixSegment.label("head"), | ||
HostPrefixSegment.static("--foo"), | ||
HostPrefixSegment.label("tail") | ||
) | ||
expect.same(result, expected) | ||
} | ||
|
||
// "foo.{label1}--abc{label2}.{label3}.secure | ||
test("Write a valid Host Prefix for DummyHostPrefix") { | ||
val injector = HttpHostPrefix(DummyHostPrefix.schema).get | ||
val input = HostLabelInput( | ||
"mabeline", | ||
"virgo", | ||
smithy4s.example.HostLabelEnum.THING1 | ||
) | ||
val result = injector.write(List.empty, input) | ||
|
||
val expected = | ||
"foo." :: "mabeline" :: "--abc" :: "virgo" :: "." :: "THING1" :: ".secure." :: Nil | ||
expect.eql(result, expected) | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
modules/bootstrapped/test/src/smithy4s/http/HttpRequestSpec.scala
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,42 @@ | ||
package smithy4s.http | ||
|
||
import munit._ | ||
import smithy4s.schema.OperationSchema | ||
import smithy4s.schema.Schema | ||
import smithy4s._ | ||
import smithy.api | ||
|
||
final class HttpRequestSpec extends FunSuite { | ||
|
||
test("host prefix") { | ||
case class Foo(foo: String) | ||
val schema = | ||
Schema.struct(Schema.string.required[Foo]("foo", _.foo))(Foo(_)) | ||
val endpointHint = | ||
api.Endpoint(hostPrefix = api.NonEmptyString("test.{foo}-other.")) | ||
val opSchema = OperationSchema( | ||
ShapeId("test", "Test"), | ||
Hints(endpointHint), | ||
schema, | ||
None, | ||
Schema.unit, | ||
None, | ||
None | ||
) | ||
|
||
val writer = HttpRequest.Writer.hostPrefix[String, Foo](opSchema) | ||
|
||
val uri = HttpUri( | ||
HttpUriScheme.Https, | ||
"example.com", | ||
None, | ||
Seq.empty, | ||
Map.empty, | ||
None | ||
) | ||
val request = HttpRequest(HttpMethod.GET, uri, Map.empty, "") | ||
val resultUri = writer.write(request, Foo("hello")).uri | ||
assertEquals(resultUri, uri.copy(host = "test.hello-other.example.com")) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package smithy4s.http | ||
|
||
import smithy4s.http.internals.HostPrefixSchemaVisitor | ||
import smithy4s.codecs.Writer | ||
import smithy4s.schema.OperationSchema | ||
|
||
object HttpHostPrefix { | ||
def apply[I, E, O, SI, SO]( | ||
endpoint: OperationSchema[I, E, O, SI, SO] | ||
): Option[Writer[List[String], I]] = { | ||
for { | ||
endpointHint <- endpoint.hints.get(smithy.api.Endpoint) | ||
hostPrefixEncoder <- HostPrefixSchemaVisitor( | ||
endpoint.input.addHints(endpointHint) | ||
) | ||
} yield hostPrefixEncoder | ||
} | ||
|
||
} |
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.