Skip to content

Commit 6cf946b

Browse files
authored
asyncapi-generator: authentication and README.md (#77)
1 parent 2ceaa63 commit 6cf946b

File tree

7 files changed

+280
-85
lines changed

7 files changed

+280
-85
lines changed

plugins/asyncapi-generator/README.md

Lines changed: 227 additions & 79 deletions
Large diffs are not rendered by default.

plugins/asyncapi-generator/src/main/java/io/zenwave360/sdk/plugins/AsyncAPIGeneratorPlugin.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@
1515
mainOptions = {
1616
"apiFile",
1717
"role",
18-
"style",
18+
"templates",
1919
"modelPackage",
2020
"producerApiPackage",
2121
"consumerApiPackage",
2222
"apiPackage",
23+
"operationIds",
24+
"excludeOperationIds",
2325
"transactionalOutbox",
26+
"jsonschema2pojo",
27+
"avroCompilerProperties",
2428
"bindingPrefix",
2529
"bindingSuffix",
2630
"generatedAnnotationClass",
27-
"jsonschema2pojo",
28-
"avroCompilerProperties"
31+
2932
},
30-
hiddenOptions = {"layout", "apiFiles", "zdlFile", "zdlFiles"})
33+
hiddenOptions = {"layout", "apiFiles", "zdlFile", "zdlFiles", "style"})
3134
public class AsyncAPIGeneratorPlugin extends Plugin {
3235

3336
public AsyncAPIGeneratorPlugin() {

plugins/asyncapi-generator/src/test/java/io/zenwave360/sdk/plugins/kafka/AsyncAPIGeneratorAvroTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,24 @@ public void test_generate_asyncapi_avro_from_http() throws Exception {
155155
Assertions.assertTrue(new File(targetFolder + "/src/main/java/io/example/api/avro/Address.java").exists());
156156
}
157157

158+
@Test
159+
public void test_generate_asyncapi_avro_from_playground() throws Exception {
160+
String targetFolder = "target/out/asyncapi_avro_from_playground";
161+
String baseUrl = "https://raw.githubusercontent.com/ZenWave360/zenwave-playground/refs/heads/main/examples/asyncapi/apis";
162+
Plugin plugin = new AsyncAPIGeneratorPlugin()
163+
.withApiFile(baseUrl + "/asyncapi-avro-refs.yml")
164+
.withTargetFolder(targetFolder)
165+
.withOption("avroCompilerProperties.imports", List.of(
166+
baseUrl + "/avro/Address.avsc",
167+
baseUrl + "/avro/PaymentMethod.avsc",
168+
baseUrl + "/avro/PaymentMethodType.avsc"))
169+
.withOption("producerApiPackage", "io.example.api.producer")
170+
.withOption("role", AsyncapiRoleType.provider)
171+
.withOption("style", ProgrammingStyle.imperative)
172+
.withOption("skipFormatting", false);
173+
174+
new MainGenerator().generate(plugin);
175+
176+
}
158177

159178
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<reflections.version>0.10.2</reflections.version>
5757
<handlebars-java.version>4.3.1</handlebars-java.version>
5858
<json-path.version>2.9.0</json-path.version>
59-
<json-schema-ref-parser-jvm.version>0.9.0</json-schema-ref-parser-jvm.version>
59+
<json-schema-ref-parser-jvm.version>1.0.0-SNAPSHOT</json-schema-ref-parser-jvm.version>
6060
<zdl-jvm.version>1.3.0</zdl-jvm.version>
6161
<graphql-java.version>19.2</graphql-java.version>
6262
<google-java-format.version>1.25.2</google-java-format.version>

zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/Plugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Map;
99
import java.util.Optional;
1010

11+
import io.zenwave360.jsonrefparser.AuthenticationValue;
1112
import io.zenwave360.sdk.zdl.layouts.DefaultProjectLayout;
1213
import io.zenwave360.sdk.zdl.layouts.ProjectLayout;
1314
import org.apache.commons.lang3.ClassUtils;
@@ -38,10 +39,13 @@ public class Plugin {
3839
@DocumentedOption(description = "API Spec files to parse (comma separated)")
3940
public List<String> apiFiles;
4041

42+
@DocumentedOption(description = "Authentication configuration values for fetching remote resources.")
43+
public List<AuthenticationValue> authentication = List.of();
44+
4145
@DocumentedOption(description = "Target folder for generated output")
4246
public String targetFolder;
4347

44-
private List<Class> chain;
48+
private List<Class> chainXX;
4549

4650
private boolean forceOverwrite = false;
4751

@@ -50,6 +54,7 @@ public class Plugin {
5054
private ClassLoader projectClassLoader;
5155

5256
public static Plugin of(String pluginConfigAsString) throws Exception {
57+
System.out.println("of: " + pluginConfigAsString);
5358
if (pluginConfigAsString != null) {
5459
if (pluginConfigAsString.contains(".")) {
5560
return (Plugin) Plugin.class.getClassLoader().loadClass(pluginConfigAsString).getDeclaredConstructor().newInstance();
@@ -78,6 +83,7 @@ private static Plugin ofSimpleClassName(String simpleClassName) {
7883
return pluginClass.getDeclaredConstructor().newInstance();
7984
} catch (Exception ignored) {
8085
// ignore
86+
System.out.println("ignored: " + ignored.getMessage() + " " + simpleClassName);
8187
}
8288
}
8389
return null;
@@ -163,6 +169,12 @@ public Plugin withZdlFiles(List<String> zdlFiles) {
163169
return this;
164170
}
165171

172+
public Plugin withAuthentication(List<AuthenticationValue> authentication) {
173+
this.authentication = authentication;
174+
this.options.put("authentication", this.authentication);
175+
return this;
176+
}
177+
166178
public Plugin withTargetFolder(String targetFolder) {
167179
if (targetFolder != null) {
168180
this.targetFolder = targetFolder;

zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/parsers/DefaultYamlParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import java.io.IOException;
77
import java.net.URI;
88
import java.util.LinkedHashMap;
9+
import java.util.List;
910
import java.util.Map;
1011

12+
import io.zenwave360.jsonrefparser.AuthenticationValue;
1113
import io.zenwave360.sdk.doc.DocumentedOption;
1214
import io.zenwave360.jsonrefparser.$RefParser;
1315
import io.zenwave360.jsonrefparser.$RefParserOptions;
@@ -23,6 +25,9 @@ public class DefaultYamlParser implements io.zenwave360.sdk.parsers.Parser {
2325
public URI apiFile;
2426
public String targetProperty = "api";
2527

28+
@DocumentedOption(description = "Authentication configuration values for fetching remote resources.")
29+
public List<AuthenticationValue> authentication = List.of();
30+
2631
private ClassLoader projectClassLoader;
2732

2833
@DocumentedOption(description = "API Specification File (@deprecated use apiFile)")
@@ -63,6 +68,7 @@ public Map<String, Object> parse() throws IOException {
6368
if(apiFile != null) {
6469
$RefParser parser = new $RefParser(apiFile)
6570
.withResourceClassLoader(this.projectClassLoader)
71+
// .withAuthenticationValues(authentication)
6672
.withOptions(new $RefParserOptions().withOnCircular(SKIP).withOnMissing(OnMissing.SKIP));
6773
model.put(targetProperty, new Model(apiFile, parser.parse().dereference().mergeAllOf().getRefs()));
6874
} else {

zenwave-sdk-maven-plugin/src/main/java/io/zenwave360/sdk/GeneratorMojo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.*;
77
import java.util.stream.Collectors;
88

9+
import io.zenwave360.jsonrefparser.AuthenticationValue;
910
import org.apache.commons.lang3.StringUtils;
1011
import org.apache.maven.artifact.Artifact;
1112
import org.apache.maven.plugin.AbstractMojo;
@@ -48,6 +49,11 @@ public class GeneratorMojo extends AbstractMojo {
4849
@Parameter(name = "zdlFiles", property = "zenwave.zdlFiles")
4950
private String[] zdlFiles;
5051

52+
/**
53+
* Authentication configuration values for fetching remote resources.
54+
*/
55+
@Parameter(name = "authentication", property = "zenwave.authentication")
56+
private List<AuthenticationValue> authentication = List.of();
5157

5258
/**
5359
* Location of the output directory.
@@ -136,6 +142,7 @@ public void execute() throws MojoExecutionException {
136142
Plugin plugin = Plugin.of(this.generatorName)
137143
.withApiFile(apiFile)
138144
.withZdlFiles(zdls)
145+
.withAuthentication(authentication)
139146
.withTargetFolder(targetFolder.getAbsolutePath())
140147
.withProjectClassLoader(projectClassLoader)
141148
.withOptions(options);

0 commit comments

Comments
 (0)