Skip to content

Commit

Permalink
Able to generate within parameter OpenAPITools#17158 (OpenAPITools#17623
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Rugal authored Jan 16, 2024
1 parent 26ab9e7 commit 287e8fc
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion modules/openapi-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.samskivert.mustache.Template;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenModel;
Expand Down Expand Up @@ -380,7 +383,7 @@ public void setUseTags(boolean useTags) {
}

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

public void setUseSpringBoot3(boolean isSpringBoot3) {
Expand Down Expand Up @@ -906,6 +909,9 @@ public void setReturnContainer(final String returnContainer) {

final List<CodegenParameter> allParams = operation.allParams;
if (allParams != null) {
if (this.isAppendRequestToHandler()) {
allParams.add(new RequestCodegenParameter(true));
}
allParams.forEach(param ->
// This is necessary in case 'modelMutable' is enabled,
// to prevent Spring Request handlers from being generated with
Expand Down Expand Up @@ -996,4 +1002,11 @@ protected boolean needToImport(String type) {
// provides extra protection against improperly trying to import language primitives and java types
return !type.startsWith("org.springframework.") && super.needToImport(type);
}

@AllArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
static class RequestCodegenParameter extends CodegenParameter {
boolean isRequestObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#appendRequestToHandler}}, serverHttpRequest: ServerHttpRequest{{/appendRequestToHandler}}): ResponseEntity<{{>returnTypes}}> {
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>requesObject}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}> {
return {{>returnValue}}
}
{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}{{#appendRequestToHandler}}, serverHttpRequest: ServerHttpRequest{{/appendRequestToHandler}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultInterface}} {
{{#reactive}}{{^isArray}}suspend {{/isArray}}{{/reactive}}fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>requesObject}}{{^-last}},{{/-last}}{{/allParams}}): ResponseEntity<{{>returnTypes}}>{{^skipDefaultInterface}} {
{{^isDelegate}}
return {{>returnValue}}
{{/isDelegate}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isRequestObject}}serverHttpRequest: ServerHttpRequest{{/isRequestObject}}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface PetApi {
value = ["/pet"],
consumes = ["application/json", "application/xml"]
)
fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -72,7 +72,7 @@ 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> {
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 ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -92,7 +92,7 @@ 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>> {
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 ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -112,7 +112,7 @@ 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>> {
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 ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -133,7 +133,7 @@ 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> {
fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long,serverHttpRequest: ServerHttpRequest): ResponseEntity<Pet> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -154,7 +154,7 @@ interface PetApi {
value = ["/pet"],
consumes = ["application/json", "application/xml"]
)
fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody body: Pet,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -173,7 +173,7 @@ 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> {
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 ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -193,7 +193,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 detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?, serverHttpRequest: ServerHttpRequest): ResponseEntity<ModelApiResponse> {
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 detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?,serverHttpRequest: ServerHttpRequest): ResponseEntity<ModelApiResponse> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface StoreApi {
method = [RequestMethod.DELETE],
value = ["/store/order/{orderId}"]
)
fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -71,7 +71,7 @@ interface StoreApi {
value = ["/store/inventory"],
produces = ["application/json"]
)
fun getInventory(, serverHttpRequest: ServerHttpRequest): ResponseEntity<Map<String, kotlin.Int>> {
fun getInventory(serverHttpRequest: ServerHttpRequest): ResponseEntity<Map<String, kotlin.Int>> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -91,7 +91,7 @@ interface StoreApi {
value = ["/store/order/{orderId}"],
produces = ["application/xml", "application/json"]
)
fun getOrderById(@Min(1L) @Max(5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long, serverHttpRequest: ServerHttpRequest): ResponseEntity<Order> {
fun getOrderById(@Min(1L) @Max(5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long,serverHttpRequest: ServerHttpRequest): ResponseEntity<Order> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -110,7 +110,7 @@ interface StoreApi {
value = ["/store/order"],
produces = ["application/xml", "application/json"]
)
fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order, serverHttpRequest: ServerHttpRequest): ResponseEntity<Order> {
fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody body: Order,serverHttpRequest: ServerHttpRequest): ResponseEntity<Order> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface UserApi {
method = [RequestMethod.POST],
value = ["/user"]
)
fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody body: User,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -68,7 +68,7 @@ interface UserApi {
method = [RequestMethod.POST],
value = ["/user/createWithArray"]
)
fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List<User>, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List<User>,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -85,7 +85,7 @@ interface UserApi {
method = [RequestMethod.POST],
value = ["/user/createWithList"]
)
fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List<User>, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody body: kotlin.collections.List<User>,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -103,7 +103,7 @@ interface UserApi {
method = [RequestMethod.DELETE],
value = ["/user/{username}"]
)
fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -123,7 +123,7 @@ interface UserApi {
value = ["/user/{username}"],
produces = ["application/xml", "application/json"]
)
fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String, serverHttpRequest: ServerHttpRequest): ResponseEntity<User> {
fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String,serverHttpRequest: ServerHttpRequest): ResponseEntity<User> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -142,7 +142,7 @@ interface UserApi {
value = ["/user/login"],
produces = ["application/xml", "application/json"]
)
fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String, serverHttpRequest: ServerHttpRequest): ResponseEntity<kotlin.String> {
fun loginUser(@NotNull @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String,serverHttpRequest: ServerHttpRequest): ResponseEntity<kotlin.String> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -159,7 +159,7 @@ interface UserApi {
method = [RequestMethod.GET],
value = ["/user/logout"]
)
fun logoutUser(, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun logoutUser(serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}

Expand All @@ -177,7 +177,7 @@ interface UserApi {
method = [RequestMethod.PUT],
value = ["/user/{username}"]
)
fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User, serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody body: User,serverHttpRequest: ServerHttpRequest): ResponseEntity<Unit> {
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
}
}

0 comments on commit 287e8fc

Please sign in to comment.