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 @@ -155,7 +155,17 @@ import okhttp3.MultipartBody
{{/-first}}
{{/prioritizedContentTypes}}
{{/formParams}}
{{^isBodyAllowed}}
{{#hasBodyOrFormParams}}
@HTTP(method = "{{httpMethod}}", path = "{{{path}}}", hasBody = true)
{{/hasBodyOrFormParams}}
{{^hasBodyOrFormParams}}
@{{httpMethod}}("{{{path}}}")
{{/hasBodyOrFormParams}}
{{/isBodyAllowed}}
{{#isBodyAllowed}}
@{{httpMethod}}("{{{path}}}")
{{/isBodyAllowed}}
{{^nonPublicApi}}{{#explicitApi}}public {{/explicitApi}}{{/nonPublicApi}}{{^doNotUseRxAndCoroutines}}{{#useCoroutines}}suspend {{/useCoroutines}}{{/doNotUseRxAndCoroutines}}fun {{operationId}}({{^allParams}}){{/allParams}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/allParams}}{{#returnType}}: {{/returnType}}{{^returnType}}{{#useResponseAsReturnType}}: {{/useResponseAsReturnType}}{{/returnType}}{{^doNotUseRxAndCoroutines}}{{#useRxJava}}Observable<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}>{{/useRxJava}}{{#useRxJava2}}{{#returnType}}Single<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava2}}{{#useRxJava3}}{{#returnType}}Single<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}>{{/returnType}}{{^returnType}}Completable{{/returnType}}{{/useRxJava3}}{{#useCoroutines}}{{#useResponseAsReturnType}}Response<{{/useResponseAsReturnType}}{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{^returnType}}{{#useResponseAsReturnType}}Unit{{/useResponseAsReturnType}}{{/returnType}}{{/isResponseFile}}{{#useResponseAsReturnType}}>{{/useResponseAsReturnType}}{{/useCoroutines}}{{/doNotUseRxAndCoroutines}}{{#doNotUseRxAndCoroutines}}Call<{{#isResponseFile}}ResponseBody{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{^returnType}}Unit{{/returnType}}{{/isResponseFile}}>{{/doNotUseRxAndCoroutines}}

{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ 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 testRetrofit2DeleteWithBodyUsesHttpAnnotation_25454() throws IOException {
OpenAPI openAPI = readOpenAPI("src/test/resources/3_0/kotlin/issue25454-delete-with-body.yaml");

KotlinClientCodegen codegen = createCodegen(ClientLibrary.JVM_RETROFIT2);

ClientOptInput input = createClientOptInput(openAPI, codegen);

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

List<File> files = generator.opts(input).generate();
File defaultApi = files.stream().filter(file -> file.getName().equals("DefaultApi.kt")).findAny().orElseThrow();
List<String> lines = Files.readAllLines(defaultApi.toPath()).stream().map(String::trim).collect(Collectors.toList());

// Retrofit rejects @Body, @FormUrlEncoded and @Multipart on @DELETE, so these need @HTTP with hasBody
assertFileContainsLine(lines, "@HTTP(method = \"DELETE\", path = \"items\", hasBody = true)");
assertFileContainsLine(lines, "@HTTP(method = \"DELETE\", path = \"items/form\", hasBody = true)");
// operations without a body, and methods that allow a body, keep the short annotation
assertFileContainsLine(lines, "@DELETE(\"items/{id}\")");
assertFileContainsLine(lines, "@POST(\"items\")");
}

@Test
public void testOptionalParamsHaveDefaultNullJvmKtor() throws IOException {
OpenAPI openAPI = readOpenAPI("3_0/kotlin/petstore.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
openapi: 3.0.3
info:
title: Repro
version: 1.0.0
paths:
/items:
delete:
operationId: deleteItems
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/DeleteItemsRequest"
responses:
"204":
description: Deleted
post:
operationId: createItems
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/DeleteItemsRequest"
responses:
"204":
description: Created
/items/form:
delete:
operationId: deleteItemsForm
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
id:
type: string
responses:
"204":
description: Deleted
/items/{id}:
delete:
operationId: deleteItem
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"204":
description: Deleted
components:
schemas:
DeleteItemsRequest:
type: object
required: [ids]
properties:
ids:
type: array
items:
type: string
Loading