Skip to content

Commit

Permalink
Expose UrlForm.parse and UrlFormDecodeError (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
BalmungSan authored Oct 10, 2023
1 parent 9a46b36 commit 410478e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ In 0.18.0, support was added for [open enums](https://disneystreaming.github.io/
This model-preprocessor aims at removing constraints from output types in AWS specs (as AWS doesn't seem to respect said constraints)
https://github.com/disneystreaming/smithy4s/pull/1251

## Expose UrlForm.parse and UrlFormDecodeError

In 0.18.0, support was added for `application/x-www-form-urlencoded` data. But, many of its related constructs were private, they are now public for users to access them directly.
https://github.com/disneystreaming/smithy4s/pull/1254

# 0.18.0

## Behavioural changes
Expand Down
11 changes: 8 additions & 3 deletions modules/core/src/smithy4s/http/UrlForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import java.nio.charset.StandardCharsets
import scala.collection.immutable.BitSet
import scala.collection.mutable

/** Represents data that was encoded using the `application/x-www-form-urlencoded` format. */
final case class UrlForm(values: List[UrlForm.FormData]) {

def render: String = {
Expand Down Expand Up @@ -80,10 +81,11 @@ object UrlForm {
}
}

// This is based on http4s' own equivalent, but simplified for our use case.
private[smithy4s] def parse(
/** Parses a `application/x-www-form-urlencoded` formatted String into a [[UrlForm]]. */
def parse(
urlFormString: String
): Either[UrlFormDecodeError, UrlForm] = {
// This is based on http4s' own equivalent, but simplified for our use case.
val inputBuffer = CharBuffer.wrap(urlFormString)
val encodedTermBuilder = new StringBuilder(capacity = 32)
val outputBuilder = List.newBuilder[UrlForm.FormData]
Expand Down Expand Up @@ -163,6 +165,8 @@ object UrlForm {
smithy4s.codecs.Decoder[Either[UrlFormDecodeError, *], UrlForm, A]

object Decoder {

/** Constructs a [[Decoder]] that decodes [[UrlForm]]s into custom data. Can be configured using `@alloyurlformname`. */
def apply(
ignoreUrlFormFlattened: Boolean,
capitalizeStructAndUnionMemberNames: Boolean
Expand Down Expand Up @@ -190,6 +194,8 @@ object UrlForm {
type Encoder[A] = smithy4s.codecs.Encoder[UrlForm, A]

object Encoder {

/** Constructs an [[Encoder]] that encodes data as [[UrlForm]]s. Can be configured using `@alloyurlformname`. */
def apply(
capitalizeStructAndUnionMemberNames: Boolean
): CachedSchemaCompiler[Encoder] =
Expand Down Expand Up @@ -219,6 +225,5 @@ object UrlForm {

}
}

}
}
2 changes: 1 addition & 1 deletion modules/core/src/smithy4s/http/UrlFormDecodeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package http
import smithy4s.codecs.PayloadPath
import smithy4s.http.internals.UrlFormCursor

private[http] final case class UrlFormDecodeError(
final case class UrlFormDecodeError(
path: PayloadPath,
message: String
) extends Throwable {
Expand Down

0 comments on commit 410478e

Please sign in to comment.