Skip to content

Commit 9a6fa8c

Browse files
authored
[kotlin] add more tests to cover nonPublicApi, explicitApi options (#23864)
* add tests for kotlin nonPublicApi, explicitApi * update workflow * update samples
1 parent 117c5e8 commit 9a6fa8c

111 files changed

Lines changed: 5390 additions & 1 deletion

File tree

Some content is hidden

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

.github/workflows/samples-kotlin-client.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ on:
77
- 'samples/client/others/kotlin-jvm-okhttp-parameter-tests/**'
88
- samples/client/others/kotlin-integer-enum/**
99
- samples/client/others/kotlin-jvm-spring-3-restclient-nullable-return/**
10+
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization*/**
11+
- samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization*/**
1012
pull_request:
1113
paths:
1214
- 'samples/client/petstore/kotlin*/**'
1315
- 'samples/client/others/kotlin-jvm-okhttp-parameter-tests/**'
1416
- samples/client/others/kotlin-integer-enum/**
15-
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization/**
1617
- samples/client/others/kotlin-jvm-spring-3-restclient-nullable-return/**
18+
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization*/**
19+
- samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization*/**
1720

1821
jobs:
1922
build:
@@ -78,6 +81,8 @@ jobs:
7881
- samples/client/petstore/kotlin-allOf-discriminator-kotlinx-serialization
7982
- samples/client/others/kotlin-oneOf-discriminator-kotlinx-serialization
8083
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization
84+
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization-nonPublicApi
85+
- samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization-explicitApi
8186
steps:
8287
- uses: actions/checkout@v5
8388
- uses: actions/setup-java@v5
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization-explicitApi
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/oneof-anyof-non-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
5+
additionalProperties:
6+
artifactId: kotlin-oneOf-anyOf-kotlinx-serialization
7+
serializableModel: "false"
8+
dateLibrary: java8
9+
library: jvm-retrofit2
10+
enumUnknownDefaultCase: true
11+
serializationLibrary: kotlinx_serialization
12+
generateOneOfAnyOfWrappers: true
13+
explicitApi: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/others/kotlin-oneOf-anyOf-kotlinx-serialization-nonPublicApi
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/oneof-anyof-non-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
5+
additionalProperties:
6+
artifactId: kotlin-oneOf-anyOf-kotlinx-serialization
7+
serializableModel: "false"
8+
dateLibrary: java8
9+
library: jvm-retrofit2
10+
enumUnknownDefaultCase: true
11+
serializationLibrary: kotlinx_serialization
12+
generateOneOfAnyOfWrappers: true
13+
nonPublicApi: true
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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
README.md
2+
build.gradle
3+
docs/AnyOfUserOrPet.md
4+
docs/AnyOfUserOrPetOrArrayString.md
5+
docs/BooleanOrLong.md
6+
docs/Pet.md
7+
docs/StringOrLong.md
8+
docs/TestApi.md
9+
docs/User.md
10+
docs/UserOrPet.md
11+
docs/UserOrPetOrArrayString.md
12+
gradle/wrapper/gradle-wrapper.jar
13+
gradle/wrapper/gradle-wrapper.properties
14+
gradlew
15+
gradlew.bat
16+
proguard-rules.pro
17+
settings.gradle
18+
src/main/kotlin/org/openapitools/client/apis/TestApi.kt
19+
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
20+
src/main/kotlin/org/openapitools/client/infrastructure/AtomicBooleanAdapter.kt
21+
src/main/kotlin/org/openapitools/client/infrastructure/AtomicIntegerAdapter.kt
22+
src/main/kotlin/org/openapitools/client/infrastructure/AtomicLongAdapter.kt
23+
src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
24+
src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
25+
src/main/kotlin/org/openapitools/client/infrastructure/CollectionFormats.kt
26+
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
27+
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateTimeAdapter.kt
28+
src/main/kotlin/org/openapitools/client/infrastructure/OffsetDateTimeAdapter.kt
29+
src/main/kotlin/org/openapitools/client/infrastructure/ResponseExt.kt
30+
src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt
31+
src/main/kotlin/org/openapitools/client/infrastructure/StringBuilderAdapter.kt
32+
src/main/kotlin/org/openapitools/client/infrastructure/URIAdapter.kt
33+
src/main/kotlin/org/openapitools/client/infrastructure/URLAdapter.kt
34+
src/main/kotlin/org/openapitools/client/infrastructure/UUIDAdapter.kt
35+
src/main/kotlin/org/openapitools/client/models/AnyOfUserOrPet.kt
36+
src/main/kotlin/org/openapitools/client/models/AnyOfUserOrPetOrArrayString.kt
37+
src/main/kotlin/org/openapitools/client/models/BooleanOrLong.kt
38+
src/main/kotlin/org/openapitools/client/models/Pet.kt
39+
src/main/kotlin/org/openapitools/client/models/StringOrLong.kt
40+
src/main/kotlin/org/openapitools/client/models/User.kt
41+
src/main/kotlin/org/openapitools/client/models/UserOrPet.kt
42+
src/main/kotlin/org/openapitools/client/models/UserOrPetOrArrayString.kt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.23.0-SNAPSHOT
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# org.openapitools.client - Kotlin client library for oneOf/anyOf non-discriminator example
2+
3+
Test non-discriminator oneOf and anyOf with model, primitive, and array types
4+
5+
## Overview
6+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client.
7+
8+
- API version: 0.1
9+
- Package version:
10+
- Generator version: 7.23.0-SNAPSHOT
11+
- Build package: org.openapitools.codegen.languages.KotlinClientCodegen
12+
13+
## Requires
14+
15+
* Kotlin 2.2.20
16+
* Gradle 8.14
17+
18+
## Build
19+
20+
First, create the gradle wrapper script:
21+
22+
```
23+
gradle wrapper
24+
```
25+
26+
Then, run:
27+
28+
```
29+
./gradlew check assemble
30+
```
31+
32+
This runs all tests and packages the library.
33+
34+
## Features/Implementation Notes
35+
36+
* Supports JSON inputs/outputs, File inputs, and Form inputs.
37+
* Supports collection formats for query parameters: csv, tsv, ssv, pipes.
38+
* Some Kotlin and Java types are fully qualified to avoid conflicts with types defined in OpenAPI definitions.
39+
* Implementation of ApiClient is intended to reduce method counts, specifically to benefit Android targets.
40+
41+
<a id="documentation-for-api-endpoints"></a>
42+
## Documentation for API Endpoints
43+
44+
All URIs are relative to *http://example.org*
45+
46+
| Class | Method | HTTP request | Description |
47+
| ------------ | ------------- | ------------- | ------------- |
48+
| *TestApi* | [**getAnyOf**](docs/TestApi.md#getanyof) | **GET** v1/test/anyOf | |
49+
| *TestApi* | [**getAnyOfArray**](docs/TestApi.md#getanyofarray) | **GET** v1/test/anyOfArray | |
50+
| *TestApi* | [**getOneOf**](docs/TestApi.md#getoneof) | **GET** v1/test/oneOf | |
51+
| *TestApi* | [**getOneOfArray**](docs/TestApi.md#getoneofarray) | **GET** v1/test/oneOfArray | |
52+
| *TestApi* | [**getOneOfBooleanPrimitive**](docs/TestApi.md#getoneofbooleanprimitive) | **GET** v1/test/oneOfBooleanPrimitive | |
53+
| *TestApi* | [**getOneOfPrimitive**](docs/TestApi.md#getoneofprimitive) | **GET** v1/test/oneOfPrimitive | |
54+
55+
56+
<a id="documentation-for-models"></a>
57+
## Documentation for Models
58+
59+
- [org.openapitools.client.models.AnyOfUserOrPet](docs/AnyOfUserOrPet.md)
60+
- [org.openapitools.client.models.AnyOfUserOrPetOrArrayString](docs/AnyOfUserOrPetOrArrayString.md)
61+
- [org.openapitools.client.models.BooleanOrLong](docs/BooleanOrLong.md)
62+
- [org.openapitools.client.models.Pet](docs/Pet.md)
63+
- [org.openapitools.client.models.StringOrLong](docs/StringOrLong.md)
64+
- [org.openapitools.client.models.User](docs/User.md)
65+
- [org.openapitools.client.models.UserOrPet](docs/UserOrPet.md)
66+
- [org.openapitools.client.models.UserOrPetOrArrayString](docs/UserOrPetOrArrayString.md)
67+
68+
69+
<a id="documentation-for-authorization"></a>
70+
## Documentation for Authorization
71+
72+
Endpoints do not require authorization.
73+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
group 'org.openapitools'
2+
version '1.0.0'
3+
4+
wrapper {
5+
gradleVersion = '8.14.3'
6+
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
7+
}
8+
9+
buildscript {
10+
ext.kotlin_version = '2.2.20'
11+
ext.retrofitVersion = '3.0.0'
12+
ext.spotless_version = "7.2.1"
13+
14+
repositories {
15+
maven { url "https://repo1.maven.org/maven2" }
16+
}
17+
dependencies {
18+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19+
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
20+
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version"
21+
}
22+
}
23+
24+
apply plugin: 'kotlin'
25+
apply plugin: 'kotlinx-serialization'
26+
apply plugin: 'maven-publish'
27+
apply plugin: 'com.diffplug.spotless'
28+
29+
repositories {
30+
maven { url "https://repo1.maven.org/maven2" }
31+
}
32+
33+
// Use spotless plugin to automatically format code, remove unused import, etc
34+
// To apply changes directly to the file, run `gradlew spotlessApply`
35+
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
36+
spotless {
37+
// comment out below to run spotless as part of the `check` task
38+
enforceCheck false
39+
40+
format 'misc', {
41+
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
42+
target '.gitignore'
43+
44+
// define the steps to apply to those files
45+
trimTrailingWhitespace()
46+
indentWithSpaces() // Takes an integer argument if you don't like 4
47+
endWithNewline()
48+
}
49+
kotlin {
50+
ktfmt()
51+
}
52+
}
53+
54+
test {
55+
useJUnitPlatform()
56+
}
57+
58+
kotlin {
59+
explicitApi()
60+
}
61+
62+
dependencies {
63+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
64+
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0"
65+
implementation "com.squareup.okhttp3:logging-interceptor:5.1.0"
66+
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
67+
implementation "com.squareup.retrofit2:converter-kotlinx-serialization:$retrofitVersion"
68+
implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion"
69+
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
70+
}
71+
72+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
73+
kotlinOptions {
74+
freeCompilerArgs += "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
75+
}
76+
}
77+
78+
java {
79+
withSourcesJar()
80+
}
81+
82+
publishing {
83+
publications {
84+
maven(MavenPublication) {
85+
groupId = 'org.openapitools'
86+
artifactId = 'kotlin-oneOf-anyOf-kotlinx-serialization'
87+
version = '1.0.0'
88+
from components.java
89+
}
90+
}
91+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# AnyOfUserOrPet
3+
4+
## Properties
5+
| Name | Type | Description | Notes |
6+
| ------------ | ------------- | ------------- | ------------- |
7+
| **id** | **kotlin.Long** | | |
8+
| **username** | **kotlin.String** | | |
9+
| **name** | **kotlin.String** | | |
10+
11+
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# AnyOfUserOrPetOrArrayString
3+
4+
## Properties
5+
| Name | Type | Description | Notes |
6+
| ------------ | ------------- | ------------- | ------------- |
7+
| **id** | **kotlin.Long** | | |
8+
| **username** | **kotlin.String** | | |
9+
| **name** | **kotlin.String** | | |
10+
11+
12+

0 commit comments

Comments
 (0)