Skip to content

Commit d5b63e6

Browse files
committed
Add types and links
1 parent a193f7c commit d5b63e6

File tree

17 files changed

+881
-228
lines changed

17 files changed

+881
-228
lines changed

docs/domains/Domain.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"type": "object",
5757
"properties": {
5858
"channelName": {
59-
"description": "Name of channel. default\u0027 refers to the admin server\u0027s default channel (configured via the ServerMBean\u0027s ListenPort) \u0027default-secure\u0027 refers to the admin server\u0027s default secure channel (configured via the ServerMBean\u0027s SSLMBean\u0027s ListenPort) \u0027default-admin\u0027 refers to the admin server\u0027s default administrative channel (configured via the DomainMBean\u0027s AdministrationPort) Otherwise, the name is the name of one of the admin server\u0027s network access points (configured via the ServerMBean\u0027s NetworkAccessMBeans).",
59+
"description": "Name of channel.\ndefault\u0027 refers to the admin server\u0027s default channel (configured via the ServerMBean\u0027s ListenPort) \n\u0027default-secure\u0027 refers to the admin server\u0027s default secure channel (configured via the ServerMBean\u0027s SSLMBean\u0027s ListenPort) \n\u0027default-admin\u0027 refers to the admin server\u0027s default administrative channel (configured via the DomainMBean\u0027s AdministrationPort) \nOtherwise, the name is the name of one of the admin server\u0027s network access points (configured via the ServerMBean\u0027s NetworkAccessMBeans).",
6060
"type": "string"
6161
},
6262
"nodePort": {

docs/domains/Domain.md

Lines changed: 129 additions & 119 deletions
Large diffs are not rendered by default.

docs/domains/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@
977977
"type": "object",
978978
"properties": {
979979
"channelName": {
980-
"description": "Name of channel. default\u0027 refers to the admin server\u0027s default channel (configured via the ServerMBean\u0027s ListenPort) \u0027default-secure\u0027 refers to the admin server\u0027s default secure channel (configured via the ServerMBean\u0027s SSLMBean\u0027s ListenPort) \u0027default-admin\u0027 refers to the admin server\u0027s default administrative channel (configured via the DomainMBean\u0027s AdministrationPort) Otherwise, the name is the name of one of the admin server\u0027s network access points (configured via the ServerMBean\u0027s NetworkAccessMBeans).",
980+
"description": "Name of channel.\ndefault\u0027 refers to the admin server\u0027s default channel (configured via the ServerMBean\u0027s ListenPort) \n\u0027default-secure\u0027 refers to the admin server\u0027s default secure channel (configured via the ServerMBean\u0027s SSLMBean\u0027s ListenPort) \n\u0027default-admin\u0027 refers to the admin server\u0027s default administrative channel (configured via the DomainMBean\u0027s AdministrationPort) \nOtherwise, the name is the name of one of the admin server\u0027s network access points (configured via the ServerMBean\u0027s NetworkAccessMBeans).",
981981
"type": "string"
982982
},
983983
"nodePort": {

docs/domains/k8s1.9.0.md

Lines changed: 283 additions & 0 deletions
Large diffs are not rendered by default.

json-schema-maven-plugin/src/main/java/oracle/kubernetes/json/mojo/JsonSchemaMojo.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.URL;
1111
import java.util.Collections;
1212
import java.util.List;
13+
import java.util.Map;
1314
import java.util.Optional;
1415
import org.apache.maven.plugin.AbstractMojo;
1516
import org.apache.maven.plugin.MojoExecutionException;
@@ -72,13 +73,20 @@ public void execute() throws MojoExecutionException {
7273

7374
if (updateNeeded(new File(classUrl.getPath()), getSchemaFile())) {
7475
getLog().info("Changes detected -- generating schema for " + rootClass + ".");
75-
main.generateSchema(rootClass, getSchemaFile());
76-
if (generateMarkdown) main.generateMarkdown(getMarkdownFile());
76+
generate();
7777
} else {
7878
getLog().info("Schema up-to-date. Skipping generation.");
7979
}
8080
}
8181

82+
private void generate() throws MojoExecutionException {
83+
Map<String, Object> generatedSchema = main.generateSchema(rootClass, getSchemaFile());
84+
if (generateMarkdown) {
85+
getLog().info(" -- generating markdown for " + rootClass + ".");
86+
main.generateMarkdown("Domain", getMarkdownFile(), generatedSchema);
87+
}
88+
}
89+
8290
private void addExternalSchemas() throws MojoExecutionException {
8391
try {
8492
if (kubernetesVersion != null) main.setKubernetesVersion(kubernetesVersion);

json-schema-maven-plugin/src/main/java/oracle/kubernetes/json/mojo/Main.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88
import java.io.IOException;
99
import java.net.URL;
10+
import java.util.Map;
1011
import org.apache.maven.plugin.MojoExecutionException;
1112

1213
public interface Main {
@@ -75,13 +76,17 @@ public interface Main {
7576
* @param outputFile the file to generate
7677
* @throws MojoExecutionException if an exception occurred during the schema generation
7778
*/
78-
void generateSchema(String className, File outputFile) throws MojoExecutionException;
79+
Map<String, Object> generateSchema(String className, File outputFile)
80+
throws MojoExecutionException;
7981

8082
/**
8183
* Generates markdown for the newly-generated schema to the specified output file.
8284
*
85+
* @param rootName
8386
* @param outputFile the file to generate
87+
* @param schema
8488
* @throws MojoExecutionException if an exception occurred during the markdown generation
8589
*/
86-
void generateMarkdown(File outputFile) throws MojoExecutionException;
90+
void generateMarkdown(String rootName, File outputFile, Map<String, Object> schema)
91+
throws MojoExecutionException;
8792
}

json-schema-maven-plugin/src/main/java/oracle/kubernetes/json/mojo/MainImpl.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class MainImpl implements Main {
1818
private SchemaGenerator generator = new SchemaGenerator();
1919
private ClassLoader classLoader;
20-
private Map<String, Object> schema;
20+
private String kubernetesVersion;
2121

2222
@Override
2323
public void setIncludeDeprecated(boolean includeDeprecated) {
@@ -46,6 +46,7 @@ public URL getResource(String name) {
4646

4747
@Override
4848
public void setKubernetesVersion(String kubernetesVersion) throws IOException {
49+
this.kubernetesVersion = kubernetesVersion;
4950
generator.useKubernetesVersion(kubernetesVersion);
5051
}
5152

@@ -56,12 +57,14 @@ public void defineSchemaUrlAndContents(URL schemaURL, URL cacheUrl) throws IOExc
5657

5758
@SuppressWarnings("ResultOfMethodCallIgnored")
5859
@Override
59-
public void generateSchema(String className, File outputFile) throws MojoExecutionException {
60+
public Map<String, Object> generateSchema(String className, File outputFile)
61+
throws MojoExecutionException {
6062
outputFile.getParentFile().mkdirs();
6163
try (FileWriter writer = new FileWriter(outputFile)) {
6264
Class<?> theClass = classLoader.loadClass(className);
63-
schema = generator.generate(theClass);
65+
Map<String, Object> schema = generator.generate(theClass);
6466
writer.write(SchemaGenerator.prettyPrint(schema));
67+
return schema;
6568
} catch (IOException e) {
6669
throw new MojoExecutionException("Error generating schema", e);
6770
} catch (ClassNotFoundException e) {
@@ -71,11 +74,24 @@ public void generateSchema(String className, File outputFile) throws MojoExecuti
7174

7275
@SuppressWarnings("ResultOfMethodCallIgnored")
7376
@Override
74-
public void generateMarkdown(File outputFile) throws MojoExecutionException {
77+
public void generateMarkdown(String rootName, File outputFile, Map<String, Object> schema)
78+
throws MojoExecutionException {
7579
outputFile.getParentFile().mkdirs();
7680

81+
YamlDocGenerator generator = new YamlDocGenerator(schema);
7782
try (FileWriter writer = new FileWriter(outputFile)) {
78-
writer.write(new YamlDocGenerator(schema).generate("Domain", schema));
83+
if (kubernetesVersion != null) generator.useKubernetesVersion(kubernetesVersion);
84+
writer.write(generator.generate(rootName));
85+
} catch (IOException e) {
86+
throw new MojoExecutionException("Error generating markdown", e);
87+
}
88+
89+
String kubernetesSchemaMarkdownFile = generator.getKubernetesSchemaMarkdownFile();
90+
if (kubernetesSchemaMarkdownFile == null) return;
91+
92+
File kubernetesFile = new File(outputFile.getParent(), kubernetesSchemaMarkdownFile);
93+
try (FileWriter writer = new FileWriter(kubernetesFile)) {
94+
writer.write(generator.getKubernetesSchemaMarkdown());
7995
} catch (IOException e) {
8096
throw new MojoExecutionException("Error generating markdown", e);
8197
}

json-schema-maven-plugin/src/test/java/oracle/kubernetes/json/mojo/JsonSchemaMojoTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.hamcrest.Matchers.*;
1212
import static org.objectweb.asm.Opcodes.ASM5;
1313

14+
import com.google.common.collect.ImmutableMap;
1415
import com.meterware.simplestub.Memento;
1516
import com.meterware.simplestub.StaticStubSupport;
1617
import java.io.File;
@@ -302,14 +303,25 @@ public void whenGenerateMarkdownNotSpecified_dontGenerateMarkdown() throws Excep
302303
}
303304

304305
@Test
305-
public void whenGenerateMarkdownSpecified_denerateMarkdown() throws Exception {
306+
public void whenGenerateMarkdownSpecified_generateMarkdown() throws Exception {
306307
setMojoParameter("generateMarkdown", true);
307308

308309
mojo.execute();
309310

310311
assertThat(main.getMarkdownFile(), equalTo(MARKDOWN_FILE));
311312
}
312313

314+
@Test
315+
public void whenGenerateMarkdownSpecified_useGeneratedSchemaForMarkdown() throws Exception {
316+
ImmutableMap<String, Object> generatedSchema = ImmutableMap.of();
317+
main.setGeneratedSchema(generatedSchema);
318+
setMojoParameter("generateMarkdown", true);
319+
320+
mojo.execute();
321+
322+
assertThat(main.getMarkdownSchema(), sameInstance(generatedSchema));
323+
}
324+
313325
@Test
314326
public void whenSchemaMoreRecentThanClassFile_dontGenerateNewSchema() throws Exception {
315327
fileSystem.defineFileContents(CLASS_FILE, "");

json-schema-maven-plugin/src/test/java/oracle/kubernetes/json/mojo/TestMain.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class TestMain implements Main {
2222
private boolean includeAdditionalProperties;
2323
private boolean supportObjectReferences;
2424
private File markdownFile;
25+
private Map<String, Object> schema;
26+
private Map<String, Object> markdownSchema;
2527

2628
TestMain() throws MalformedURLException {
2729
classpathResource = new URL("file:abc");
@@ -55,6 +57,14 @@ File getMarkdownFile() {
5557
return markdownFile;
5658
}
5759

60+
public Map<String, Object> getMarkdownSchema() {
61+
return markdownSchema;
62+
}
63+
64+
void setGeneratedSchema(Map<String, Object> schema) {
65+
this.schema = schema;
66+
}
67+
5868
URL getCacheFor(URL schemaUrl) {
5969
return schemas.get(schemaUrl);
6070
}
@@ -108,13 +118,15 @@ public URL getResource(String name) {
108118
}
109119

110120
@Override
111-
public void generateSchema(String className, File outputFile) {
121+
public Map<String, Object> generateSchema(String className, File outputFile) {
112122
this.className = className;
113123
this.schemaFile = outputFile;
124+
return schema;
114125
}
115126

116127
@Override
117-
public void generateMarkdown(File markdownFile) {
128+
public void generateMarkdown(String rootName, File markdownFile, Map<String, Object> schema) {
118129
this.markdownFile = markdownFile;
130+
this.markdownSchema = schema;
119131
}
120132
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2019 Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.json;
6+
7+
import java.net.MalformedURLException;
8+
import java.net.URL;
9+
10+
public class KubernetesSchemaReference {
11+
private static final String K8S_SCHEMA_URL =
12+
"https://github.com/garethr/kubernetes-json-schema/blob/master/v%s/_definitions.json";
13+
private static final String K8S_SCHEMA_CACHE = "caches/kubernetes-%s.json";
14+
private static final String K8S_MARKDOWN_LINK = "k8s%s.md";
15+
16+
private String version;
17+
18+
private KubernetesSchemaReference(String version) {
19+
this.version = version;
20+
}
21+
22+
public static KubernetesSchemaReference create(String version) {
23+
return new KubernetesSchemaReference(version);
24+
}
25+
26+
URL getKubernetesSchemaUrl() throws MalformedURLException {
27+
return new URL(getUrlString());
28+
}
29+
30+
private String getUrlString() {
31+
return String.format(K8S_SCHEMA_URL, version);
32+
}
33+
34+
boolean matchesUrl(String url) {
35+
return url.equals(getUrlString());
36+
}
37+
38+
public URL getKubernetesSchemaCacheUrl() {
39+
return KubernetesSchemaReference.class.getResource(String.format(K8S_SCHEMA_CACHE, version));
40+
}
41+
42+
String getK8sMarkdownLink() {
43+
return String.format(K8S_MARKDOWN_LINK, version);
44+
}
45+
}

0 commit comments

Comments
 (0)