Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8efe999
Add optValue to CliOption
A-Joshi Mar 18, 2019
b5f4b6b
Use CliOption for classModifier, operationModifier, buildTarget, add …
A-Joshi Mar 18, 2019
c85b5bf
Make abstract method look cleaner
A-Joshi Mar 18, 2019
dd1d826
Add ASP.Net core 2.2
A-Joshi Mar 18, 2019
b70372b
update docs
A-Joshi Mar 18, 2019
0b15fac
fix java doc issue (#2435)
wing328 Mar 18, 2019
1f45ea7
[#2425] - implemented yaml parsing for config file. (#2434)
dragosnutu Mar 18, 2019
d93fd31
[dart] Fix authentication for dart (#2419)
dalewking Mar 19, 2019
93baa5d
Initial attempt at deploying to gradle plugin portal (#2440)
jimschubert Mar 19, 2019
43fcd19
add semi colon to gradle tasks
wing328 Mar 19, 2019
7ad479e
[C] Update README and adding object.c/h files (#2377)
zhemant Mar 19, 2019
3320d3c
Handle collection params in path (assume csv for now). (#2259)
jacobweber Mar 19, 2019
79d9388
Reformat code to meet PR feedback
A-Joshi Mar 19, 2019
1dd25ef
Fix compilation with ASP.Net Core 2.1
A-Joshi Mar 19, 2019
54041f2
Update docs
A-Joshi Mar 19, 2019
01c480d
Add optValue to CliOption
A-Joshi Mar 18, 2019
d1a089e
Use CliOption for classModifier, operationModifier, buildTarget, add …
A-Joshi Mar 18, 2019
58a3d2c
Make abstract method look cleaner
A-Joshi Mar 18, 2019
fb4f8b9
Add ASP.Net core 2.2
A-Joshi Mar 18, 2019
144d18c
update docs
A-Joshi Mar 18, 2019
b9513e9
Reformat code to meet PR feedback
A-Joshi Mar 19, 2019
4332298
Fix compilation with ASP.Net Core 2.1
A-Joshi Mar 19, 2019
d8b2bac
Update docs
A-Joshi Mar 19, 2019
53f217b
Merge branch 'feature/cleanup' of https://github.com/ihsmarkitoss/ope…
A-Joshi Mar 20, 2019
80a34b3
Fix build target error
A-Joshi Mar 20, 2019
04b66d0
Remove duplicated code
A-Joshi Mar 20, 2019
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
Prev Previous commit
Next Next commit
[#2425] - implemented yaml parsing for config file. (#2434)
  • Loading branch information
dragosnutu authored and wing328 committed Mar 18, 2019
commit 1f45ea7d1a0b63da18b0f46e3a3b55a2ecc83eef
15 changes: 14 additions & 1 deletion docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ and `config.json` contains the following as an example:
"apiPackage" : "petstore"
}
```
You can use also `config.yml` with following equivalent example:
```yaml
apiPackage: "petstore"
```

Supported config options can be different per language. Running `config-help -g {lang}` will show available options.
**These options are applied via configuration file (e.g. config.json) or by passing them with `-D{optionName}={optionValue}`**. (If `-D{optionName}` does not work, please open a [ticket](https://github.com/openapitools/openapi-generator/issues/new) and we'll look into it)
**These options are applied via configuration file (e.g. config.json or config.yml) or by passing them with `-D{optionName}={optionValue}`**. (If `-D{optionName}` does not work, please open a [ticket](https://github.com/openapitools/openapi-generator/issues/new) and we'll look into it)

```sh
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -g java
Expand Down Expand Up @@ -258,6 +262,15 @@ Your config file for Java can look like
}
```

Or if you preffer yaml format it can look like

```yaml
groupId: "com.my.company"
artifactId: "MyClient"
artifactVersion: "1.2.0"
library: "feign"
```

For all the unspecified options default values will be used.

Another way to override default options is to extend the config class for the specific language.
Expand Down
20 changes: 19 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ NOTE: `import-mappings` is assigned a key-value pair in this example, but multip

#### Configuration File

Rather than passing generator options in a CSV of `--additional-properties`, you may also provide the settings via JSON file.
Rather than passing generator options in a CSV of `--additional-properties`, you may also provide the settings via JSON file or YAML file.

For example, one of our typescript samples has the following configuration file:

Expand All @@ -500,3 +500,21 @@ These settings can be passed via `-c filename`. Here, we've saved the above as `
openapi-generator generate -i petstore.yaml -g typescript-fetch -o out \
-c config.json
```

Same configuration file can be passed into YAML format having following equivalent content:

```yaml
npmName: "@swagger/typescript-fetch-petstore"
npmVersion: "1.0.0"
npmRepository: "https://skimdb.npmjs.com/registry"
snapshot: false
supportsES6: true
```

The settings are passed exactly the same as for `config.json`. The most important part is the file extension. Supported values are `yml` or `yaml`.
The name of the file should be `config.yml` or `config.yaml` (in our example it will be `config.yaml`.

```bash
openapi-generator generate -i petstore.yaml -g typescript-fetch -o out \
-c config.yaml
```
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,14 +42,6 @@
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
*/
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void testSystemProperties() throws Exception {


@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");
Expand All @@ -237,6 +237,26 @@ public void testConfig() throws Exception {
};
}

@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 {

Expand Down
Loading