Skip to content

Commit 86a8e52

Browse files
authored
Add tests for scala sttp client (jsonLibrary: circe) (OpenAPITools#21061)
* add tests for scala sttp circe * use jdk 11 * test with jdk 17 * fix * test in circleci * remove finch
1 parent 89f0f75 commit 86a8e52

26 files changed

+1066
-4
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Samples Scala/sbt (JDK8)
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/server/petstore/scala-finch/**'
7+
pull_request:
8+
paths:
9+
- 'samples/server/petstore/scala-finch/**'
10+
jobs:
11+
build:
12+
name: Build scala-finch servers
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
sample:
18+
# servers
19+
- samples/server/petstore/scala-finch # cannot be tested with jdk11
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-java@v4
23+
with:
24+
distribution: 'temurin'
25+
java-version: 8
26+
- name: Setup sbt launcher
27+
uses: sbt/setup-sbt@v1
28+
- name: Cache maven dependencies
29+
uses: actions/cache@v4
30+
env:
31+
cache-name: maven-repository
32+
with:
33+
path: |
34+
~/.ivy2
35+
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/build.sbt') }}
36+
- name: Build and test
37+
working-directory: ${{ matrix.sample }}
38+
run: sbt -v +test

.github/workflows/samples-scala.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ jobs:
2020
matrix:
2121
sample:
2222
# clients
23-
- 'samples/client/petstore/java/okhttp-gson'
23+
- samples/client/petstore/java/okhttp-gson
2424
- samples/client/petstore/scalaz
2525
- samples/client/petstore/scala-pekko
2626
- samples/client/petstore/scala-http4s
27-
#- samples/client/petstore/scala-sttp # won't pass while the same tests in circleci pass
27+
#- samples/client/petstore/scala-sttp
28+
#- samples/client/petstore/scala-sttp-circe
2829
# servers
2930
- samples/server/petstore/scala-lagom-server
3031
- samples/server/petstore/scala-play-server
3132
- samples/server/petstore/scala-akka-http-server
3233
- samples/server/petstore/scala-pekko-http-server
3334
- samples/server/petstore/scalatra
34-
- samples/server/petstore/scala-finch # cannot be tested with jdk11
3535
- samples/server/petstore/scala-http4s-server
3636
- samples/server/petstore/scala-cask
3737
steps:
3838
- uses: actions/checkout@v4
3939
- uses: actions/setup-java@v4
4040
with:
4141
distribution: 'temurin'
42-
java-version: 8
42+
java-version: 11
4343
- name: Setup sbt launcher
4444
uses: sbt/setup-sbt@v1
4545
- name: Cache maven dependencies

CI/circle_parallel.sh

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ else
122122

123123
(cd samples/client/petstore/scala-akka && mvn integration-test)
124124
(cd samples/client/petstore/scala-sttp && mvn integration-test)
125+
(cd samples/client/petstore/scala-sttp-circe && mvn integration-test)
125126
(cd samples/client/petstore/scala-sttp4 && mvn integration-test)
126127
(cd samples/client/petstore/clojure && mvn integration-test)
127128
(cd samples/client/petstore/java/jersey2-java8 && mvn integration-test)

bin/configs/scala-sttp-circe.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
generatorName: scala-sttp
2+
outputDir: samples/client/petstore/scala-sttp-circe
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/scala/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/scala-sttp
5+
nameMappings:
6+
_type: "`underscoreType`"
7+
type_: "`typeWithUnderscore`"
8+
http_debug_operation: "`httpDebugOperation`"
9+
parameterNameMappings:
10+
_type: underscoreType
11+
type_: typeWithUnderscore
12+
http_debug_operation: httpDebugOperation
13+
additionalProperties:
14+
artifactId: scala-sttp-petstore
15+
jsonLibrary: circe
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
README.md
2+
build.sbt
3+
project/build.properties
4+
src/main/scala/org/openapitools/client/api/FakeApi.scala
5+
src/main/scala/org/openapitools/client/api/PetApi.scala
6+
src/main/scala/org/openapitools/client/api/StoreApi.scala
7+
src/main/scala/org/openapitools/client/api/UserApi.scala
8+
src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala
9+
src/main/scala/org/openapitools/client/core/DateSerializers.scala
10+
src/main/scala/org/openapitools/client/core/JsonSupport.scala
11+
src/main/scala/org/openapitools/client/model/ApiResponse.scala
12+
src/main/scala/org/openapitools/client/model/Category.scala
13+
src/main/scala/org/openapitools/client/model/EnumTest.scala
14+
src/main/scala/org/openapitools/client/model/Order.scala
15+
src/main/scala/org/openapitools/client/model/Pet.scala
16+
src/main/scala/org/openapitools/client/model/PropertyNameMapping.scala
17+
src/main/scala/org/openapitools/client/model/Tag.scala
18+
src/main/scala/org/openapitools/client/model/User.scala
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.13.0-SNAPSHOT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# scala-sttp-petstore
2+
3+
OpenAPI Petstore
4+
- API version: 1.0.0
5+
- Generator version: 7.13.0-SNAPSHOT
6+
7+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
8+
9+
10+
*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)*
11+
12+
## Requirements
13+
14+
Building the API client library requires:
15+
1. Java 1.7+
16+
2. Maven/Gradle/SBT
17+
18+
## Installation
19+
20+
To install the API client library to your local Maven repository, simply execute:
21+
22+
```shell
23+
mvn clean install
24+
```
25+
26+
To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:
27+
28+
```shell
29+
mvn clean deploy
30+
```
31+
32+
Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.
33+
34+
### Maven users
35+
36+
Add this dependency to your project's POM:
37+
38+
```xml
39+
<dependency>
40+
<groupId>org.openapitools</groupId>
41+
<artifactId>scala-sttp-petstore</artifactId>
42+
<version>1.0.0</version>
43+
<scope>compile</scope>
44+
</dependency>
45+
```
46+
47+
### Gradle users
48+
49+
Add this dependency to your project's build file:
50+
51+
```groovy
52+
compile "org.openapitools:scala-sttp-petstore:1.0.0"
53+
```
54+
55+
### SBT users
56+
57+
```scala
58+
libraryDependencies += "org.openapitools" % "scala-sttp-petstore" % "1.0.0"
59+
```
60+
61+
## Getting Started
62+
63+
## Documentation for API Endpoints
64+
65+
All URIs are relative to *http://petstore.swagger.io/v2*
66+
67+
Class | Method | HTTP request | Description
68+
------------ | ------------- | ------------- | -------------
69+
*FakeApi* | **getParameterNameMapping** | **GET** /fake/parameter-name-mapping | parameter name mapping test
70+
*PetApi* | **addPet** | **POST** /pet | Add a new pet to the store
71+
*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet
72+
*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
73+
*PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags
74+
*PetApi* | **getPetById** | **GET** /pet/${petId} | Find pet by ID
75+
*PetApi* | **updatePet** | **PUT** /pet | Update an existing pet
76+
*PetApi* | **updatePetWithForm** | **POST** /pet/${petId} | Updates a pet in the store with form data
77+
*PetApi* | **uploadFile** | **POST** /pet/${petId}/uploadImage | uploads an image
78+
*StoreApi* | **deleteOrder** | **DELETE** /store/order/${orderId} | Delete purchase order by ID
79+
*StoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status
80+
*StoreApi* | **getOrderById** | **GET** /store/order/${orderId} | Find purchase order by ID
81+
*StoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet
82+
*UserApi* | **createUser** | **POST** /user | Create user
83+
*UserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array
84+
*UserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array
85+
*UserApi* | **deleteUser** | **DELETE** /user/${username} | Delete user
86+
*UserApi* | **getUserByName** | **GET** /user/${username} | Get user by user name
87+
*UserApi* | **loginUser** | **GET** /user/login | Logs user into the system
88+
*UserApi* | **logoutUser** | **GET** /user/logout | Logs out current logged in user session
89+
*UserApi* | **updateUser** | **PUT** /user/${username} | Updated user
90+
91+
92+
## Documentation for Models
93+
94+
- [ApiResponse](ApiResponse.md)
95+
- [Category](Category.md)
96+
- [EnumTest](EnumTest.md)
97+
- [Order](Order.md)
98+
- [Pet](Pet.md)
99+
- [PropertyNameMapping](PropertyNameMapping.md)
100+
- [Tag](Tag.md)
101+
- [User](User.md)
102+
103+
104+
<a id="documentation-for-authorization"></a>
105+
## Documentation for Authorization
106+
107+
108+
Authentication schemes defined for the API:
109+
<a id="api_key"></a>
110+
### api_key
111+
112+
- **Type**: API key
113+
- **API key parameter name**: api_key
114+
- **Location**: HTTP header
115+
116+
117+
## Author
118+
119+
120+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version := "1.0.0"
2+
name := "scala-sttp-petstore"
3+
organization := "org.openapitools"
4+
5+
scalaVersion := "2.13.16"
6+
crossScalaVersions := Seq(scalaVersion.value, "2.12.20")
7+
8+
libraryDependencies ++= Seq(
9+
"com.softwaremill.sttp.client3" %% "core" % "3.3.18",
10+
"com.softwaremill.sttp.client3" %% "circe" % "3.3.18",
11+
"io.circe" %% "circe-generic" % "0.14.1"
12+
)
13+
14+
scalacOptions := Seq(
15+
"-unchecked",
16+
"-deprecation",
17+
"-feature"
18+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<project>
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>org.openapitools</groupId>
4+
<artifactId>scala-sttp-circe-petstore</artifactId>
5+
<packaging>pom</packaging>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>scala-sttp-circe-petstore</name>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>org.codehaus.mojo</groupId>
12+
<artifactId>exec-maven-plugin</artifactId>
13+
<version>1.5.0</version>
14+
<executions>
15+
<execution>
16+
<id>sbt-test</id>
17+
<phase>integration-test</phase>
18+
<goals>
19+
<goal>exec</goal>
20+
</goals>
21+
<configuration>
22+
<executable>sbt</executable>
23+
<arguments>
24+
<argument>-ivy</argument>
25+
<argument>${user.home}/.ivy2</argument>
26+
<argument>test</argument>
27+
</arguments>
28+
</configuration>
29+
</execution>
30+
</executions>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.10.11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* OpenAPI Petstore
3+
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package org.openapitools.client.api
13+
14+
import org.openapitools.client.core.JsonSupport._
15+
import sttp.client3._
16+
import sttp.model.Method
17+
18+
object FakeApi {
19+
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new FakeApi(baseUrl)
20+
}
21+
22+
class FakeApi(baseUrl: String) {
23+
24+
/**
25+
* Expected answers:
26+
* code 200 : (OK)
27+
*
28+
* @param underscoreType _type
29+
* @param `type` type
30+
* @param typeWithUnderscore type_
31+
* @param httpDebugOption http debug option (to test parameter naming option)
32+
*/
33+
def getParameterNameMapping(underscoreType: Long, `type`: String, typeWithUnderscore: String, httpDebugOption: String
34+
): Request[Either[ResponseException[String, Exception], Unit], Any] =
35+
basicRequest
36+
.method(Method.GET, uri"$baseUrl/fake/parameter-name-mapping?type=${ `type` }&http_debug_option=${ httpDebugOption }")
37+
.contentType("application/json")
38+
.header("_type", underscoreType.toString)
39+
.header("type_", typeWithUnderscore.toString)
40+
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
41+
42+
}

0 commit comments

Comments
 (0)