Skip to content

Commit e594023

Browse files
committed
fix: generate samples, make a new one for sttp4-circe
1 parent bd2a4bd commit e594023

26 files changed

Lines changed: 929 additions & 20 deletions

File tree

bin/configs/scala-sttp4-circe.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: scala-sttp4
2+
outputDir: samples/client/petstore/scala-sttp4-circe
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/scala-sttp4
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"
7+
jsonLibrary: "circe"

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaSttp4ClientCodegen.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class ScalaSttp4ClientCodegen extends AbstractScalaCodegen implements CodegenConfig {
2626
private static final StringProperty STTP_CLIENT_VERSION = new StringProperty("sttpClientVersion", "The version of " +
27-
"sttp client", "4.0.0-M1");
27+
"sttp client", "4.0.15");
2828
private static final BooleanProperty USE_SEPARATE_ERROR_CHANNEL = new BooleanProperty("separateErrorChannel",
2929
"Whether to return response as " +
3030
"F[Either[ResponseError[ErrorType], ReturnType]]] or to flatten " +
@@ -33,6 +33,10 @@ public class ScalaSttp4ClientCodegen extends AbstractScalaCodegen implements Cod
3333
"joda-time library", "2.10.13");
3434
private static final StringProperty JSON4S_VERSION = new StringProperty("json4sVersion", "The version of json4s " +
3535
"library", "4.0.6");
36+
private static final StringProperty CIRCE_VERSION = new StringProperty("circeVersion", "The version of circe " +
37+
"library", "0.14.15");
38+
private static final StringProperty CIRCE_EXTRAS_VERSION = new StringProperty("circeExtrasVersion",
39+
"The version of circe-generic-extras library", "0.14.4");
3640

3741
private static final JsonLibraryProperty JSON_LIBRARY_PROPERTY = new JsonLibraryProperty();
3842

@@ -41,7 +45,7 @@ public class ScalaSttp4ClientCodegen extends AbstractScalaCodegen implements Cod
4145

4246
private static final List<Property<?>> properties = Arrays.asList(
4347
STTP_CLIENT_VERSION, USE_SEPARATE_ERROR_CHANNEL, JODA_TIME_VERSION,
44-
JSON4S_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
48+
JSON4S_VERSION, CIRCE_VERSION, CIRCE_EXTRAS_VERSION, JSON_LIBRARY_PROPERTY, PACKAGE_PROPERTY);
4549

4650
private final Logger LOGGER = LoggerFactory.getLogger(ScalaSttp4ClientCodegen.class);
4751

modules/openapi-generator/src/main/resources/scala-sttp4/build.sbt.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ libraryDependencies ++= Seq(
1616
{{/json4s}}
1717
{{#circe}}
1818
"com.softwaremill.sttp.client4" %% "circe" % "{{sttpClientVersion}}"
19+
"io.circe" %% "circe-generic" % "{{circeVersion}}",
20+
"io.circe" %% "circe-generic-extras" % "{{circeExtrasVersion}}",
1921
{{/circe}}
2022
)
2123

Lines changed: 23 additions & 0 deletions
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
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
README.md
2+
build.sbt
3+
project/build.properties
4+
src/main/scala/org/openapitools/client/api/PetApi.scala
5+
src/main/scala/org/openapitools/client/api/StoreApi.scala
6+
src/main/scala/org/openapitools/client/api/UserApi.scala
7+
src/main/scala/org/openapitools/client/core/AdditionalTypeSerializers.scala
8+
src/main/scala/org/openapitools/client/core/DateSerializers.scala
9+
src/main/scala/org/openapitools/client/core/JsonSupport.scala
10+
src/main/scala/org/openapitools/client/model/ApiResponse.scala
11+
src/main/scala/org/openapitools/client/model/Category.scala
12+
src/main/scala/org/openapitools/client/model/Order.scala
13+
src/main/scala/org/openapitools/client/model/Pet.scala
14+
src/main/scala/org/openapitools/client/model/Tag.scala
15+
src/main/scala/org/openapitools/client/model/User.scala
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.20.0-SNAPSHOT
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# openapi-client
2+
3+
OpenAPI Petstore
4+
- API version: 1.0.0
5+
- Generator version: 7.20.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>openapi-client</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:openapi-client:1.0.0"
53+
```
54+
55+
### SBT users
56+
57+
```scala
58+
libraryDependencies += "org.openapitools" % "openapi-client" % "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+
*PetApi* | **addPet** | **POST** /pet | Add a new pet to the store
70+
*PetApi* | **deletePet** | **DELETE** /pet/${petId} | Deletes a pet
71+
*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status
72+
*PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags
73+
*PetApi* | **getPetById** | **GET** /pet/${petId} | Find pet by ID
74+
*PetApi* | **updatePet** | **PUT** /pet | Update an existing pet
75+
*PetApi* | **updatePetWithForm** | **POST** /pet/${petId} | Updates a pet in the store with form data
76+
*PetApi* | **uploadFile** | **POST** /pet/${petId}/uploadImage | uploads an image
77+
*StoreApi* | **deleteOrder** | **DELETE** /store/order/${orderId} | Delete purchase order by ID
78+
*StoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status
79+
*StoreApi* | **getOrderById** | **GET** /store/order/${orderId} | Find purchase order by ID
80+
*StoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet
81+
*UserApi* | **createUser** | **POST** /user | Create user
82+
*UserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array
83+
*UserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array
84+
*UserApi* | **deleteUser** | **DELETE** /user/${username} | Delete user
85+
*UserApi* | **getUserByName** | **GET** /user/${username} | Get user by user name
86+
*UserApi* | **loginUser** | **GET** /user/login | Logs user into the system
87+
*UserApi* | **logoutUser** | **GET** /user/logout | Logs out current logged in user session
88+
*UserApi* | **updateUser** | **PUT** /user/${username} | Updated user
89+
90+
91+
## Documentation for Models
92+
93+
- [ApiResponse](ApiResponse.md)
94+
- [Category](Category.md)
95+
- [Order](Order.md)
96+
- [Pet](Pet.md)
97+
- [Tag](Tag.md)
98+
- [User](User.md)
99+
100+
101+
<a id="documentation-for-authorization"></a>
102+
## Documentation for Authorization
103+
104+
105+
Authentication schemes defined for the API:
106+
<a id="api_key"></a>
107+
### api_key
108+
109+
- **Type**: API key
110+
- **API key parameter name**: api_key
111+
- **Location**: HTTP header
112+
113+
114+
## Author
115+
116+
117+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version := "1.0.0"
2+
name := "openapi-client"
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.client4" %% "core" % "4.0.15",
10+
"com.softwaremill.sttp.client4" %% "circe" % "4.0.15"
11+
"io.circe" %% "circe-generic" % "0.14.15",
12+
"io.circe" %% "circe-generic-extras" % "0.14.4",
13+
)
14+
15+
scalacOptions := Seq(
16+
"-unchecked",
17+
"-deprecation",
18+
"-feature"
19+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.10.11
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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.model.ApiResponse
15+
import java.io.File
16+
import org.openapitools.client.model.Pet
17+
import org.openapitools.client.core.JsonSupport._
18+
import sttp.client4._
19+
import sttp.model.Method
20+
21+
object PetApi {
22+
def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl)
23+
}
24+
25+
class PetApi(baseUrl: String) {
26+
27+
/**
28+
*
29+
*
30+
* Expected answers:
31+
* code 200 : Pet (successful operation)
32+
* code 405 : (Invalid input)
33+
*
34+
* @param pet Pet object that needs to be added to the store
35+
*/
36+
def addPet(pet: Pet): Request[Either[ResponseException[String], Pet]] =
37+
basicRequest
38+
.method(Method.POST, uri"$baseUrl/pet")
39+
.contentType("application/json")
40+
.body(asJson(pet))
41+
.response(asJson[Pet])
42+
43+
/**
44+
*
45+
*
46+
* Expected answers:
47+
* code 400 : (Invalid pet value)
48+
*
49+
* @param petId Pet id to delete
50+
* @param apiKey
51+
*/
52+
def deletePet(petId: Long, apiKey: Option[String] = None): Request[Either[ResponseException[String], Unit]] =
53+
basicRequest
54+
.method(Method.DELETE, uri"$baseUrl/pet/${petId}")
55+
.contentType("application/json")
56+
.header("api_key", apiKey)
57+
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
58+
59+
/**
60+
* Multiple status values can be provided with comma separated strings
61+
*
62+
* Expected answers:
63+
* code 200 : Seq[Pet] (successful operation)
64+
* code 400 : (Invalid status value)
65+
*
66+
* @param status Status values that need to be considered for filter
67+
*/
68+
def findPetsByStatus(status: Seq[String] = Seq.empty): Request[Either[ResponseException[String], Seq[Pet]]] =
69+
basicRequest
70+
.method(Method.GET, uri"$baseUrl/pet/findByStatus?status=${ status }")
71+
.contentType("application/json")
72+
.response(asJson[Seq[Pet]])
73+
74+
/**
75+
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
76+
*
77+
* Expected answers:
78+
* code 200 : Seq[Pet] (successful operation)
79+
* code 400 : (Invalid tag value)
80+
*
81+
* @param tags Tags to filter by
82+
*/
83+
def findPetsByTags(tags: Seq[String] = Seq.empty): Request[Either[ResponseException[String], Seq[Pet]]] =
84+
basicRequest
85+
.method(Method.GET, uri"$baseUrl/pet/findByTags?tags=${ tags }")
86+
.contentType("application/json")
87+
.response(asJson[Seq[Pet]])
88+
89+
/**
90+
* Returns a single pet
91+
*
92+
* Expected answers:
93+
* code 200 : Pet (successful operation)
94+
* code 400 : (Invalid ID supplied)
95+
* code 404 : (Pet not found)
96+
*
97+
* Available security schemes:
98+
* api_key (apiKey)
99+
*
100+
* @param petId ID of pet to return
101+
*/
102+
def getPetById(apiKeyHeader: String)(petId: Long): Request[Either[ResponseException[String], Pet]] =
103+
basicRequest
104+
.method(Method.GET, uri"$baseUrl/pet/${petId}")
105+
.contentType("application/json")
106+
.header("api_key", apiKeyHeader)
107+
.response(asJson[Pet])
108+
109+
/**
110+
*
111+
*
112+
* Expected answers:
113+
* code 200 : Pet (successful operation)
114+
* code 400 : (Invalid ID supplied)
115+
* code 404 : (Pet not found)
116+
* code 405 : (Validation exception)
117+
*
118+
* @param pet Pet object that needs to be added to the store
119+
*/
120+
def updatePet(pet: Pet): Request[Either[ResponseException[String], Pet]] =
121+
basicRequest
122+
.method(Method.PUT, uri"$baseUrl/pet")
123+
.contentType("application/json")
124+
.body(asJson(pet))
125+
.response(asJson[Pet])
126+
127+
/**
128+
*
129+
*
130+
* Expected answers:
131+
* code 405 : (Invalid input)
132+
*
133+
* @param petId ID of pet that needs to be updated
134+
* @param name Updated name of the pet
135+
* @param status Updated status of the pet
136+
*/
137+
def updatePetWithForm(petId: Long, name: Option[String] = None, status: Option[String] = None): Request[Either[ResponseException[String], Unit]] =
138+
basicRequest
139+
.method(Method.POST, uri"$baseUrl/pet/${petId}")
140+
.contentType("application/x-www-form-urlencoded")
141+
.body(Map(
142+
"name" -> name,
143+
"status" -> status
144+
))
145+
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
146+
147+
/**
148+
*
149+
*
150+
* Expected answers:
151+
* code 200 : ApiResponse (successful operation)
152+
*
153+
* @param petId ID of pet to update
154+
* @param additionalMetadata Additional data to pass to server
155+
* @param file file to upload
156+
*/
157+
def uploadFile(petId: Long, additionalMetadata: Option[String] = None, file: Option[File] = None): Request[Either[ResponseException[String], ApiResponse]] =
158+
basicRequest
159+
.method(Method.POST, uri"$baseUrl/pet/${petId}/uploadImage")
160+
.contentType("multipart/form-data")
161+
.multipartBody(Seq(
162+
additionalMetadata.map(multipart("additionalMetadata", _))
163+
,
164+
file.map(multipartFile("file", _))
165+
166+
).flatten)
167+
.response(asJson[ApiResponse])
168+
169+
}

0 commit comments

Comments
 (0)