Skip to content

Commit

Permalink
Release 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Sep 7, 2022
1 parent 8c886de commit 947b2c8
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ tapir documentation is available at [tapir.softwaremill.com](http://tapir.softwa
Add the following dependency:

```sbt
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.1.0"
```

Then, import:
Expand Down
4 changes: 2 additions & 2 deletions doc/docs/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ these steps can be done separately, giving you complete control over the process
To generate OpenAPI documentation and expose it using the Swagger UI in a single step, first add the dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % "1.1.0"
```

Then, you can interpret a list of endpoints using `SwaggerInterpreter`. The result will be a list of file-serving
Expand Down Expand Up @@ -55,7 +55,7 @@ for details.
Similarly as above, you'll need the following dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-redoc-bundle" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-redoc-bundle" % "1.1.0"
```

And the server endpoints can be generated using the `sttp.tapir.redoc.bundle.RedocInterpreter` class.
Expand Down
2 changes: 1 addition & 1 deletion generated-doc/out/client/http4s.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-http4s-client" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-http4s-client" % "1.1.0"
```

To interpret an endpoint definition as an `org.http4s.Request[F]`, import:
Expand Down
2 changes: 1 addition & 1 deletion generated-doc/out/client/play.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-play-client" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-play-client" % "1.1.0"
```

To make requests using an endpoint definition using the [play client](https://github.com/playframework/play-ws), import:
Expand Down
4 changes: 2 additions & 2 deletions generated-doc/out/client/sttp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-sttp-client" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-sttp-client" % "1.1.0"
```

To make requests using an endpoint definition using the [sttp client](https://github.com/softwaremill/sttp), import:
Expand Down Expand Up @@ -102,7 +102,7 @@ In this case add the following dependencies (note the [`%%%`](https://www.scala-
instead of the usual `%%`):

```scala
"com.softwaremill.sttp.tapir" %%% "tapir-sttp-client" % "1.0.6"
"com.softwaremill.sttp.tapir" %%% "tapir-sttp-client" % "1.1.0"
"io.github.cquiroz" %%% "scala-java-time" % "2.2.0" // implementations of java.time classes for Scala.JS
```

Expand Down
2 changes: 1 addition & 1 deletion generated-doc/out/docs/asyncapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To use, add the following dependencies:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-asyncapi-docs" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-asyncapi-docs" % "1.1.0"
"com.softwaremill.sttp.apispec" %% "asyncapi-circe-yaml" % "..." // see https://github.com/softwaremill/sttp-apispec
```

Expand Down
10 changes: 5 additions & 5 deletions generated-doc/out/docs/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ these steps can be done separately, giving you complete control over the process
To generate OpenAPI documentation and expose it using the Swagger UI in a single step, first add the dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % "1.1.0"
```

Then, you can interpret a list of endpoints using `SwaggerInterpreter`. The result will be a list of file-serving
Expand Down Expand Up @@ -55,7 +55,7 @@ for details.
Similarly as above, you'll need the following dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-redoc-bundle" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-redoc-bundle" % "1.1.0"
```

And the server endpoints can be generated using the `sttp.tapir.redoc.bundle.RedocInterpreter` class.
Expand All @@ -65,7 +65,7 @@ And the server endpoints can be generated using the `sttp.tapir.redoc.bundle.Red
To generate the docs in the OpenAPI yaml format, add the following dependencies:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs" % "1.1.0"
"com.softwaremill.sttp.apispec" %% "openapi-circe-yaml" % "..." // see https://github.com/softwaremill/sttp-apispec
```

Expand Down Expand Up @@ -136,12 +136,12 @@ The modules `tapir-swagger-ui` and `tapir-redoc` contain server endpoint definit
yaml format, will expose it using the given context path. To use, add as a dependency either
`tapir-swagger-ui`:
```scala
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui" % "1.1.0"
```

or `tapir-redoc`:
```scala
"com.softwaremill.sttp.tapir" %% "tapir-redoc" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-redoc" % "1.1.0"
```

Then, you'll need to pass the server endpoints to your server interpreter. For example, using akka-http:
Expand Down
42 changes: 25 additions & 17 deletions generated-doc/out/endpoint/customtypes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
# Custom types

To support a custom type, you'll need to provide an implicit `Codec` for that type, or the components to create such
a codec. The below mostly applies to wrapper types for inputs/outputs such as query parameters, path segments or
headers. For custom types used in [json](json.md) or [forms](forms.md) bodies, see the dedicated sections.
a codec.

Most commonly, you'll be defining a custom codec so that a custom type can be used in inputs/outputs such as query
parameters, path segments or headers. [Json](json.md) and [forms](forms.md) bodies have dedicated support for
creating codecs, see the appropriate sections.

A custom codec can be created by writing one from scratch, mapping over an existing codec, or automatically deriving one.
Which of these approaches can be taken, depends on the context in which the codec will be used.

## Automatically deriving codecs

In some cases, codecs can be automatically derived:

* for supported [json](json.md) libraries
* for urlencoded and multipart [forms](forms.md)
* for value classes (extending `AnyVal`)

Automatic codec derivation usually requires other implicits, such as:

* json encoders/decoders from the json library
* codecs for individual form fields
* schema of the custom type, through the `Schema[T]` implicits (see the [next section on schemas](schemas.md))

Note that derivation of e.g. circe json encoders/decoders and tapir schemas are separate processes, and must be
configured separately.

## Creating an implicit codec by hand

To create a custom codec, you can either directly implement the `Codec` trait, which requires to provide the following
Expand Down Expand Up @@ -76,22 +96,10 @@ endpoint.in(query[MyId]("myId"))
endpoint.in(path[MyId])
```

## Automatically deriving codecs

In some cases, codecs can be automatically derived:

* for supported [json](json.md) libraries
* for urlencoded and multipart [forms](forms.md)
* for value classes (extending `AnyVal`)

Automatic codec derivation usually requires other implicits, such as:
### Codecs for enumerations

* json encoders/decoders from the json library
* codecs for individual form fields
* schema of the custom type, through the `Schema[T]` implicits (see the next section)

Note the derivation of e.g. circe json encoders/decoders and tapir schemas are separate processes, and must be
configured separately.
In some cases, codecs for enumerations can be derived, but need to be defined as an implicit value by hand, because
you'll need to provide some parameters. See the section on [enumerations validators](validation.md) for more details.

## Next

Expand Down
14 changes: 7 additions & 7 deletions generated-doc/out/endpoint/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `tapir-cats` module contains additional instances for some [cats](https://ty
datatypes as well as additional syntax:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-cats" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-cats" % "1.1.0"
```

- `import sttp.tapir.integ.cats.codec._` - brings schema, validator and codec instances
Expand All @@ -26,7 +26,7 @@ If you use [refined](https://github.com/fthomas/refined), the `tapir-refined` mo
validators for `T Refined P` as long as a codec for `T` already exists:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-refined" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-refined" % "1.1.0"
```

You'll need to extend the `sttp.tapir.codec.refined.TapirCodecRefined`
Expand All @@ -38,7 +38,7 @@ Some predicates will bind correctly to the vanilla tapir Validator, while others
might not be very clear when reading the generated documentation. Correctly bound predicates can be found in
`integration/refined/src/main/scala/sttp/tapir/codec/refined/TapirCodecRefined.scala`.
If you are not satisfied with the validator generated by `tapir-refined`, you can provide an implicit
`ValidatorForPredicate[T, P]` in scope using `ValidatorForPredicate.fromPrimitiveValidator' to build it (do not
`ValidatorForPredicate[T, P]` in scope using `ValidatorForPredicate.fromPrimitiveValidator` to build it (do not
hesitate to contribute your work!).

## Enumeratum integration
Expand All @@ -47,7 +47,7 @@ The `tapir-enumeratum` module provides schemas, validators and codecs for [Enume
enumerations. To use, add the following dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-enumeratum" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-enumeratum" % "1.1.0"
```

Then, `import sttp.tapir.codec.enumeratum._`, or extends the `sttp.tapir.codec.enumeratum.TapirCodecEnumeratum` trait.
Expand Down Expand Up @@ -87,7 +87,7 @@ If you use [scala-newtype](https://github.com/estatico/scala-newtype), the `tapi
schemas for types with a `@newtype` and `@newsubtype` annotations as long as a codec and schema for its underlying value already exists:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-newtype" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-newtype" % "1.1.0"
```

Then, `import sttp.tapir.codec.newtype._`, or extend the `sttp.tapir.codec.newtype.TapirCodecNewType` trait to bring the implicit values into scope.
Expand All @@ -98,7 +98,7 @@ If you use [monix newtypes](https://github.com/monix/newtypes), the `tapir-monix
schemas for types which extend `NewtypeWrapped` and `NewsubtypeWrapped` annotations as long as a codec and schema for its underlying value already exists:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-monix-newtype" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-monix-newtype" % "1.1.0"
```

Then, `import sttp.tapir.codec.monix.newtype._`, or extend the `sttp.tapir.codec.monix.newtype.TapirCodecMonixNewType` trait to bring the implicit values into scope.
Expand All @@ -110,7 +110,7 @@ For details refer to [derevo documentation](https://github.com/tofu-tf/derevo#in
To use, add the following dependency:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-derevo" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-derevo" % "1.1.0"
```

Then you can derive schema for your ADT along with other typeclasses besides ADT declaration itself:
Expand Down
28 changes: 19 additions & 9 deletions generated-doc/out/endpoint/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ customised, by creating a string-based body with the correct codec format (which

```scala
import sttp.tapir._
stringBodyUtf8AnyFormat(Codec.id(CodecFormat.Json(), Schema.string))
stringBodyUtf8AnyFormat(Codec.string.format(CodecFormat.Json()))

// or, providing a schema:
import sttp.tapir.generic.auto._
Expand All @@ -49,7 +49,7 @@ stringBodyUtf8AnyFormat(Codec.id(CodecFormat.Json(), implicitly[Schema[MyBody]].
To use [Circe](https://github.com/circe/circe), add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonCirce` trait, see [MyTapir](../mytapir.md)):
Expand Down Expand Up @@ -122,7 +122,7 @@ Now the above JSON object will render as
To use [µPickle](http://www.lihaoyi.com/upickle/) add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-upickle" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-upickle" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonuPickle` trait, see [MyTapir](../mytapir.md) and add `TapirJsonuPickle` not `TapirCirceJson`):
Expand Down Expand Up @@ -157,7 +157,7 @@ For more examples, including making a custom encoder/decoder, see [TapirJsonuPic
To use [Play JSON](https://github.com/playframework/play-json) add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-play" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-play" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonPlay` trait, see [MyTapir](../mytapir.md) and add `TapirJsonPlay` not `TapirCirceJson`):
Expand All @@ -173,7 +173,7 @@ Play JSON requires `Reads` and `Writes` implicit values in scope for each type y
To use [Spray JSON](https://github.com/spray/spray-json) add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-spray" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-spray" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonSpray` trait, see [MyTapir](../mytapir.md) and add `TapirJsonSpray` not `TapirCirceJson`):
Expand All @@ -189,7 +189,7 @@ Spray JSON requires a `JsonFormat` implicit value in scope for each type you wan
To use [Tethys JSON](https://github.com/tethys-json/tethys) add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-tethys" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-tethys" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonTethys` trait, see [MyTapir](../mytapir.md) and add `TapirJsonTethys` not `TapirCirceJson`):
Expand All @@ -205,7 +205,7 @@ Tethys JSON requires `JsonReader` and `JsonWriter` implicit values in scope for
To use [Jsoniter-scala](https://github.com/plokhotnyuk/jsoniter-scala) add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % "1.1.0"
```

Next, import the package (or extend the `TapirJsonJsoniter` trait, see [MyTapir](../mytapir.md) and add `TapirJsonJsoniter` not `TapirCirceJson`):
Expand All @@ -221,7 +221,7 @@ Jsoniter Scala requires `JsonValueCodec` implicit value in scope for each type y
To use [json4s](https://github.com/json4s/json4s) add the following dependencies to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-json4s" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-json4s" % "1.1.0"
```

And one of the implementations:
Expand Down Expand Up @@ -252,7 +252,7 @@ implicit val formats: Formats = org.json4s.jackson.Serialization.formats(NoTypeH
To use [zio-json](https://github.com/zio/zio-json), add the following dependency to your project:

```scala
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % "1.0.6"
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % "1.1.0"
```
Next, import the package (or extend the `TapirJsonZio` trait, see [MyTapir](../mytapir.md) and add `TapirJsonZio` instead of `TapirCirceJson`):

Expand All @@ -268,6 +268,16 @@ To add support for additional JSON libraries, see the
[sources](https://github.com/softwaremill/tapir/blob/master/json/circe/src/main/scala/sttp/tapir/json/circe/TapirJsonCirce.scala)
for the Circe codec (which is just a couple of lines of code).

## Coproducts (enums, sealed traits, classes)

If you are serialising a sealed hierarchy, such as a Scala 3 `enum`, a `sealed trait` or `sealed class`, the configuration
of [schema derivation](schemas.md) will have to match the configuration of your json library. Different json libraries
have different defaults when it comes to a discrimination strategy, so in order to have the schemas (and hence the
documentation) in sync with how the values are serialised, you will have to configure schema derivation as well.

Schemas are referenced at the point of `jsonBody` usage, so any configuration must be available in the implicit scope
when this method is called.

## Next

Read on about [working with forms](forms.md).
Loading

0 comments on commit 947b2c8

Please sign in to comment.