Skip to content

Commit d7d0b97

Browse files
committed
Add a new sample for ktor2
1 parent 52f2396 commit d7d0b97

26 files changed

Lines changed: 1372 additions & 4 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: kotlin-server
2+
outputDir: samples/server/petstore/kotlin-server/ktor2-usetags-false
3+
library: ktor2
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/petstore-with-tags.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
6+
additionalProperties:
7+
hideGenerationTimestamp: "true"
8+
serializableModel: "true"
9+
useTags: "false"

modules/openapi-generator/src/test/resources/3_0/kotlin/petstore-with-tags.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,10 @@ paths:
271271
additionalMetadata:
272272
type: string
273273
description: Additional data to pass to server
274-
required: false
275274
image:
276275
type: string
277276
description: image to upload
278277
format: binary
279-
required: true
280278
responses:
281279
200:
282280
description: successful operation
@@ -310,14 +308,12 @@ paths:
310308
additionalMetadata:
311309
type: string
312310
description: Additional data to pass to server
313-
required: false
314311
images:
315312
type: array
316313
items:
317314
type: string
318315
description: image to upload
319316
format: binary
320-
required: true
321317
responses:
322318
200:
323319
description: successful operation
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Dockerfile
2+
README.md
3+
build.gradle.kts
4+
gradle.properties
5+
gradle/wrapper/gradle-wrapper.properties
6+
settings.gradle
7+
src/main/kotlin/org/openapitools/server/AppMain.kt
8+
src/main/kotlin/org/openapitools/server/Configuration.kt
9+
src/main/kotlin/org/openapitools/server/Paths.kt
10+
src/main/kotlin/org/openapitools/server/apis/PetApi.kt
11+
src/main/kotlin/org/openapitools/server/apis/StoreApi.kt
12+
src/main/kotlin/org/openapitools/server/apis/UserApi.kt
13+
src/main/kotlin/org/openapitools/server/infrastructure/ApiKeyAuth.kt
14+
src/main/kotlin/org/openapitools/server/models/Category.kt
15+
src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt
16+
src/main/kotlin/org/openapitools/server/models/Order.kt
17+
src/main/kotlin/org/openapitools/server/models/Pet.kt
18+
src/main/kotlin/org/openapitools/server/models/Tag.kt
19+
src/main/kotlin/org/openapitools/server/models/User.kt
20+
src/main/resources/application.conf
21+
src/main/resources/logback.xml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.22.0-SNAPSHOT
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openjdk:8-jre-alpine
2+
3+
COPY ./build/libs/kotlin-server.jar /root/kotlin-server.jar
4+
5+
WORKDIR /root
6+
7+
CMD ["java", "-server", "-Xms4g", "-Xmx4g", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "kotlin-server.jar"]
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# org.openapitools.server - Kotlin Server library for OpenAPI Petstore
2+
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+
Generated by OpenAPI Generator 7.22.0-SNAPSHOT.
6+
7+
## Requires
8+
9+
* Kotlin 2.0.20
10+
* Gradle 8.10.2
11+
12+
## Build
13+
14+
First, create the gradle wrapper script:
15+
16+
```
17+
gradle wrapper
18+
```
19+
20+
Then, run:
21+
22+
```
23+
./gradlew check assemble
24+
```
25+
26+
This runs all tests and packages the library.
27+
28+
## Running
29+
30+
The server builds as a fat jar with a main entrypoint. To start the service, run `java -jar ./build/libs/kotlin-server.jar`.
31+
32+
You may also run in docker:
33+
34+
```
35+
docker build -t kotlin-server .
36+
docker run -p 8080:8080 kotlin-server
37+
```
38+
39+
## Features/Implementation Notes
40+
41+
* Supports JSON inputs/outputs, File inputs, and Form inputs (see ktor documentation for more info).
42+
* ~Supports collection formats for query parameters: csv, tsv, ssv, pipes.~
43+
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
44+
45+
<a id="documentation-for-api-endpoints"></a>
46+
## Documentation for API Endpoints
47+
48+
All URIs are relative to *http://petstore.swagger.io/v2*
49+
50+
Class | Method | HTTP request | Description
51+
------------ | ------------- | ------------- | -------------
52+
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
53+
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
54+
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
55+
*PetApi* | [**findPetsByTags**](docs/PetApi.md#findpetsbytags) | **GET** /pet/findByTags | Finds Pets by tags
56+
*PetApi* | [**getImage**](docs/PetApi.md#getimage) | **GET** /pet/{petId}/getImage | Get an image
57+
*PetApi* | [**getPetById**](docs/PetApi.md#getpetbyid) | **GET** /pet/{petId} | Find pet by ID
58+
*PetApi* | [**updatePet**](docs/PetApi.md#updatepet) | **PUT** /pet | Update an existing pet
59+
*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatepetwithform) | **POST** /pet/{petId} | Updates a pet in the store with form data
60+
*PetApi* | [**uploadFile**](docs/PetApi.md#uploadfile) | **POST** /pet/{petId}/uploadImage | uploads an image
61+
*PetApi* | [**uploadMultipleFile**](docs/PetApi.md#uploadmultiplefile) | **POST** /pet/{petId}/uploadMultipleImage | uploads multiple images
62+
*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteorder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
63+
*StoreApi* | [**getInventory**](docs/StoreApi.md#getinventory) | **GET** /store/inventory | Returns pet inventories by status
64+
*StoreApi* | [**getOrderById**](docs/StoreApi.md#getorderbyid) | **GET** /store/order/{orderId} | Find purchase order by ID
65+
*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeorder) | **POST** /store/order | Place an order for a pet
66+
*UserApi* | [**createUser**](docs/UserApi.md#createuser) | **POST** /user | Create user
67+
*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **POST** /user/createWithArray | Creates list of users with given input array
68+
*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **POST** /user/createWithList | Creates list of users with given input array
69+
*UserApi* | [**deleteUser**](docs/UserApi.md#deleteuser) | **DELETE** /user/{username} | Delete user
70+
*UserApi* | [**getUserByName**](docs/UserApi.md#getuserbyname) | **GET** /user/{username} | Get user by user name
71+
*UserApi* | [**loginUser**](docs/UserApi.md#loginuser) | **GET** /user/login | Logs user into the system
72+
*UserApi* | [**logoutUser**](docs/UserApi.md#logoutuser) | **GET** /user/logout | Logs out current logged in user session
73+
*UserApi* | [**logoutUserOptions**](docs/UserApi.md#logoutuseroptions) | **OPTIONS** /user/logout | logoutUserOptions
74+
*UserApi* | [**updateUser**](docs/UserApi.md#updateuser) | **PUT** /user/{username} | Updated user
75+
76+
77+
<a id="documentation-for-models"></a>
78+
## Documentation for Models
79+
80+
- [org.openapitools.server.models.Category](docs/Category.md)
81+
- [org.openapitools.server.models.ModelApiResponse](docs/ModelApiResponse.md)
82+
- [org.openapitools.server.models.Order](docs/Order.md)
83+
- [org.openapitools.server.models.Pet](docs/Pet.md)
84+
- [org.openapitools.server.models.Tag](docs/Tag.md)
85+
- [org.openapitools.server.models.User](docs/User.md)
86+
87+
88+
<a id="documentation-for-authorization"></a>
89+
## Documentation for Authorization
90+
91+
92+
Authentication schemes defined for the API:
93+
<a id="petstore_auth"></a>
94+
### petstore_auth
95+
96+
- **Type**: OAuth
97+
- **Flow**: implicit
98+
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
99+
- **Scopes**:
100+
- write:pets: modify pets in your account
101+
- read:pets: read your pets
102+
103+
<a id="api_key"></a>
104+
### api_key
105+
106+
- **Type**: API key
107+
- **API key parameter name**: api_key
108+
- **Location**: HTTP header
109+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
val kotlin_version: String by project
3+
val logback_version: String by project
4+
5+
group = "org.openapitools"
6+
version = "1.0.0"
7+
8+
plugins {
9+
kotlin("jvm") version "2.0.20"
10+
id("io.ktor.plugin") version "2.3.12"
11+
}
12+
13+
application {
14+
mainClass.set("io.ktor.server.netty.EngineMain")
15+
16+
val isDevelopment: Boolean = project.ext.has("development")
17+
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
implementation("ch.qos.logback:logback-classic:$logback_version")
26+
implementation("com.typesafe:config:1.4.1")
27+
implementation("io.ktor:ktor-server-auth")
28+
implementation("io.ktor:ktor-client-apache")
29+
implementation("io.ktor:ktor-server-auto-head-response")
30+
implementation("io.ktor:ktor-server-default-headers")
31+
implementation("io.ktor:ktor-server-content-negotiation")
32+
implementation("io.ktor:ktor-serialization-gson")
33+
implementation("io.ktor:ktor-server-resources")
34+
implementation("io.ktor:ktor-server-hsts")
35+
implementation("io.ktor:ktor-server-compression")
36+
implementation("io.dropwizard.metrics:metrics-core:4.1.18")
37+
implementation("io.ktor:ktor-server-metrics")
38+
implementation("io.ktor:ktor-server-netty")
39+
40+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
41+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kotlin.code.style=official
2+
ktor_version=2.3.12
3+
kotlin_version=2.0.20
4+
logback_version=1.5.19
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)