Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
{{#returnType}}
@Suppress("UNCHECKED_CAST")
{{/returnType}}
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> {
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{{dataType}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}}{{^required}} = null{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}): HttpResponse<{{{returnType}}}{{^returnType}}Unit{{/returnType}}> {

val localVariableAuthNames = listOf<String>({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface {{classname}}Service {
{{/externalDocs}}
* @see {{classname}}#{{operationId}}
*/
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}): {{>returnTypes}}
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{/isArray}}{{/reactive}}{{/isBodyParam}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}}{{^required}} = null{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}): {{>returnTypes}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface {{classname}}Service {
{{/externalDocs}}
* @see {{classname}}#{{operationId}}
*/
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}ctx: Context): {{>returnTypes}}
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{{paramName}}}: {{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{/isArray}}{{/reactive}}{{/isBodyParam}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{^defaultValue}}{{^required}} = null{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}ctx: Context): {{>returnTypes}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ public void testUseResponseAsReturnType(Object useResponseAsReturnType, String e
assertFileContainsLine(lines, "suspend fun deletePet(@Path(\"petId\") petId: kotlin.Long, @Header(\"api_key\") apiKey: kotlin.String? = null)" + expectedUnitResponse);
}

@Test
public void testOptionalParamsHaveDefaultNullJvmKtor() throws IOException {
OpenAPI openAPI = readOpenAPI("3_0/kotlin/petstore.yaml");

KotlinClientCodegen codegen = createCodegen(ClientLibrary.JVM_KTOR);

ClientOptInput input = createClientOptInput(openAPI, codegen);

DefaultGenerator generator = new DefaultGenerator();
enableOnlyApiGeneration(generator);

List<File> files = generator.opts(input).generate();
File petApi = files.stream().filter(file -> file.getName().equals("PetApi.kt")).findAny().orElseThrow();

assertFileContains(petApi.toPath(), "apiKey: kotlin.String? = null");
}

@Test
public void testEnumDefaultForReferencedSchemaParameterJvmOkhttp4() throws IOException {
OpenAPI openAPI = readOpenAPI("3_0/kotlin/enum-default-query.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import java.text.DateFormat
* @param status2 number type (optional)
* @return void
*/
open suspend fun updatePetWithFormNumber(petId: kotlin.Long, name: kotlin.String?, status: kotlin.Int?, status2: java.math.BigDecimal?): HttpResponse<Unit> {
open suspend fun updatePetWithFormNumber(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.Int? = null, status2: java.math.BigDecimal? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import java.text.DateFormat
* @param apiKey (optional)
* @return void
*/
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): HttpResponse<Unit> {
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -253,7 +253,7 @@ import java.text.DateFormat
* @param status Updated status of the pet (optional)
* @return void
*/
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): HttpResponse<Unit> {
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -292,7 +292,7 @@ import java.text.DateFormat
* @return ModelApiResponse
*/
@Suppress("UNCHECKED_CAST")
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>?): HttpResponse<ModelApiResponse> {
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>? = null): HttpResponse<ModelApiResponse> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
* @param apiKey (optional)
* @return void
*/
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): HttpResponse<Unit> {
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -249,7 +249,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
* @param status Updated status of the pet (optional)
* @return void
*/
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): HttpResponse<Unit> {
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -288,7 +288,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
* @return ModelApiResponse
*/
@Suppress("UNCHECKED_CAST")
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>?): HttpResponse<ModelApiResponse> {
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>? = null): HttpResponse<ModelApiResponse> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import io.ktor.http.ParametersBuilder
* @param apiKey (optional)
* @return void
*/
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): HttpResponse<Unit> {
open suspend fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -248,7 +248,7 @@ import io.ktor.http.ParametersBuilder
* @param status Updated status of the pet (optional)
* @return void
*/
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): HttpResponse<Unit> {
open suspend fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null): HttpResponse<Unit> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down Expand Up @@ -287,7 +287,7 @@ import io.ktor.http.ParametersBuilder
* @return ModelApiResponse
*/
@Suppress("UNCHECKED_CAST")
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>?): HttpResponse<ModelApiResponse> {
open suspend fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: io.ktor.client.request.forms.FormPart<io.ktor.client.request.forms.InputProvider>? = null): HttpResponse<ModelApiResponse> {

val localVariableAuthNames = listOf<String>("petstore_auth")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface PetApiService {
* @return Invalid pet value (status code 400)
* @see PetApi#deletePet
*/
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?, ctx: Context): Unit
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null, ctx: Context): Unit

/**
* GET /pet/findByStatus : Finds Pets by status
Expand Down Expand Up @@ -95,7 +95,7 @@ interface PetApiService {
* @return Invalid input (status code 405)
* @see PetApi#updatePetWithForm
*/
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?, ctx: Context): Unit
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null, ctx: Context): Unit

/**
* POST /pet/{petId}/uploadImage : uploads an image
Expand All @@ -108,5 +108,5 @@ interface PetApiService {
* @return successful operation (status code 200)
* @see PetApi#uploadFile
*/
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.javalin.http.UploadedFile?, ctx: Context): ModelApiResponse
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: io.javalin.http.UploadedFile? = null, ctx: Context): ModelApiResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface PetApiService {
* @return Invalid pet value (status code 400)
* @see PetApi#deletePet
*/
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String? = null): Unit

/**
* GET /pet/findByStatus : Finds Pets by status
Expand Down Expand Up @@ -87,7 +87,7 @@ interface PetApiService {
* @return Invalid input (status code 405)
* @see PetApi#updatePetWithForm
*/
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String? = null, status: kotlin.String? = null): Unit

/**
* POST /pet/{petId}/uploadImage : uploads an image
Expand All @@ -99,5 +99,5 @@ interface PetApiService {
* @return successful operation (status code 200)
* @see PetApi#uploadFile
*/
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: io.javalin.http.UploadedFile?): ModelApiResponse
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String? = null, file: io.javalin.http.UploadedFile? = null): ModelApiResponse
}
Loading