forked from loafle/openapi-generator-original
[feat][docs][website] Initial docusaurus based site (#1770)
* Iniital docusaurus based site * Remove error about default local being used by String.format * Change pinned users to represent global presence rather than alphabetical order pinning * Include generator indexes in ensure-up-to-date (docusaurus site and /generators/README) * Add Font Awesome attribution footer * Remove feature callout until it is completed * Include NPM try it out section * Improve "Getting Started" type docs * Include new custom template documentation * Updating templating and customization docs * Add vendor extension docs * Cleanup templating page(s). * Move users to yaml file for easy edit. * travis configuration, and baseUrl mods to image URLs * [docs] Migrate FAQ, release summary from wiki FAQ has been split into multiple smaller documents to better categorize and allow users to find what they're looking for (in docs folder or in new website). Release summary information (versioning strategy and cadence) has been migrated from the Wiki and clarified a bit. Also adds copy button for all code snippets in website. * Copy current contributing/code of conduct to website * [docs] Creating a new generator
This commit is contained in:
committed by
William Cheng
parent
9cba9b6f88
commit
6fe9a52229
@@ -19,6 +19,7 @@ package org.openapitools.codegen.cmd;
|
||||
|
||||
import io.airlift.airline.Command;
|
||||
import io.airlift.airline.Option;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
@@ -28,10 +29,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
@Command(name = "config-help", description = "Config help for chosen lang")
|
||||
public class ConfigHelp implements Runnable {
|
||||
@@ -50,12 +52,20 @@ public class ConfigHelp implements Runnable {
|
||||
description = "Optionally write help to this location, otherwise default is standard output")
|
||||
private String outputFile;
|
||||
|
||||
@Option(name = {"-f", "--format"}, title = "output format",
|
||||
description = "Write output files in the desired format. Options are 'text' and 'markdown'. Default is 'text'.")
|
||||
private String format;
|
||||
|
||||
@Option(name = {"--markdown-header"}, title = "markdown header",
|
||||
description = "When format=markdown, include this option to write out markdown headers (e.g. for docusaurus).")
|
||||
private Boolean markdownHeader;
|
||||
|
||||
private String newline = System.lineSeparator();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (isEmpty(generatorName)) {
|
||||
System.err.println("[error] A generator name (--generator-name / -g) is required.");
|
||||
LOGGER.error("[error] A generator name (--generator-name / -g) is required.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -63,12 +73,18 @@ public class ConfigHelp implements Runnable {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
CodegenConfig config = CodegenConfigLoader.forName(generatorName);
|
||||
|
||||
generatePlainTextHelp(sb, config);
|
||||
if (StringUtils.isEmpty(format) || "text".equalsIgnoreCase(format)) {
|
||||
generatePlainTextHelp(sb, config);
|
||||
} else if ("markdown".equalsIgnoreCase(format)) {
|
||||
generateMarkdownHelp(sb, config);
|
||||
} else {
|
||||
LOGGER.warn("[warning] Unrecognized format option: %s.%n", format);
|
||||
}
|
||||
|
||||
if (!isEmpty(outputFile)) {
|
||||
File out = Paths.get(outputFile).toFile();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
out.mkdirs();
|
||||
out.getParentFile().mkdirs();
|
||||
|
||||
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), StandardCharsets.UTF_8));
|
||||
|
||||
@@ -78,14 +94,68 @@ public class ConfigHelp implements Runnable {
|
||||
System.out.print(sb.toString());
|
||||
}
|
||||
} catch (GeneratorNotFoundException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.err.println("[error] Check the spelling of the generator's name and try again.");
|
||||
LOGGER.error(e.getMessage());
|
||||
LOGGER.error("[error] Check the spelling of the generator's name and try again.");
|
||||
System.exit(1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void generateMarkdownHelp(StringBuilder sb, CodegenConfig config) {
|
||||
sb.append(newline);
|
||||
|
||||
if (Boolean.TRUE.equals(markdownHeader)) {
|
||||
sb.append("---").append(newline);
|
||||
sb.append("id: generator-opts-").append(config.getTag().toValue()).append("-").append(config.getName()).append(newline);
|
||||
sb.append("title: Config Options for ").append(generatorName).append(newline);
|
||||
sb.append("sidebar_label: ").append(generatorName).append(newline);
|
||||
sb.append("---").append(newline);
|
||||
} else {
|
||||
sb.append("## CONFIG OPTIONS");
|
||||
|
||||
if (Boolean.TRUE.equals(namedHeader)) {
|
||||
sb.append(" for <em>").append(generatorName).append("</em>").append(newline);
|
||||
}
|
||||
}
|
||||
|
||||
sb.append(newline);
|
||||
|
||||
sb.append("| Option | Description | Values | Default |").append(newline);
|
||||
sb.append("| ------ | ----------- | ------ | ------- |").append(newline);
|
||||
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
// start
|
||||
sb.append("|");
|
||||
|
||||
// option
|
||||
sb.append(escapeHtml4(langCliOption.getOpt())).append("|");
|
||||
// description
|
||||
sb.append(escapeHtml4(langCliOption.getDescription())).append("|");
|
||||
|
||||
// values
|
||||
Map<String, String> enums = langCliOption.getEnum();
|
||||
if (enums != null) {
|
||||
sb.append("<dl>");
|
||||
|
||||
for (Map.Entry<String, String> entry : enums.entrySet()) {
|
||||
sb.append("<dt>**").append(escapeHtml4(entry.getKey())).append("**</dt>");
|
||||
sb.append("<dd>").append(escapeHtml4(entry.getValue())).append("</dd>");
|
||||
}
|
||||
|
||||
sb.append("<dl>");
|
||||
} else {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append("|");
|
||||
|
||||
// default
|
||||
sb.append(escapeHtml4(langCliOption.getDefault())).append("|");
|
||||
|
||||
sb.append(newline);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePlainTextHelp(StringBuilder sb, CodegenConfig config) {
|
||||
sb.append(newline);
|
||||
sb.append("CONFIG OPTIONS");
|
||||
|
||||
@@ -22,6 +22,9 @@ public class ListGenerators implements Runnable {
|
||||
@Option(name = {"-s", "--short" }, description = "shortened output (suitable for scripting)")
|
||||
private Boolean shortened = false;
|
||||
|
||||
@Option(name = {"-d", "--docsite" }, description = "format for docusaurus site output", hidden = true)
|
||||
private Boolean docusaurus = false;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<CodegenConfig> generators = CodegenConfigLoader.getAll();
|
||||
@@ -37,7 +40,7 @@ public class ListGenerators implements Runnable {
|
||||
sb.append(generator.getName());
|
||||
}
|
||||
} else {
|
||||
List<CodegenType> types = Arrays.asList(CodegenType.values());
|
||||
CodegenType[] types = CodegenType.values();
|
||||
|
||||
sb.append("The following generators are available:");
|
||||
|
||||
@@ -60,11 +63,27 @@ public class ListGenerators implements Runnable {
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if(list.size() > 0) {
|
||||
sb.append(typeName).append(" generators:");
|
||||
if (docusaurus) {
|
||||
sb.append("## ").append(typeName).append(" generators");
|
||||
} else {
|
||||
sb.append(typeName).append(" generators:");
|
||||
}
|
||||
sb.append(System.lineSeparator());
|
||||
|
||||
list.stream()
|
||||
.forEach(generator -> sb.append(" - ").append(generator.getName()).append(System.lineSeparator()));
|
||||
list.forEach(generator -> {
|
||||
if (docusaurus) {
|
||||
sb.append("* ");
|
||||
String id = "generators/" + generator.getName();
|
||||
sb.append("[").append(generator.getName()).append("](").append(id).append(")");
|
||||
|
||||
// trailing space is important for markdown list formatting
|
||||
sb.append(" ");
|
||||
} else {
|
||||
sb.append(" - ");
|
||||
sb.append(generator.getName());
|
||||
}
|
||||
sb.append(System.lineSeparator());
|
||||
});
|
||||
|
||||
sb.append(System.lineSeparator());
|
||||
sb.append(System.lineSeparator());
|
||||
|
||||
Reference in New Issue
Block a user