An open API service indexing awesome lists of open source software.

https://github.com/softwaremill/tapir-scalaxb-example

This project showcases how to implement xml serialization / deserialization in Tapir, using code generated by Scalaxb.
https://github.com/softwaremill/tapir-scalaxb-example

Last synced: 6 months ago
JSON representation

This project showcases how to implement xml serialization / deserialization in Tapir, using code generated by Scalaxb.

Awesome Lists containing this project

README

          

# Tapir Scalaxb Example

This project showcases how to implement xml serialization / deserialization in [Tapir](https://github.com/softwaremill/tapir), using code generated by [Scalaxb](https://github.com/eed3si9n/scalaxb).

## Project overview

Project exposes one endpoint, named "xml", that consumes xml object - `Outer`:
```xml


42
true
horses

cats

```
and returns a "reversed" version of it
```xml


-42
false
sesroh

stac

```

When running at localhost, the endpoint could be accessed using `curl`:
```shell
curl -X 'POST' \
'http://localhost:8080/xml' \
-H 'accept: application/xml' \
-H 'Content-Type: application/xml' \
-d '

42
true
horses

cats
'
```
or viewed in swagger at [http://localhost:8080/docs](http://localhost:8080/docs).

The `Outer` object model, serialization, and deserialization logic is a part of code generated by `scalaxb` based on XML Schema definition file, located at `src/main/xsd/InnerOuter.xsd`.
The code responsible for integrating code generated by `scalaxb` with `tapir` is located in `xml` package.
The key file is named `TapirXmlScalaxb` as it implements `XmlCodec[T]` enabling integration.
Its usage could be looked up in `Endpoints` file as well as in tests in `EndpointsSpec` or `TapirXmlScalaxbTest`.

Please notice, that just after opening the project in the IDE of your choosing, several symbols might appear in red as they cannot be resolved.
This is because the scalaxb code is not generated yet.
Compilation of code (or simply running the project) would generate missing files and fix "symbol not resolved" errors.

## Running project

If you have [sbt](https://www.scala-sbt.org) installed, you can use the standard commands:
```shell
sbt compile # build the project
sbt test # run the tests
sbt run # run the application (Main)
```

If you don't have [sbt](https://www.scala-sbt.org) installed, you can use the provided wrapper script:
```shell
./sbtx -h # shows an usage of a wrapper script
./sbtx compile # build the project
./sbtx test # run the tests
./sbtx run # run the application (Main)
```

For more details check the [sbtx usage](https://github.com/dwijnand/sbt-extras#sbt--h) page.

## Docs
[Tapir documentation](https://tapir.softwaremill.com/en/latest/)

[Tapir - Codecs](https://tapir.softwaremill.com/en/latest/endpoint/codecs.html)

[Scalaxb documentation](https://scalaxb.org/)

[Setup scalaxb as sbt plugin](https://scalaxb.org/sbt-scalaxb)

[Running scalaxb](https://scalaxb.org/running-scalaxb)