Skip to content
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

#66 Generate multiple clients #71

Merged
merged 7 commits into from
Jun 21, 2022
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ As commented above, they both could be used at the same time, setting a double
<plugin>
<groupId>net.coru</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<id>asyncapi</id>
Expand Down Expand Up @@ -111,7 +111,7 @@ which the plugin is designed.
<plugin>
<groupId>net.coru</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down Expand Up @@ -464,7 +464,7 @@ file. Here is an example of a basic configuration:
<plugin>
<groupId>net.coru</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<executions>
<execution>
<goals>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>net.coru</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<packaging>maven-plugin</packaging>

<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public final class OpenapiMultiFileMojo extends AbstractMojo {
@Parameter(property = "fileSpecs")
private List<FileSpec> fileSpecs;

@Parameter(name = "clientPackage", property = "clientPackage")
private String clientPackage;

@Parameter(name = "overwriteModel", property = "overwriteModel", defaultValue = "true")
private Boolean overwriteModel;

Expand All @@ -82,7 +79,6 @@ public void execute() throws MojoExecutionException {
templateFactory = new TemplateFactory();
if (null != fileSpecs && !fileSpecs.isEmpty()) {
processFileSpec(fileSpecs);
createClients();
} else {
throw new MojoExecutionException("Code generation failed. Not exists FileSpec configuration to generate package and class");
}
Expand All @@ -97,7 +93,7 @@ private void processFileSpec(final List<FileSpec> fileSpecsList) throws MojoExec
final String filePathToSave = processPath(fileSpec.getApiPackage(), false);
project.addCompileSourceRoot(filePathToSave);
processFile(fileSpec, filePathToSave);

createClients(fileSpec);
} catch (final MojoExecutionException e) {
getLog().error(e);
throw new MojoExecutionException("Code generation failed. See above for the full exception.");
Expand All @@ -108,6 +104,7 @@ private void processFileSpec(final List<FileSpec> fileSpecsList) throws MojoExec
private void processFile(final FileSpec fileSpec, final String filePathToSave) throws MojoExecutionException {

final OpenAPI openAPI = OpenApiUtil.getPojoFromSwagger(fileSpec);
final String clientPackage = fileSpec.getClientPackage();

if (fileSpec.getCallMode()) {
templateFactory.setWebClientPackageName(StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE);
Expand All @@ -122,7 +119,8 @@ private void processFile(final FileSpec fileSpec, final String filePathToSave) t

}

private void createClients() {
private void createClients(final FileSpec fileSpec) {
final String clientPackage = fileSpec.getClientPackage();

if (isWebClient || isRestClient) {
final String clientPath = processPath(StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE, false);
Expand All @@ -134,17 +132,18 @@ private void createClients() {
if (isRestClient) {
templateFactory.fillTemplateRestClient(clientPath);
}
createAuthTemplates();
createAuthTemplates(fileSpec);
} catch (IOException | TemplateException e) {
e.printStackTrace();
}
}
}

private void createAuthTemplates() throws TemplateException, IOException {

private void createAuthTemplates(final FileSpec fileSpec) throws TemplateException, IOException {
final String clientPackage = fileSpec.getClientPackage();
final var authFileRoot = (StringUtils.isNotBlank(clientPackage) ? clientPackage : DEFAULT_OPENAPI_CLIENT_PACKAGE) + ".auth";
final String authFileToSave = processPath(authFileRoot, false);

templateFactory.setAuthPackageName(authFileRoot);
templateFactory.fillTemplateAuth(authFileToSave, "Authentication");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class FileSpec {
@Parameter(name = "modelNameSuffix", property = "modelNameSuffix")
private String modelNameSuffix;

@Parameter(name = "clientPackage", property = "clientPackage")
private String clientPackage;

@Parameter(name = "callMode", property = "callMode")
private Boolean callMode = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
<inputSpec>api-test.yml</inputSpec>
<apiPackage>net.coru.multifileplugin.testclientpackage</apiPackage>
<modelPackage>net.coru.multifileplugin.testclientpackage.model</modelPackage>
<clientPackage>net.coru.multifileplugin.testclientpackage.client</clientPackage>
<callMode>true</callMode>
</fileSpec>
</fileSpecs>
<clientPackage>net.coru.multifileplugin.testclientpackage.client</clientPackage>
</configuration>
</plugin>
</plugins>
Expand Down