You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [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
Copy file name to clipboardExpand all lines: modules/openapi-generator-cli/src/main/java/org/openapitools/codegen/cmd/Generate.java
+11
Original file line number
Diff line number
Diff line change
@@ -214,6 +214,12 @@ public class Generate implements Runnable {
214
214
description = "Skips the default behavior of validating an input specification.")
215
215
privateBooleanskipValidateSpec;
216
216
217
+
@Option(name = {"--strict-spec"},
218
+
title = "true/false strict behavior",
219
+
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.",
220
+
arity = 1)
221
+
privateBooleanstrictSpecBehavior;
222
+
217
223
@Option(name = {"--log-to-stderr"},
218
224
title = "Log to STDERR",
219
225
description = "write all log messages (not just errors) to STDOUT."
-`skipValidateSpec` - Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in an error.
60
+
-`strictSpec` - Whether or not to treat an input document strictly against the spec. '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.
60
61
-`generateAliasAsModel` - generate alias (array, map) as model
61
62
-`generateApis` - generate the apis (`true` by default)
62
63
-`generateApiTests` - generate the api tests (`true` by default. Only available if `generateApis` is `true`)
if (isStrictSpecBehavior() && !path.startsWith("/")) {
2394
+
// modifies an operation.path to strictly conform to OpenAPI Spec
2393
2395
op.path = "/" + path;
2396
+
} else {
2397
+
op.path = path;
2394
2398
}
2399
+
2395
2400
op.operationId = toOperationId(operationId);
2396
2401
op.summary = escapeText(operation.getSummary());
2397
2402
op.unescapedNotes = operation.getDescription();
@@ -4900,4 +4905,24 @@ public void setEnableMinimalUpdate(boolean enableMinimalUpdate) {
4900
4905
this.enableMinimalUpdate = enableMinimalUpdate;
4901
4906
}
4902
4907
4908
+
/**
4909
+
* Indicates whether the codegen configuration should treat documents as strictly defined by the OpenAPI specification.
4910
+
*
4911
+
* @return true to act strictly upon spec documents, potentially modifying the spec to strictly fit the spec.
4912
+
*/
4913
+
@Override
4914
+
publicbooleanisStrictSpecBehavior() {
4915
+
returnthis.strictSpecBehavior;
4916
+
}
4917
+
4918
+
/**
4919
+
* Sets the boolean valid indicating whether generation will work strictly against the specification, potentially making
4920
+
* minor changes to the input document.
4921
+
*
4922
+
* @param strictSpecBehavior true if we will behave strictly, false to allow specification documents which pass validation to be loosely interpreted against the spec.
0 commit comments