Skip to content

Commit

Permalink
Remove appendRequestToHandler (#19500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rugal authored Sep 4, 2024
1 parent 42d98e2 commit f54b0e2
Show file tree
Hide file tree
Showing 38 changed files with 85 additions and 1,296 deletions.
1 change: 0 additions & 1 deletion .github/workflows/samples-kotlin-server-jdk17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
# server
- samples/server/petstore/kotlin-springboot-3
- samples/server/petstore/kotlin-springboot-delegate-nodefaults
- samples/server/petstore/kotlin-springboot-request
- samples/server/petstore/kotlin-springboot-request-cookie
- samples/server/petstore/kotlin-server/javalin
- samples/server/petstore/kotlin-server/javalin-6
Expand Down
9 changes: 0 additions & 9 deletions bin/configs/kotlin-spring-boot-request.yaml

This file was deleted.

1 change: 0 additions & 1 deletion docs/generators/kotlin-spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|annotationLibrary|Select the complementary documentation annotation library.|<dl><dt>**none**</dt><dd>Do not annotate Model and Api with complementary annotations.</dd><dt>**swagger1**</dt><dd>Annotate Model and Api using the Swagger Annotations 1.x library.</dd><dt>**swagger2**</dt><dd>Annotate Model and Api using the Swagger Annotations 2.x library.</dd></dl>|swagger2|
|apiPackage|api package for generated code| |org.openapitools.api|
|apiSuffix|suffix for api classes| |Api|
|appendRequestToHandler|Append ServerHttpRequest to handler method for getting request stuff| |false|
|artifactId|Generated artifact id (name of jar).| |openapi-spring|
|artifactVersion|Generated artifact's package version.| |1.0.0|
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
public static final String BEAN_QUALIFIERS = "beanQualifiers";

public static final String USE_SPRING_BOOT3 = "useSpringBoot3";
public static final String APPEND_REQUEST_TO_HANDLER = "appendRequestToHandler";
public static final String REQUEST_MAPPING_OPTION = "requestMappingMode";
public static final String USE_REQUEST_MAPPING_ON_CONTROLLER = "useRequestMappingOnController";
public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface";
Expand Down Expand Up @@ -236,7 +235,6 @@ public KotlinSpringServerCodegen() {
"@RestController annotations. May be used to prevent bean names clash if multiple generated libraries" +
" (contexts) added to single project.", beanQualifiers);
addSwitch(USE_SPRING_BOOT3, "Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.", useSpringBoot3);
addSwitch(APPEND_REQUEST_TO_HANDLER, "Append ServerHttpRequest to handler method for getting request stuff", false);
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
Expand Down Expand Up @@ -356,10 +354,6 @@ public boolean getUseBeanValidation() {
return this.useBeanValidation;
}

public boolean isAppendRequestToHandler() {
return Boolean.parseBoolean(additionalProperties.getOrDefault(APPEND_REQUEST_TO_HANDLER, false).toString());
}

@Override
public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
Expand Down Expand Up @@ -889,9 +883,6 @@ public void setReturnContainer(final String returnContainer) {

final List<CodegenParameter> allParams = operation.allParams;
if (allParams != null) {
if (this.isAppendRequestToHandler()) {
allParams.add(new RequestCodegenParameter());
}
allParams.forEach(param ->
// This is necessary in case 'modelMutable' is enabled,
// to prevent Spring Request handlers from being generated with
Expand Down Expand Up @@ -983,22 +974,6 @@ protected boolean needToImport(String type) {
return !type.startsWith("org.springframework.") && super.needToImport(type);
}

@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
static class RequestCodegenParameter extends CodegenParameter {

boolean isRequestObject = true;

public RequestCodegenParameter() {
this.isOptional = false;
this.required = true;
this.paramName = "serverHttpRequest";
this.dataType = "ServerHttpRequest";
}

}

public RequestMappingMode getRequestMappingMode() {
return requestMappingMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired

{{#appendRequestToHandler}}
import org.springframework.http.server.reactive.ServerHttpRequest
{{/appendRequestToHandler}}
{{#useBeanValidation}}
import {{javaxPackage}}.validation.Valid
import {{javaxPackage}}.validation.constraints.DecimalMax
Expand Down Expand Up @@ -92,7 +89,7 @@ class {{classname}}Controller({{#serviceInterface}}@Autowired(required = true) v
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}},
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}}
)
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{>requesObject}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
return {{>returnValue}}
}
{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
{{#appendRequestToHandler}}
import org.springframework.http.server.reactive.ServerHttpRequest
{{/appendRequestToHandler}}

import org.springframework.web.bind.annotation.*
{{#useBeanValidation}}
Expand Down Expand Up @@ -103,7 +100,7 @@ interface {{classname}} {
produces = [{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}]{{/hasProduces}}{{#hasConsumes}},
consumes = [{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}]{{/hasConsumes}}{{/singleContentTypes}}
)
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{>requesObject}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultApiInterface}} {
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultApiInterface}} {
{{^isDelegate}}
return {{>returnValue}}
{{/isDelegate}}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import io.swagger.v3.oas.annotations.security.*
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.http.server.reactive.ServerHttpRequest

import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
Expand Down Expand Up @@ -58,8 +57,8 @@ interface PetApi {
produces = ["application/xml", "application/json"],
consumes = ["application/json", "application/xml"]
)
fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet,serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
return getDelegate().addPet(pet, serverHttpRequest)
fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity<Pet> {
return getDelegate().addPet(pet)
}

@Operation(
Expand All @@ -76,8 +75,8 @@ interface PetApi {
method = [RequestMethod.DELETE],
value = ["/pet/{petId}"]
)
fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return getDelegate().deletePet(petId, apiKey, serverHttpRequest)
fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity<Unit> {
return getDelegate().deletePet(petId, apiKey)
}

@Operation(
Expand All @@ -96,8 +95,8 @@ interface PetApi {
value = ["/pet/findByStatus"],
produces = ["application/xml", "application/json"]
)
fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>,serverHttpRequest: ServerHttpRequest): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByStatus(status, serverHttpRequest)
fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByStatus(status)
}

@Operation(
Expand All @@ -116,8 +115,8 @@ interface PetApi {
value = ["/pet/findByTags"],
produces = ["application/xml", "application/json"]
)
fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>,serverHttpRequest: ServerHttpRequest): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByTags(tags, serverHttpRequest)
fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByTags(tags)
}

@Operation(
Expand All @@ -137,8 +136,8 @@ interface PetApi {
value = ["/pet/{petId}"],
produces = ["application/xml", "application/json"]
)
fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long,serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
return getDelegate().getPetById(petId, serverHttpRequest)
fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity<Pet> {
return getDelegate().getPetById(petId)
}

@Operation(
Expand All @@ -160,8 +159,8 @@ interface PetApi {
produces = ["application/xml", "application/json"],
consumes = ["application/json", "application/xml"]
)
fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet,serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
return getDelegate().updatePet(pet, serverHttpRequest)
fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity<Pet> {
return getDelegate().updatePet(pet)
}

@Operation(
Expand All @@ -179,8 +178,8 @@ interface PetApi {
value = ["/pet/{petId}"],
consumes = ["application/x-www-form-urlencoded"]
)
fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return getDelegate().updatePetWithForm(petId, name, status, serverHttpRequest)
fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity<Unit> {
return getDelegate().updatePetWithForm(petId, name, status)
}

@Operation(
Expand All @@ -199,7 +198,7 @@ interface PetApi {
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.core.io.Resource?,serverHttpRequest: ServerHttpRequest): ResponseEntity<ModelApiResponse> {
return getDelegate().uploadFile(petId, additionalMetadata, file, serverHttpRequest)
fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.core.io.Resource?): ResponseEntity<ModelApiResponse> {
return getDelegate().uploadFile(petId, additionalMetadata, file)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ interface PetApiDelegate {
/**
* @see PetApi#addPet
*/
fun addPet(pet: Pet,
serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
fun addPet(pet: Pet): ResponseEntity<Pet> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand All @@ -46,8 +45,7 @@ interface PetApiDelegate {
* @see PetApi#deletePet
*/
fun deletePet(petId: kotlin.Long,
apiKey: kotlin.String?,
serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
apiKey: kotlin.String?): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)

}
Expand All @@ -56,8 +54,7 @@ interface PetApiDelegate {
/**
* @see PetApi#findPetsByStatus
*/
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>,
serverHttpRequest: ServerHttpRequest): ResponseEntity<List<Pet>> {
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand All @@ -78,8 +75,7 @@ interface PetApiDelegate {
/**
* @see PetApi#findPetsByTags
*/
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>,
serverHttpRequest: ServerHttpRequest): ResponseEntity<List<Pet>> {
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand All @@ -100,8 +96,7 @@ interface PetApiDelegate {
/**
* @see PetApi#getPetById
*/
fun getPetById(petId: kotlin.Long,
serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
fun getPetById(petId: kotlin.Long): ResponseEntity<Pet> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand All @@ -122,8 +117,7 @@ interface PetApiDelegate {
/**
* @see PetApi#updatePet
*/
fun updatePet(pet: Pet,
serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
fun updatePet(pet: Pet): ResponseEntity<Pet> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand All @@ -146,8 +140,7 @@ interface PetApiDelegate {
*/
fun updatePetWithForm(petId: kotlin.Long,
name: kotlin.String?,
status: kotlin.String?,
serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
status: kotlin.String?): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)

}
Expand All @@ -158,8 +151,7 @@ interface PetApiDelegate {
*/
fun uploadFile(petId: kotlin.Long,
additionalMetadata: kotlin.String?,
file: Resource?,
serverHttpRequest: ServerHttpRequest): ResponseEntity<ModelApiResponse> {
file: Resource?): ResponseEntity<ModelApiResponse> {
getRequest().ifPresent { request ->
for (mediaType in MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
Expand Down
Loading

0 comments on commit f54b0e2

Please sign in to comment.