Skip to content

[Kotlin] Allow other content-types when only interested in status-code / Unit #19801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 7, 2024
Merged
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 @@ -167,8 +167,11 @@ import com.squareup.moshi.adapter
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ internal open class ApiClient(val baseUrl: String, val client: Call.Factory = de
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ open class ApiClient(val baseUrl: String, val client: Call.Factory = defaultClie
val body = response.body
if(body == null) {
return null
}
if (T::class.java == File::class.java) {
} else if (T::class.java == Unit::class.java) {
// No need to parse the body when we're not interested in the body
// Useful when API is returning other Content-Type
return null
} else if (T::class.java == File::class.java) {
// return tempFile
val contentDisposition = response.header("Content-Disposition")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,6 @@ public function fakeEnumEndpointWithHttpInfo(

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

switch($statusCode) {
case 200:
Expand Down Expand Up @@ -592,6 +580,19 @@ public function fakeEnumEndpointWithHttpInfo(
];
}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = '\OpenAPI\Client\Model\EnumClass';
if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'])) {
$content = $response->getBody(); //stream goes to serializer
Expand Down
25 changes: 13 additions & 12 deletions samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,18 +529,6 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

switch($statusCode) {
case 200:
Expand Down Expand Up @@ -572,6 +560,19 @@ public function fakeEnumEndpointWithHttpInfo($enum_class, $enum_class_array, $en
];
}

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

$returnType = '\OpenAPI\Client\Model\EnumClass';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
Expand Down
Loading