[all] Adds strict spec option (#2783)

* [all] Adds strict spec option

Introduces an option to allow user customization of strict specification
behaviors. For instance, OpenAPI 3.x requires a path object name to be
prefixed with '/' so we append any missing '/', but this may not be
desirable to some users or generators. In this commit, this fix specifically is
the only modification affected.

* Clarify strict-spec docs, add option to README.md

* Update CLI options in docs/usage.md
This commit is contained in:
Jim Schubert
2019-05-03 10:57:47 -04:00
committed by GitHub
parent e71eb3020c
commit a2fb88c1c1
10 changed files with 143 additions and 10 deletions

View File

@@ -214,6 +214,12 @@ public class Generate implements Runnable {
description = "Skips the default behavior of validating an input specification.")
private Boolean skipValidateSpec;
@Option(name = {"--strict-spec"},
title = "true/false strict behavior",
description = "'MUST' and 'SHALL' wording in OpenAPI spec is strictly adhered to. e.g. when false, no fixes will be applied to documents which pass validation but don't follow the spec.",
arity = 1)
private Boolean strictSpecBehavior;
@Option(name = {"--log-to-stderr"},
title = "Log to STDERR",
description = "write all log messages (not just errors) to STDOUT."
@@ -368,10 +374,15 @@ public class Generate implements Runnable {
if (generateAliasAsModel != null) {
configurator.setGenerateAliasAsModel(generateAliasAsModel);
}
if (minimalUpdate != null) {
configurator.setEnableMinimalUpdate(minimalUpdate);
}
if (strictSpecBehavior != null) {
configurator.setStrictSpecBehavior(strictSpecBehavior);
}
applySystemPropertiesKvpList(systemProperties, configurator);
applyInstantiationTypesKvpList(instantiationTypes, configurator);
applyImportMappingsKvpList(importMappings, configurator);

View File

@@ -277,6 +277,26 @@ public class GenerateTest {
};
}
@Test
public void testStrictSpec() throws Exception {
setupAndRunGenericTest("--strict-spec", "true");
new FullVerifications() {
{
configurator.setStrictSpecBehavior(true);
times = 1;
}
};
setupAndRunGenericTest("--strict-spec", "false");
new FullVerifications() {
{
configurator.setStrictSpecBehavior(false);
times = 1;
}
};
}
@Test
public void testPackageName() throws Exception {
final String value = "io.foo.bar.baz";