-
Notifications
You must be signed in to change notification settings - Fork 422
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 #2104 from softwaremill/scala-native
Support scala native
- Loading branch information
Showing
17 changed files
with
306 additions
and
148 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
10 changes: 10 additions & 0 deletions
10
core/src/main/scalanative/sttp/tapir/CodecExtensions.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,10 @@ | ||
package sttp.tapir | ||
|
||
import sttp.tapir.Codec.fileRange | ||
import sttp.tapir.CodecFormat.OctetStream | ||
|
||
import java.nio.file.Path | ||
|
||
trait CodecExtensions { | ||
implicit lazy val path: Codec[FileRange, Path, OctetStream] = fileRange.map(d => d.file.toPath)(e => FileRange(e.toFile)) | ||
} |
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,8 @@ | ||
package sttp.tapir | ||
|
||
import java.io.File | ||
|
||
object Defaults { | ||
def createTempFile: () => TapirFile = () => File.createTempFile("tapir", "tmp") | ||
def deleteFile(): TapirFile => Unit = file => file.delete() | ||
} |
12 changes: 12 additions & 0 deletions
12
core/src/main/scalanative/sttp/tapir/TapirExtensions.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,12 @@ | ||
package sttp.tapir | ||
|
||
import java.nio.file.Path | ||
|
||
trait TapirExtensions { | ||
type TapirFile = java.io.File | ||
def pathBody: EndpointIO.Body[FileRange, Path] = binaryBody(RawBodyType.FileBody)[Path] | ||
} | ||
|
||
object TapirFile { | ||
def name(f: TapirFile): String = f.getName | ||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/scalanative/sttp/tapir/internal/UrlencodedData.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 sttp.tapir.internal | ||
|
||
import sttp.model.internal.Rfc3986 | ||
|
||
import java.net.{URLDecoder, URLEncoder} | ||
import java.nio.charset.Charset | ||
|
||
private[tapir] object UrlencodedData { | ||
def decode(s: String, charset: Charset): Seq[(String, String)] = { | ||
s.split("&") | ||
.toList | ||
.flatMap(kv => | ||
kv.split("=", 2) match { | ||
case Array(k, v) => | ||
Some((URLDecoder.decode(k, charset.toString), URLDecoder.decode(v, charset.toString))) | ||
case _ => None | ||
} | ||
) | ||
} | ||
|
||
def encode(s: Seq[(String, String)], charset: Charset): String = { | ||
s.map { case (k, v) => | ||
s"${URLEncoder.encode(k, charset.toString)}=${URLEncoder.encode(v, charset.toString)}" | ||
}.mkString("&") | ||
} | ||
|
||
def encode(s: String): String = { | ||
URLEncoder.encode(s, "UTF-8") | ||
} | ||
|
||
def encodePathSegment(s: String): String = { | ||
Rfc3986.encode(Rfc3986.PathSegment)(s) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
core/src/main/scalanative/sttp/tapir/static/TapirStaticContentEndpoints.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,3 @@ | ||
package sttp.tapir.static | ||
|
||
trait TapirStaticContentEndpoints |
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.