-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest-client-from-swagger): Generate reactive http client from sw… (
#409) * feat(rest-client-from-swagger): Generate reactive http client from swagger file
- Loading branch information
1 parent
d088e47
commit 50d6717
Showing
35 changed files
with
242 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/swagger/codegen/v3/generators/RestControllerCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.swagger.codegen.v3.generators; | ||
|
||
import io.swagger.codegen.v3.CodegenType; | ||
|
||
public class RestControllerCodegen extends AbstractScaffoldCodegen { | ||
|
||
public RestControllerCodegen() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public CodegenType getTag() { | ||
return CodegenType.SERVER; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RestController"; | ||
} | ||
|
||
@Override | ||
public String getHelp() { | ||
return "Generates a entry point rest with RestController."; | ||
} | ||
|
||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
apiTemplateFiles.put("apiController.mustache", "Controller.java"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/swagger/codegen/v3/generators/WebClientCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.swagger.codegen.v3.generators; | ||
|
||
public class WebClientCodegen extends AbstractScaffoldCodegen { | ||
|
||
public WebClientCodegen() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "WebClient"; | ||
} | ||
|
||
@Override | ||
public String getHelp() { | ||
return "Generates an entrypoint rest with WebClient."; | ||
} | ||
|
||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
apiTemplateFiles.put("apiClientReactive.mustache", ".java"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/swagger/codegen/v3/generators/WebFluxRouterCodegen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.swagger.codegen.v3.generators; | ||
|
||
public class WebFluxRouterCodegen extends AbstractScaffoldCodegen { | ||
|
||
public WebFluxRouterCodegen() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "WebFlux"; | ||
} | ||
|
||
@Override | ||
public String getHelp() { | ||
return "Generates an entrypoint rest with WebFlux."; | ||
} | ||
|
||
@Override | ||
public void processOpts() { | ||
super.processOpts(); | ||
apiTemplateFiles.put("apiHandler.mustache", "Handler.java"); | ||
apiTemplateFiles.put("apiRouter.mustache", "Router.java"); | ||
} | ||
} |
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
src/main/resources/commons/rest-from-swagger/apiClientReactive.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package {{package}}; | ||
|
||
{{#imports}}import {{import}}; | ||
{{/imports}} | ||
|
||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
{{^fullJavaUtil}} | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
{{/fullJavaUtil}} | ||
{{#lombok}} | ||
import lombok.extern.log4j.Log4j2; | ||
import lombok.AllArgsConstructor; | ||
{{/lombok}} | ||
|
||
{{#operations}} | ||
{{#lombok}} | ||
@Log4j2 | ||
@AllArgsConstructor | ||
{{/lombok}} | ||
@Service | ||
public class {{classname}} { | ||
private final WebClient client; | ||
{{^lombok}} | ||
private static final Logger log = LoggerFactory.getLogger({{classname}}Controller.class); | ||
|
||
public {{classname}}(WebClient client) { | ||
this.client = client; | ||
} | ||
{{/lombok}} | ||
|
||
{{#operation}} | ||
{{#contents}} | ||
/** | ||
* Build call for {{operationId}}{{#parameters}} | ||
* @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/parameters}} | ||
* @return Mono<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> response | ||
{{#externalDocs}} | ||
* {{description}} | ||
* @see <a href="{{url}}">{{summary}} Documentation</a> | ||
{{/externalDocs}} | ||
*/ | ||
public Mono<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}Request({{#parameters}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) { | ||
return client.method(HttpMethod.{{httpMethod}}) | ||
.uri("{{{path}}}"{{#pathParams}}, {{{paramName}}}{{/pathParams}}){{#headerParams}} | ||
.header("{{baseName}}", {{paramName}}){{/headerParams}}{{#consumes}}{{#@first}} | ||
.contentType(MediaType.parseMediaType("{{{mediaType}}}")){{/@first}}{{/consumes}}{{^isForm}}{{#bodyParam}} | ||
.body(BodyInserters.fromValue({{paramName}})){{/bodyParam}}{{/isForm}}{{#isForm}}{{#formParams}} | ||
{{#@first}}.body(BodyInserters.fromFormData("{{baseName}}", {{paramName}}){{/@first}}{{^@first}} .with("{{baseName}}", {{paramName}}){{/@first}}{{#@last}}){{/@last}}{{/formParams}}{{/isForm}} | ||
{{#produces}}{{#@first}}.accept(MediaType.parseMediaType("{{{mediaType}}}")) | ||
{{/@first}}{{/produces}}.retrieve() | ||
.bodyToMono({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}.class); | ||
} | ||
{{/contents}} | ||
{{/operation}} | ||
} | ||
{{/operations}} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.