[#2425] - implemented yaml parsing for config file. (#2434)

This commit is contained in:
dragosnutu
2019-03-18 15:49:45 +02:00
committed by William Cheng
parent 0b15fac3e1
commit 1f45ea7d1a
5 changed files with 181 additions and 83 deletions

View File

@@ -17,10 +17,23 @@
package org.openapitools.codegen.cmd;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvpList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvpList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsvList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvpList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applySystemPropertiesKvpList;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvpList;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.spi.FilterAttachable;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.DefaultGenerator;
@@ -29,14 +42,6 @@ import org.openapitools.codegen.config.CodegenConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.openapitools.codegen.config.CodegenConfiguratorUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* User: lanwen Date: 24.03.15 Time: 20:22
*/
@@ -82,8 +87,9 @@ public class Generate implements Runnable {
@Option(
name = {"-c", "--config"},
title = "configuration file",
description = "Path to json configuration file. "
+ "File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} "
description = "Path to configuration file configuration file. It can be json or yaml."
+ "If file is json, the content should have the format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...}."
+ "If file is yaml, the content should have the format optionKey: optionValue"
+ "Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options.")
private String configFile;

View File

@@ -218,7 +218,7 @@ public class GenerateTest {
@Test
public void testConfig() throws Exception {
public void testConfigJson() throws Exception {
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
"config.json", "-c", "config.json");
@@ -237,6 +237,26 @@ public class GenerateTest {
};
}
@Test
public void testConfigYaml() throws Exception {
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
"config.yaml", "-c", "config.yaml");
new FullVerifications() {
{
}
};
setupAndRunTest("-i", "src/test/resources/swagger.yaml", "-g", "java", "-o", "src/main/java", true,
"config.yaml", "--config", "config.yaml");
new FullVerifications() {
{
}
};
}
@Test
public void testSkipOverwrite() throws Exception {