Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit d11490f

Browse files
committed
Adds kotlin petstore sample
1 parent 9e824ae commit d11490f

File tree

2,337 files changed

+260082
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,337 files changed

+260082
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build/
2+
.gradle/
3+
.idea/
4+
target/
5+
6+
# gradle wrapper
7+
gradlew
8+
gradlew.bat
9+
gradle/
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/openapi-json-schema-tools/openapi-json-schema-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

samples/client/petstore/kotlin/.openapi-generator/FILES

Lines changed: 2000 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unset

samples/client/petstore/kotlin/README.md

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import org.checkerframework.gradle.plugin.CheckerFrameworkExtension
2+
3+
plugins {
4+
`java-library`
5+
`maven-publish`
6+
id("org.checkerframework") version "0.6.33"
7+
}
8+
9+
repositories {
10+
mavenLocal()
11+
maven {
12+
url = uri("https://repo.maven.apache.org/maven2/")
13+
}
14+
}
15+
16+
dependencies {
17+
implementation("org.checkerframework:checker-qual:3.42.0")
18+
implementation("com.google.code.gson:gson:2.10.1")
19+
testImplementation("junit:junit:4.13.2")
20+
checkerFramework("org.checkerframework:checker:3.42.0")
21+
}
22+
23+
configure<CheckerFrameworkExtension> {
24+
checkers = listOf(
25+
"org.checkerframework.checker.nullness.NullnessChecker"
26+
)
27+
}
28+
29+
group = "org.openapijsonschematools"
30+
version = "1.0.0"
31+
description = "OpenAPI Kotlin"
32+
33+
val testsJar by tasks.registering(Jar::class) {
34+
archiveClassifier = "tests"
35+
from(sourceSets["test"].output)
36+
}
37+
38+
java {
39+
toolchain {
40+
languageVersion.set(JavaLanguageVersion.of(17))
41+
}
42+
withSourcesJar()
43+
withJavadocJar()
44+
}
45+
46+
publishing {
47+
publications.create<MavenPublication>("maven") {
48+
from(components["java"])
49+
artifact(testsJar)
50+
}
51+
}
52+
53+
tasks.wrapper {
54+
gradleVersion = "8.7"
55+
}
56+
57+
tasks.withType<JavaCompile>() {
58+
options.encoding = "UTF-8"
59+
}
60+
61+
tasks.withType<Javadoc>() {
62+
enabled = false
63+
options.encoding = "UTF-8"
64+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# RootServerInfo
2+
RootServerInfo.java
3+
4+
public class RootServerInfo
5+
6+
A class that provides a server, and any needed server info classes
7+
- a class that is a ServerProvider
8+
- a builder for the ServerProvider
9+
- an enum class that stores server index values
10+
11+
## Nested Class Summary
12+
| Modifier and Type | Class and Description |
13+
| ----------------- | --------------------- |
14+
| static class | [RootServerInfo.RootServerInfo1](#rootserverinfo1)<br>class that stores a server index |
15+
| static class | [RootServerInfo.RootServerInfoBuilder](#rootserverinfobuilder)<br>class that stores a server index |
16+
| enum | [RootServerInfo.ServerIndex](#serverindex)<br>class that stores a server index |
17+
18+
## RootServerInfo1
19+
implements ServerProvider<[ServerIndex](#serverindex)><br>
20+
21+
A class that stores servers and allows one to be returned with a ServerIndex instance
22+
23+
### Constructor Summary
24+
| Constructor and Description |
25+
| --------------------------- |
26+
| RootServerInfo1(@Nullable [RootServer0](servers/RootServer0.md) server0,@Nullable [RootServer1](servers/RootServer1.md) server1,@Nullable [RootServer2](servers/RootServer2.md) server2)<br>Creates an instance using passed in servers |
27+
28+
### Field Summary
29+
| Modifier and Type | Field and Description |
30+
| ----------------- | --------------------- |
31+
| [RootServer0](servers/RootServer0.md) | server0 |
32+
| [RootServer1](servers/RootServer1.md) | server1 |
33+
| [RootServer2](servers/RootServer2.md) | server2 |
34+
35+
### Method Summary
36+
| Modifier and Type | Method and Description |
37+
| ----------------- | ---------------------- |
38+
| Server | getServer([ServerIndex](#serverindex) serverIndex) |
39+
40+
## RootServerInfoBuilder
41+
42+
a builder for [RootServerInfo1](#rootserverinfo1)
43+
44+
### Constructor Summary
45+
| Constructor and Description |
46+
| --------------------------- |
47+
| RootServerInfoBuilder()<br>Creates an instance |
48+
49+
### Method Summary
50+
| Modifier and Type | Method and Description |
51+
| ----------------- | ---------------------- |
52+
| [RootServerInfoBuilder](#rootserverinfobuilder) | rootServer0([RootServer0](servers/RootServer0.md) server0)<br>sets the server |
53+
| [RootServerInfoBuilder](#rootserverinfobuilder) | rootServer1([RootServer1](servers/RootServer1.md) server1)<br>sets the server |
54+
| [RootServerInfoBuilder](#rootserverinfobuilder) | rootServer2([RootServer2](servers/RootServer2.md) server2)<br>sets the server |
55+
| [RootServerInfo1](#rootserverinfo1) | build() |
56+
57+
## ServerIndex
58+
enum ServerIndex<br>
59+
60+
### Enum Constant Summary
61+
| Enum Constant And Description |
62+
| ----------------------------- |
63+
| SERVER_0<br>server 0 |
64+
| SERVER_1<br>server 1 |
65+
| SERVER_2<br>server 2 |
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Anotherfakedummy
2+
3+
public class Anotherfakedummy extends extends ApiClient implements
4+
[AnotherfakedummyPatch.PatchOperation](../../paths/anotherfakedummy/AnotherfakedummyPatch.md#patchoperation)
5+
6+
an api client class which contains all the routes for path="/another-fake/dummy"
7+
8+
## Method Summary
9+
| Modifier and Type | Method and Description |
10+
| ----------------- | ---------------------- |
11+
| [AnotherfakedummyPatchResponses.EndpointResponse](../../paths/anotherfakedummy/patch/AnotherfakedummyPatchResponses.md#endpointresponse) | [patch](#patch)([AnotherfakedummyPatch.PatchRequest](../../paths/anotherfakedummy/AnotherfakedummyPatch.md#patchrequest) request)<br>To test special tags and operation ID starting with number |
12+
13+
## Method Detail
14+
15+
### patch
16+
public [AnotherfakedummyPatchResponses.EndpointResponse](../../paths/anotherfakedummy/patch/AnotherfakedummyPatchResponses.md#endpointresponse) patch([AnotherfakedummyPatch.PatchRequest](../../paths/anotherfakedummy/AnotherfakedummyPatch.md#patchrequest) request)
17+
18+
To test special tags and operation ID starting with number
19+
20+
**Parameters:**<br>
21+
request - the input request
22+
23+
**Returns:**<br>
24+
the deserialized response
25+
26+
**Throws:**<br>
27+
IOException, InterruptedException - an exception happened when making the request<br>
28+
ValidationException - the returned response body or header values do not conform the the schema validation requirements<br>
29+
NotImplementedException - the request body serialization or deserialization has not yet been implemented<br>
30+
or the header content type deserialization has not yet been implemented for this contentType<br>
31+
ApiException - server returned a response/contentType not defined in the openapi document<br>
32+
33+
#### Code Sample
34+
```
35+
import org.openapijsonschematools.client.configurations.ApiConfiguration;
36+
import org.openapijsonschematools.client.configurations.SchemaConfiguration;
37+
import org.openapijsonschematools.client.configurations.JsonSchemaKeywordFlags;
38+
import org.openapijsonschematools.client.exceptions.ValidationException;
39+
import org.openapijsonschematools.client.exceptions.NotImplementedException;
40+
import org.openapijsonschematools.client.exceptions.ApiException;
41+
import org.openapijsonschematools.client.schemas.validation.MapUtils;
42+
import org.openapijsonschematools.client.schemas.validation.FrozenList;
43+
import org.openapijsonschematools.client.schemas.validation.FrozenMap;
44+
import org.openapijsonschematools.client.RootServerInfo;
45+
import org.openapijsonschematools.client.paths.anotherfakedummy.patch.AnotherfakedummyPatchRequestBody;
46+
import org.openapijsonschematools.client.components.schemas.Client;
47+
import org.openapijsonschematools.client.servers.RootServer0;
48+
import org.openapijsonschematools.client.servers.RootServer1;
49+
import org.openapijsonschematools.client.servers.RootServer2;
50+
import org.openapijsonschematools.client.paths.anotherfakedummy.patch.responses.AnotherfakedummyPatchCode200Response;
51+
import org.openapijsonschematools.client.servers.RootServerInfo;
52+
import org.openapijsonschematools.client.apis.paths.Anotherfakedummy;
53+
import org.openapijsonschematools.client.paths.anotherfakedummy.patch.AnotherfakedummyPatchResponses;
54+
55+
import java.io.IOException;
56+
import java.util.Arrays;
57+
import java.util.List;
58+
import java.util.Map;
59+
import java.util.AbstractMap;
60+
61+
// if you want to use a server that is not SERVER_0 pass it in here and change the ServerIndex input below
62+
ApiConfiguration.ServerInfo serverInfo = new ApiConfiguration.ServerInfoBuilder()
63+
.rootServerInfo(
64+
new RootServerInfo.RootServerInfoBuilder()
65+
.rootServer0(new RootServer0())
66+
.build()
67+
)
68+
.build();
69+
ApiConfiguration.ServerIndexInfo serverIndexInfo = new ApiConfiguration.ServerIndexInfoBuilder()
70+
.rootServerInfoServerIndex(RootServerInfo.ServerIndex.SERVER_0)
71+
.build();
72+
Duration timeout = Duration.ofSeconds(1L);
73+
Map<String, List<String>> defaultHeaders = Map.of("User-Agent", List.of("OpenAPI-JSON-Schema-Generator/1.0.0/java"));
74+
ApiConfiguration apiConfiguration = new ApiConfiguration(
75+
serverInfo
76+
serverIndexInfo,
77+
timeout,
78+
defaultHeaders
79+
);
80+
SchemaConfiguration schemaConfiguration = new SchemaConfiguration(new JsonSchemaKeywordFlags.Builder().build());
81+
Anotherfakedummy apiClient = new Anotherfakedummy(apiConfiguration, schemaConfiguration);
82+
83+
84+
Client1BoxedMap requestBodyPayload =
85+
Client.Client1.validateAndBox(
86+
new Client.ClientMapBuilder1()
87+
.client("a")
88+
89+
.build(),
90+
schemaConfiguration
91+
);
92+
AnotherfakedummyPatchRequestBody.SealedRequestBody requestBody = new AnotherfakedummyPatchRequestBody.ApplicationjsonRequestBody(requestBodyPayload);
93+
94+
var request = new AnotherfakedummyPatch.PatchRequestBuilder()
95+
.requestBody(requestBody)
96+
.build();
97+
98+
AnotherfakedummyPatchResponses.EndpointResponse response;
99+
try {
100+
response = apiClient.patch(request);
101+
} catch (ApiException e) {
102+
// server returned a response/contentType not defined in the openapi document
103+
throw e;
104+
} catch (ValidationException e) {
105+
// the returned response body or header values do not conform the the schema validation requirements
106+
throw e;
107+
} catch (IOException | InterruptedException e) {
108+
// an exception happened when making the request
109+
throw e;
110+
} catch (NotImplementedException e) {
111+
// the request body serialization or deserialization has not yet been implemented
112+
// or the header content type deserialization has not yet been implemented for this contentType
113+
throw e;
114+
}
115+
AnotherfakedummyPatchResponses.EndpointAnotherfakedummyPatchCode200Response castResponse = (AnotherfakedummyPatchResponses.EndpointAnotherfakedummyPatchCode200Response) response;
116+
AnotherfakedummyPatchCode200Response.ApplicationjsonResponseBody deserializedBody = (AnotherfakedummyPatchCode200Response.ApplicationjsonResponseBody) castResponse.body;
117+
// handle deserialized body here
118+
```
119+
[[Back to top]](#top) [[Back to README]](../../../README.md)

0 commit comments

Comments
 (0)