diff --git a/kaizen-openapi-parser/pom.xml b/kaizen-openapi-parser/pom.xml index 15f27840..c742e970 100755 --- a/kaizen-openapi-parser/pom.xml +++ b/kaizen-openapi-parser/pom.xml @@ -61,11 +61,6 @@ jackson-dataformat-yaml ${jackson-version} - - com.google.inject - guice - 4.1.0 - org.skyscreamer jsonassert @@ -82,10 +77,20 @@ javax.mail-api 1.6.1 + + com.sun.mail + javax.mail + 1.6.1 + + + com.google.guava + guava + 19.0 + com.reprezen.jsonoverlay jsonoverlay - ${json-overlay-version} + [3.0,4.0) @@ -235,4 +240,10 @@ true 2.6.2 + + + jovl-staging + https://oss.sonatype.org/content/repositories/comreprezenjsonoverlay-1033/ + + diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApi3Parser.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApi3Parser.java index bd09ea36..0664dc28 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApi3Parser.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApi3Parser.java @@ -16,18 +16,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.reprezen.kaizen.oasparser.model3.OpenApi3; -import com.reprezen.kaizen.oasparser.val3.ValidationConfigurator; public class OpenApi3Parser extends OpenApiParser { - public OpenApi3Parser() { - super(); - } - - public OpenApi3Parser(ValidationConfigurator validationConfigurator) { - super(validationConfigurator); - } - @Override public OpenApi3 parse(String spec, URL resolutionBase) { return (OpenApi3) super.parse(spec, resolutionBase); @@ -80,7 +71,8 @@ public OpenApi3 parse(JsonNode tree, URL resolutionBase, boolean validate) { @Override protected boolean isVersion3(JsonNode tree) { - return true; // if 'openapi' property is missing or incorrect, that will show up as a - // validation error + return true; // if 'openapi' property is missing or incorrect, that will + // show up as a + // validation error } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApiParser.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApiParser.java index 0568c353..266f1556 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApiParser.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/OpenApiParser.java @@ -17,27 +17,13 @@ import java.net.URL; import com.fasterxml.jackson.databind.JsonNode; -import com.google.inject.Guice; -import com.google.inject.Injector; import com.reprezen.jsonoverlay.JsonLoader; import com.reprezen.jsonoverlay.ReferenceManager; import com.reprezen.kaizen.oasparser.model3.OpenApi3; import com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl; -import com.reprezen.kaizen.oasparser.val3.ValidationConfigurator; -import com.reprezen.kaizen.oasparser.val3.ovl.OverlayValidationConfigurator; public class OpenApiParser { - private Injector injector; - - public OpenApiParser() { - this(new OverlayValidationConfigurator()); - } - - public OpenApiParser(ValidationConfigurator validationConfigurator) { - this.injector = Guice.createInjector(validationConfigurator); - } - public OpenApi parse(String spec, URL resolutionBase) { return parse(spec, resolutionBase, true); } @@ -101,7 +87,6 @@ private OpenApi parse(ReferenceManager manager, boolean validate) { if (isVersion3(tree)) { OpenApi3 model = (OpenApi3) OpenApi3Impl.factory.create(tree, null, manager); ((OpenApi3Impl) model)._setCreatingRef(manager.getDocReference()); - injector.injectMembers(model); if (validate) { model.validate(); } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/CallbackImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/CallbackImpl.java index 525e1daa..c4bab266 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/CallbackImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/CallbackImpl.java @@ -133,6 +133,12 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_callbackPaths = "callbackPaths"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ContactImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ContactImpl.java index 945c2f5a..143a2662 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ContactImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ContactImpl.java @@ -114,6 +114,18 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_url = "url"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_email = "email"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/EncodingPropertyImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/EncodingPropertyImpl.java index d8bbda0e..98a98642 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/EncodingPropertyImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/EncodingPropertyImpl.java @@ -171,6 +171,21 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contentType = "contentType"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_headers = "headers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_style = "style"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_explode = "explode"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExampleImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExampleImpl.java index d1104a60..f6a058a2 100644 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExampleImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExampleImpl.java @@ -136,6 +136,21 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_summary = "summary"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_value = "value"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_externalValue = "externalValue"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExternalDocsImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExternalDocsImpl.java index f3d547fe..c98e28b9 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExternalDocsImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ExternalDocsImpl.java @@ -101,6 +101,15 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_url = "url"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/HeaderImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/HeaderImpl.java index 60b014fb..a71a6591 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/HeaderImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/HeaderImpl.java @@ -370,6 +370,48 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_in = "in"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_required = "required"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_deprecated = "deprecated"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_allowEmptyValue = "allowEmptyValue"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_style = "style"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_explode = "explode"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_allowReserved = "allowReserved"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_schema = "schema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_example = "example"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_examples = "examples"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contentMediaTypes = "contentMediaTypes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/InfoImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/InfoImpl.java index a6451ce8..d050fbb5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/InfoImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/InfoImpl.java @@ -167,6 +167,27 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_title = "title"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_termsOfService = "termsOfService"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contact = "contact"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_license = "license"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_version = "version"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LicenseImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LicenseImpl.java index 676794b0..77e39161 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LicenseImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LicenseImpl.java @@ -103,6 +103,15 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_url = "url"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LinkImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LinkImpl.java index b0106986..587c0ac5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LinkImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/LinkImpl.java @@ -242,6 +242,27 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_operationId = "operationId"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_operationRef = "operationRef"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_parameters = "parameters"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_headers = "headers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_server = "server"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/MediaTypeImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/MediaTypeImpl.java index 0c845056..faa20723 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/MediaTypeImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/MediaTypeImpl.java @@ -207,6 +207,21 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_schema = "schema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_examples = "examples"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_example = "example"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_encodingProperties = "encodingProperties"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OAuthFlowImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OAuthFlowImpl.java index 0b33576c..fa31fc7c 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OAuthFlowImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OAuthFlowImpl.java @@ -212,6 +212,24 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_authorizationUrl = "authorizationUrl"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_tokenUrl = "tokenUrl"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_refreshUrl = "refreshUrl"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_scopes = "scopes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_scopesExtensions = "scopesExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.java index b01662c3..49e69e6b 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OpenApi3Impl.java @@ -8,9 +8,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.JsonOverlay; import com.reprezen.jsonoverlay.ObjectOverlay; +import com.reprezen.jsonoverlay.Overlay; import com.reprezen.jsonoverlay.OverlayFactory; import com.reprezen.jsonoverlay.PropertiesOverlay; import com.reprezen.jsonoverlay.ReferenceManager; @@ -33,7 +33,8 @@ import com.reprezen.kaizen.oasparser.model3.Tag; import com.reprezen.kaizen.oasparser.val.ValidationResults; import com.reprezen.kaizen.oasparser.val.ValidationResults.Severity; -import com.reprezen.kaizen.oasparser.val.Validator; +import com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationResultsInstance; +import com.reprezen.kaizen.oasparser.val3.OpenApi3Validator; public class OpenApi3Impl extends PropertiesOverlay implements OpenApi3 { @@ -50,12 +51,12 @@ protected JsonNode _fixJson(JsonNode json) { return json; } - @Inject - private Validator validator; - @Override public void validate() { - validationResults = validator.validate(this); + try (ValidationResultsInstance instance = ValidationResults.open()) { + validationResults = instance.get(); + new OpenApi3Validator().validate(Overlay.of(this)); + } } @Override @@ -942,6 +943,63 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_openApi = "openApi"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_info = "info"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_servers = "servers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_paths = "paths"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_pathsExtensions = "pathsExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_schemas = "schemas"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_responses = "responses"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_parameters = "parameters"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_examples = "examples"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_requestBodies = "requestBodies"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_headers = "headers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_securitySchemes = "securitySchemes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_links = "links"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_callbacks = "callbacks"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_componentsExtensions = "componentsExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_securityRequirements = "securityRequirements"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_tags = "tags"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_externalDocs = "externalDocs"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OperationImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OperationImpl.java index a6836b97..f72d533c 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OperationImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/OperationImpl.java @@ -597,6 +597,51 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_tags = "tags"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_summary = "summary"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_externalDocs = "externalDocs"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_operationId = "operationId"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_parameters = "parameters"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_requestBody = "requestBody"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_responses = "responses"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_responsesExtensions = "responsesExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_callbacks = "callbacks"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_callbacksExtensions = "callbacksExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_deprecated = "deprecated"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_securityRequirements = "securityRequirements"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_servers = "servers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ParameterImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ParameterImpl.java index 86a8baf3..68dc4e9d 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ParameterImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ParameterImpl.java @@ -370,6 +370,48 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_in = "in"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_required = "required"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_deprecated = "deprecated"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_allowEmptyValue = "allowEmptyValue"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_style = "style"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_explode = "explode"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_allowReserved = "allowReserved"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_schema = "schema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_example = "example"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_examples = "examples"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contentMediaTypes = "contentMediaTypes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/PathImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/PathImpl.java index ea48a948..17454a49 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/PathImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/PathImpl.java @@ -393,6 +393,24 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_summary = "summary"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_operations = "operations"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_servers = "servers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_parameters = "parameters"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/RequestBodyImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/RequestBodyImpl.java index 04ea988f..cc9d07d9 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/RequestBodyImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/RequestBodyImpl.java @@ -168,6 +168,18 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contentMediaTypes = "contentMediaTypes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_required = "required"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ResponseImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ResponseImpl.java index 9aae9b8d..b3d38b3d 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ResponseImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ResponseImpl.java @@ -247,6 +247,21 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_headers = "headers"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_contentMediaTypes = "contentMediaTypes"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_links = "links"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.java index 6e6d4e3c..b7d797a0 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SchemaImpl.java @@ -951,6 +951,120 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_title = "title"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_multipleOf = "multipleOf"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_maximum = "maximum"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_exclusiveMaximum = "exclusiveMaximum"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_minimum = "minimum"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_exclusiveMinimum = "exclusiveMinimum"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_maxLength = "maxLength"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_minLength = "minLength"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_pattern = "pattern"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_maxItems = "maxItems"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_minItems = "minItems"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_uniqueItems = "uniqueItems"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_maxProperties = "maxProperties"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_minProperties = "minProperties"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_requiredFields = "requiredFields"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_enums = "enums"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_type = "type"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_allOfSchemas = "allOfSchemas"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_oneOfSchemas = "oneOfSchemas"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_anyOfSchemas = "anyOfSchemas"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_notSchema = "notSchema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_itemsSchema = "itemsSchema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_properties = "properties"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_additionalPropertiesSchema = "additionalPropertiesSchema"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_additionalProperties = "additionalProperties"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_format = "format"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_defaultValue = "defaultValue"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_nullable = "nullable"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_discriminator = "discriminator"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_readOnly = "readOnly"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_writeOnly = "writeOnly"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_xml = "xml"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_externalDocs = "externalDocs"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_examples = "examples"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_example = "example"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_deprecated = "deprecated"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityParameterImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityParameterImpl.java index 4ed11a96..4d586665 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityParameterImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityParameterImpl.java @@ -85,6 +85,9 @@ public void removeParameter(int index) { _remove("parameters", index, String.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_parameters = "parameters"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityRequirementImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityRequirementImpl.java index 7846ffa6..2eff44eb 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityRequirementImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecurityRequirementImpl.java @@ -75,6 +75,9 @@ public void removeRequirement(String name) { _remove("requirements", name, SecurityParameter.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_requirements = "requirements"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecuritySchemeImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecuritySchemeImpl.java index 80e92a09..578bfa32 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecuritySchemeImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/SecuritySchemeImpl.java @@ -301,6 +301,45 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_type = "type"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_in = "in"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_scheme = "scheme"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_bearerFormat = "bearerFormat"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_implicitOAuthFlow = "implicitOAuthFlow"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_passwordOAuthFlow = "passwordOAuthFlow"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_clientCredentialsOAuthFlow = "clientCredentialsOAuthFlow"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_authorizationCodeOAuthFlow = "authorizationCodeOAuthFlow"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_oAuthFlowsExtensions = "oAuthFlowsExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_openIdConnectUrl = "openIdConnectUrl"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerImpl.java index e7987724..5e88b6b5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerImpl.java @@ -200,6 +200,21 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_url = "url"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_serverVariables = "serverVariables"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_variablesExtensions = "variablesExtensions"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerVariableImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerVariableImpl.java index a82acd53..cbaa3c0b 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerVariableImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/ServerVariableImpl.java @@ -158,6 +158,18 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_enumValues = "enumValues"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_defaultValue = "defaultValue"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/TagImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/TagImpl.java index f1ca1fc3..b903a3e6 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/TagImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/TagImpl.java @@ -121,6 +121,18 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_description = "description"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_externalDocs = "externalDocs"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/XmlImpl.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/XmlImpl.java index 00048be3..f9fd6fbc 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/XmlImpl.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/XmlImpl.java @@ -155,6 +155,24 @@ public void removeExtension(String name) { _remove("extensions", name, Object.class); } + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_name = "name"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_namespace = "namespace"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_prefix = "prefix"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_attribute = "attribute"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_wrapped = "wrapped"; + + @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") + public static final String F_extensions = "extensions"; + @Override @Generated("com.reprezen.jsonoverlay.gen.CodeGenerator") protected void _elaborateJson() { diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/types3.yaml b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/types3.yaml index 5e1e09cc..1e7307c5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/types3.yaml +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/types3.yaml @@ -1,520 +1,521 @@ -modelType: OpenApi3 -imports: - OpenApi: com.reprezen.kaizen.oasparser.OpenApi - Validator: com.reprezen.kaizen.oasparser.val.Validator - ValidationResults: com.reprezen.kaizen.oasparser.val.ValidationResults - Severity: com.reprezen.kaizen.oasparser.val.ValidationResults.Severity - OpenApi3Validator: com.reprezen.kaizen.oasparser.val3.OpenApi3Validator - Overlay: com.reprezen.jsonoverlay.Overlay - Collection: java.util.Collection - ReferenceRegistry: com.reprezen.jsonoverlay.ReferenceRegistry - Inject: com.google.inject.Inject -decls: - - extPat: &extPat "x-.+" - - noextPat: &noextPat "(?!x-).*" - - namePat: &namePat "[a-zA-Z0-9\\._-]+" - - noextNamePat: &noextNamePat "(?!x-)[a-zA-Z0-9\\._-]+" - - pathPat: &pathPat "/.*" - - extName: &extName extension - - extDef: &extDef - name: Extension - type: Object - parentPath: "" - structure: map - keyPattern: *extPat - -types: - - name: OpenApi3 - imports: - intf: [ ValidationResults, Collection ] - impl: [ OpenApi3Validator, Validator, ValidationResults, Severity, Inject, ReferenceRegistry, ObjectNode, JsonNodeFactory, Collection ] - extendInterfaces: [OpenApi] - fields: - openapi: - name: OpenApi - info: {} - servers: - structure: collection - paths: - structure: map - keyPattern: *pathPat - pathsExtension: - name: PathsExtension - <<: *extDef - parentPath: paths - components/schemas: - structure: map - type: Schema - keyPattern: *namePat - components/responses: - structure: map - keyPattern: *namePat - components/parameters: - structure: map - keyPattern: *namePat - components/examples: - type: Example - structure: map - keyPattern: *namePat - components/requestBodies: - name: RequestBody - plural: RequestBodies - structure: map - keyPattern: *namePat - components/headers: - structure: map - keyPattern: *namePat - components/securitySchemes: - structure: map - keyPattern: *namePat - components/links: - structure: map - keyPattern: *namePat - components/callbacks: - structure: map - keyPattern: *noextNamePat - componentsExtension: - name: ComponentsExtension - <<: *extDef - parentPath: components - security: - name: SecurityRequirement - structure: collection - tags: - structure: collection - externalDocs: {} - *extName: *extDef - - - name: OAuthFlow - fields: - authorizationUrl: {} - tokenUrl: {} - refreshUrl: {} - scopes: - structure: map - keyPattern: *noextPat - scopesExtension: - name: ScopesExtension - <<: *extDef - parentPath: scopes - *extName: *extDef - - - name: Tag - fields: - name: {} - description: {} - externalDocs: {} - *extName: *extDef - - - name: SecurityScheme - imports: - impl: [Overlay] - fields: - type: {} - description: {} - name: {} - in: {} - scheme: {} - bearerFormat: {} - flow/implicit: - name: ImplicitOAuthFlow - type: OAuthFlow - flow/password: - name: PasswordOAuthFlow - type: OAuthFlow - flow/clientCredentials: - name: ClientCredentialsOAuthFlow - type: OAuthFlow - flow/authorizationCode: - name: AuthorizationCodeOAuthFlow - type: OAuthFlow - flowExtension: - <<: *extDef - name: OAuthFlowsExtension - parentPath: flow - openIdConnectUrl: {} - *extName: *extDef - - - name: Info - fields: - title: {} - description: {} - termsOfService: {} - contact: {} - license: {} - version: {} - *extName: *extDef - - - name: Contact - fields: - name: {} - url: {} - email: {} - *extName: *extDef - - - name: License - fields: - name: {} - url: {} - *extName: *extDef - - - name: Server - fields: - url: {} - description: {} - variables: - name: ServerVariable - structure: map - keyPattern: *noextNamePat - variablesExtension: - name: VariablesExtension - <<: *extDef - parentPath: variables - *extName: *extDef - - - name: ServerVariable - fields: - enum: - name: EnumValue - type: Primitive - structure: collection - default: - type: Primitive - description: {} - *extName: *extDef - - - name: Path - imports: - impl: [ Overlay ] - fields: - summary: {} - description: {} - operations: - structure: map - parentPath: "" - keyPattern: get|put|post|delete|options|head|patch|trace - get: - type: Operation - noImpl: true - put: - type: Operation - noImpl: true - post: - type: Operation - noImpl: true - delete: - type: Operation - noImpl: true - options: - type: Operation - noImpl: true - head: - type: Operation - noImpl: true - patch: - type: Operation - noImpl: true - trace: - type: Operation - noImpl: true - servers: - structure: collection - parameters: - structure: collection -# keyDecls: -# - String name -# - String in - *extName: *extDef - - - name: Operation - fields: - tags: - type: String - structure: collection - summary: {} - description: {} - externalDocs: {} - operationId: {} - parameters: - structure: collection -# keyDecls: -# - String name -# - String id - requestBody: {} - responses: - structure: map - keyPattern: "default|(\\d\\d\\d)" - responsesExtension: - name: ResponsesExtension - <<: *extDef - parentPath: responses - callbacks: - structure: map - keyPattern: *noextNamePat - callbacksExtension: - name: CallbacksExtension - <<: *extDef - parentPath: callbacks - deprecated: - type: Boolean - security: - name: SecurityRequirement - structure: collection - servers: - structure: collection - *extName: *extDef - - - name: Callback - imports: - impl: [ Overlay ] - fields: - callbackPaths: - type: Path - structure: map - parentPath: "" - keyPattern: *noextPat - keyName: expression - *extName: *extDef - - - name: SecurityRequirement - fields: - requirement: - type: SecurityParameter - parentPath: "" - structure: map - keyPattern: *namePat - - - name: SecurityParameter - imports: - impl: [JsonNodeFactory] - fields: - parameter: - type: String - parentPath: "" - structure: collection - - - name: Response - imports: - impl: [Overlay] - fields: - description: {} - headers: - structure: map - content: - name: ContentMediaType - type: MediaType - structure: map - links: - structure: map - *extName: *extDef - - - name: Link - imports: - impl: [Overlay] - fields: - operationId: {} - operationRef: {} - parameters: - type: String - structure: map - headers: - type: Header - structure: map - description: {} - server: - type: Server - *extName: *extDef - - - name: RequestBody - imports: - impl: [Overlay] - fields: - description: {} - content: - name: ContentMediaType - type: MediaType - structure: map - required: - type: Boolean - *extName: *extDef - - - name: MediaType - fields: - schema: {} - examples: - type: Example - structure: map - keyPattern: *namePat - example: - type: Object - encoding: - name: EncodingProperty - plural: EncodingProperties - structure: map - *extName: *extDef - - - name: EncodingProperty - fields: - contentType: {} - headers: - structure: map - type: String - style: {} - explode: - type: Boolean - *extName: *extDef - - - name: ExternalDocs - fields: - description: {} - url: {} - *extName: *extDef - - - name: Parameter - imports: - impl: [Overlay] - fields: ¶mFields - name: {} - in: {} - description: {} - required: - type: Boolean - deprecated: - type: Boolean - allowEmptyValue: - type: Boolean - style: {} - explode: - type: Boolean - allowReserved: - type: Boolean - schema: {} - example: - type: Object - examples: - type: Example - structure: map - keyPattern: *namePat - content: - name: ContentMediaType - type: MediaType - structure: map - *extName: *extDef - - - name: Header - imports: - impl: [Overlay] - # Header is identical to Parameter except in terms of where it's allowed - fields: *paramFields - - - name: Schema - imports: - impl: [ Optional, JsonPointer, Overlay] - fields: - title: {} - multipleOf: - type: Number - maximum: - type: Number - exclusiveMaximum: - type: Boolean - minimum: - type: Number - exclusiveMinimum: - type: Boolean - maxLength: - type: Integer - minLength: - type: Integer - pattern: {} - maxItems: - type: Integer - minItems: - type: Integer - uniqueItems: - type: Boolean - maxProperties: - type: Integer - minProperties: - type: Integer - required: - name: RequiredField - structure: collection - enum: - type: Object - structure: collection - type: {} - allOf: - name: AllOfSchema - type: Schema - structure: collection - oneOf: - name: OneOfSchema - type: Schema - structure: collection - anyOf: - name: AnyOfSchema - type: Schema - structure: collection - not: - name: NotSchema - type: Schema - items: - name: ItemsSchema - type: Schema - properties: - name: Property - plural: Properties - type: Schema - structure: map - additionalPropertiesSchema: - parentPath: additionalProperties - type: Schema - additionalPropertiesBoolean: - name: AdditionalProperties - parentPath: additionalProperties - type: Boolean - description: {} - format: {} - default: - type: Object - nullable: - type: Boolean - discriminator: {} - readOnly: - type: Boolean - writeOnly: - type: Boolean - xml: {} - externalDocs: {} - examples: - type: Example - structure: map - keyPattern: *namePat - example: - type: Object - deprecated: - type: Boolean - *extName: *extDef - - - name: Xml - fields: - name: {} - namespace: {} - prefix: {} - attribute: - type: Boolean - wrapped: - type: Boolean - *extName: *extDef - - - name: Example - imports: - impl: [Overlay] - fields: - summary: {} - description: {} - value: - type: Object - externalValue: {} - *extName: *extDef +modelType: OpenApi3 +imports: + OpenApi: com.reprezen.kaizen.oasparser.OpenApi + Validator: com.reprezen.kaizen.oasparser.val.Validator + ValidationResults: com.reprezen.kaizen.oasparser.val.ValidationResults + ValidationResultsInstance: com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationResultsInstance + Severity: com.reprezen.kaizen.oasparser.val.ValidationResults.Severity + OpenApi3Validator: com.reprezen.kaizen.oasparser.val3.OpenApi3Validator + Overlay: com.reprezen.jsonoverlay.Overlay + Collection: java.util.Collection + ReferenceRegistry: com.reprezen.jsonoverlay.ReferenceRegistry + Inject: com.google.inject.Inject +decls: + - extPat: &extPat "x-.+" + - noextPat: &noextPat "(?!x-).*" + - namePat: &namePat "[a-zA-Z0-9\\._-]+" + - noextNamePat: &noextNamePat "(?!x-)[a-zA-Z0-9\\._-]+" + - pathPat: &pathPat "/.*" + - extName: &extName extension + - extDef: &extDef + name: Extension + type: Object + parentPath: "" + structure: map + keyPattern: *extPat + +types: + - name: OpenApi3 + imports: + intf: [ ValidationResults, Collection ] + impl: [ OpenApi3Validator, Validator, ValidationResults, ValidationResultsInstance, Severity, ReferenceRegistry, Overlay, ObjectNode, JsonNodeFactory, Collection ] + extendInterfaces: [OpenApi] + fields: + openapi: + name: OpenApi + info: {} + servers: + structure: collection + paths: + structure: map + keyPattern: *pathPat + pathsExtension: + name: PathsExtension + <<: *extDef + parentPath: paths + components/schemas: + structure: map + type: Schema + keyPattern: *namePat + components/responses: + structure: map + keyPattern: *namePat + components/parameters: + structure: map + keyPattern: *namePat + components/examples: + type: Example + structure: map + keyPattern: *namePat + components/requestBodies: + name: RequestBody + plural: RequestBodies + structure: map + keyPattern: *namePat + components/headers: + structure: map + keyPattern: *namePat + components/securitySchemes: + structure: map + keyPattern: *namePat + components/links: + structure: map + keyPattern: *namePat + components/callbacks: + structure: map + keyPattern: *noextNamePat + componentsExtension: + name: ComponentsExtension + <<: *extDef + parentPath: components + security: + name: SecurityRequirement + structure: collection + tags: + structure: collection + externalDocs: {} + *extName: *extDef + + - name: OAuthFlow + fields: + authorizationUrl: {} + tokenUrl: {} + refreshUrl: {} + scopes: + structure: map + keyPattern: *noextPat + scopesExtension: + name: ScopesExtension + <<: *extDef + parentPath: scopes + *extName: *extDef + + - name: Tag + fields: + name: {} + description: {} + externalDocs: {} + *extName: *extDef + + - name: SecurityScheme + imports: + impl: [Overlay] + fields: + type: {} + description: {} + name: {} + in: {} + scheme: {} + bearerFormat: {} + flow/implicit: + name: ImplicitOAuthFlow + type: OAuthFlow + flow/password: + name: PasswordOAuthFlow + type: OAuthFlow + flow/clientCredentials: + name: ClientCredentialsOAuthFlow + type: OAuthFlow + flow/authorizationCode: + name: AuthorizationCodeOAuthFlow + type: OAuthFlow + flowExtension: + <<: *extDef + name: OAuthFlowsExtension + parentPath: flow + openIdConnectUrl: {} + *extName: *extDef + + - name: Info + fields: + title: {} + description: {} + termsOfService: {} + contact: {} + license: {} + version: {} + *extName: *extDef + + - name: Contact + fields: + name: {} + url: {} + email: {} + *extName: *extDef + + - name: License + fields: + name: {} + url: {} + *extName: *extDef + + - name: Server + fields: + url: {} + description: {} + variables: + name: ServerVariable + structure: map + keyPattern: *noextNamePat + variablesExtension: + name: VariablesExtension + <<: *extDef + parentPath: variables + *extName: *extDef + + - name: ServerVariable + fields: + enum: + name: EnumValue + type: Primitive + structure: collection + default: + type: Primitive + description: {} + *extName: *extDef + + - name: Path + imports: + impl: [ Overlay ] + fields: + summary: {} + description: {} + operations: + structure: map + parentPath: "" + keyPattern: get|put|post|delete|options|head|patch|trace + get: + type: Operation + noImpl: true + put: + type: Operation + noImpl: true + post: + type: Operation + noImpl: true + delete: + type: Operation + noImpl: true + options: + type: Operation + noImpl: true + head: + type: Operation + noImpl: true + patch: + type: Operation + noImpl: true + trace: + type: Operation + noImpl: true + servers: + structure: collection + parameters: + structure: collection +# keyDecls: +# - String name +# - String in + *extName: *extDef + + - name: Operation + fields: + tags: + type: String + structure: collection + summary: {} + description: {} + externalDocs: {} + operationId: {} + parameters: + structure: collection +# keyDecls: +# - String name +# - String id + requestBody: {} + responses: + structure: map + keyPattern: "default|(\\d\\d\\d)" + responsesExtension: + name: ResponsesExtension + <<: *extDef + parentPath: responses + callbacks: + structure: map + keyPattern: *noextNamePat + callbacksExtension: + name: CallbacksExtension + <<: *extDef + parentPath: callbacks + deprecated: + type: Boolean + security: + name: SecurityRequirement + structure: collection + servers: + structure: collection + *extName: *extDef + + - name: Callback + imports: + impl: [ Overlay ] + fields: + callbackPaths: + type: Path + structure: map + parentPath: "" + keyPattern: *noextPat + keyName: expression + *extName: *extDef + + - name: SecurityRequirement + fields: + requirement: + type: SecurityParameter + parentPath: "" + structure: map + keyPattern: *namePat + + - name: SecurityParameter + imports: + impl: [JsonNodeFactory] + fields: + parameter: + type: String + parentPath: "" + structure: collection + + - name: Response + imports: + impl: [Overlay] + fields: + description: {} + headers: + structure: map + content: + name: ContentMediaType + type: MediaType + structure: map + links: + structure: map + *extName: *extDef + + - name: Link + imports: + impl: [Overlay] + fields: + operationId: {} + operationRef: {} + parameters: + type: String + structure: map + headers: + type: Header + structure: map + description: {} + server: + type: Server + *extName: *extDef + + - name: RequestBody + imports: + impl: [Overlay] + fields: + description: {} + content: + name: ContentMediaType + type: MediaType + structure: map + required: + type: Boolean + *extName: *extDef + + - name: MediaType + fields: + schema: {} + examples: + type: Example + structure: map + keyPattern: *namePat + example: + type: Object + encoding: + name: EncodingProperty + plural: EncodingProperties + structure: map + *extName: *extDef + + - name: EncodingProperty + fields: + contentType: {} + headers: + structure: map + type: String + style: {} + explode: + type: Boolean + *extName: *extDef + + - name: ExternalDocs + fields: + description: {} + url: {} + *extName: *extDef + + - name: Parameter + imports: + impl: [Overlay] + fields: ¶mFields + name: {} + in: {} + description: {} + required: + type: Boolean + deprecated: + type: Boolean + allowEmptyValue: + type: Boolean + style: {} + explode: + type: Boolean + allowReserved: + type: Boolean + schema: {} + example: + type: Object + examples: + type: Example + structure: map + keyPattern: *namePat + content: + name: ContentMediaType + type: MediaType + structure: map + *extName: *extDef + + - name: Header + imports: + impl: [Overlay] + # Header is identical to Parameter except in terms of where it's allowed + fields: *paramFields + + - name: Schema + imports: + impl: [ Optional, JsonPointer, Overlay] + fields: + title: {} + multipleOf: + type: Number + maximum: + type: Number + exclusiveMaximum: + type: Boolean + minimum: + type: Number + exclusiveMinimum: + type: Boolean + maxLength: + type: Integer + minLength: + type: Integer + pattern: {} + maxItems: + type: Integer + minItems: + type: Integer + uniqueItems: + type: Boolean + maxProperties: + type: Integer + minProperties: + type: Integer + required: + name: RequiredField + structure: collection + enum: + type: Object + structure: collection + type: {} + allOf: + name: AllOfSchema + type: Schema + structure: collection + oneOf: + name: OneOfSchema + type: Schema + structure: collection + anyOf: + name: AnyOfSchema + type: Schema + structure: collection + not: + name: NotSchema + type: Schema + items: + name: ItemsSchema + type: Schema + properties: + name: Property + plural: Properties + type: Schema + structure: map + additionalPropertiesSchema: + parentPath: additionalProperties + type: Schema + additionalPropertiesBoolean: + name: AdditionalProperties + parentPath: additionalProperties + type: Boolean + description: {} + format: {} + default: + type: Object + nullable: + type: Boolean + discriminator: {} + readOnly: + type: Boolean + writeOnly: + type: Boolean + xml: {} + externalDocs: {} + examples: + type: Example + structure: map + keyPattern: *namePat + example: + type: Object + deprecated: + type: Boolean + *extName: *extDef + + - name: Xml + fields: + name: {} + namespace: {} + prefix: {} + attribute: + type: Boolean + wrapped: + type: Boolean + *extName: *extDef + + - name: Example + imports: + impl: [Overlay] + fields: + summary: {} + description: {} + value: + type: Object + externalValue: {} + *extName: *extDef diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/AnyObjectValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/AnyObjectValidator.java deleted file mode 100755 index 4d0728a1..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/AnyObjectValidator.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import com.reprezen.jsonoverlay.ObjectOverlay; - -public class AnyObjectValidator extends OverlayValidator { - - @Override - public void validate(ObjectOverlay overlay, ValidationResults results) { - super.validate(overlay, results); - } - -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/BooleanValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/BooleanValidator.java deleted file mode 100755 index 6cf0e7fa..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/BooleanValidator.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import com.fasterxml.jackson.databind.node.BooleanNode; -import com.reprezen.jsonoverlay.BooleanOverlay; - -public class BooleanValidator extends OverlayValidator { - - @Override - public void validate(BooleanOverlay overlay, ValidationResults results) { - super.validate(overlay, results, BooleanNode.class); - } -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ImplValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ImplValidator.java deleted file mode 100755 index 02c2a06f..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ImplValidator.java +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -public interface ImplValidator { - - void validateImpl(T object, ValidationResults results); -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/IntegerValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/IntegerValidator.java deleted file mode 100755 index 8acf600f..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/IntegerValidator.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import java.util.Set; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.BigIntegerNode; -import com.fasterxml.jackson.databind.node.IntNode; -import com.fasterxml.jackson.databind.node.ShortNode; -import com.google.common.collect.Sets; -import com.reprezen.jsonoverlay.IntegerOverlay; - -public class IntegerValidator extends OverlayValidator { - - @SuppressWarnings("unchecked") - private static Set> intTypes = Sets.> newHashSet( // - IntNode.class, ShortNode.class, BigIntegerNode.class); - - @Override - public void validate(IntegerOverlay overlay, ValidationResults results) { - super.validate(overlay, results, intTypes); - } -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/JsonTypeChecker.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/JsonTypeChecker.java new file mode 100755 index 00000000..2e3e3876 --- /dev/null +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/JsonTypeChecker.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2017 ModelSolv, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ModelSolv, Inc. - initial API and implementation and/or initial documentation + *******************************************************************************/ +package com.reprezen.kaizen.oasparser.val; + +import static com.reprezen.kaizen.oasparser.val.Messages.m; + +import java.util.Arrays; +import java.util.Collection; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.BigIntegerNode; +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.IntNode; +import com.fasterxml.jackson.databind.node.NumericNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.ShortNode; +import com.fasterxml.jackson.databind.node.TextNode; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.reprezen.jsonoverlay.BooleanOverlay; +import com.reprezen.jsonoverlay.IntegerOverlay; +import com.reprezen.jsonoverlay.JsonOverlay; +import com.reprezen.jsonoverlay.ListOverlay; +import com.reprezen.jsonoverlay.MapOverlay; +import com.reprezen.jsonoverlay.NumberOverlay; +import com.reprezen.jsonoverlay.ObjectOverlay; +import com.reprezen.jsonoverlay.Overlay; +import com.reprezen.jsonoverlay.PrimitiveOverlay; +import com.reprezen.jsonoverlay.PropertiesOverlay; +import com.reprezen.jsonoverlay.StringOverlay; + +public class JsonTypeChecker { + + public static void checkJsonType(Overlay value, ValidationResults results) { + JsonNode json = value.getParsedJson(); + if (json != null && !json.isMissingNode()) { + Collection> allowedJsonTypes = getAllowedJsonTypes(value); + for (Class type : allowedJsonTypes) { + if (type.isAssignableFrom(json.getClass())) { + return; + } + } + results.addError(m.msg("WrongTypeJson|Property bound to incompatible JSON Node type", json.getNodeType(), + allowedJsonTypes), value); + } + } + + private static Multimap, Class> allowedJsonTypes = null; + + private static Collection> getAllowedJsonTypes(Overlay value) { + if (allowedJsonTypes == null) { + createAllowedJsonTypes(); + } + JsonOverlay overlay = value.getOverlay(); + return allowedJsonTypes + .get(overlay instanceof PropertiesOverlay ? PropertiesOverlay.class : overlay.getClass()); + } + + private static void createAllowedJsonTypes() { + Multimap, Class> types = ArrayListMultimap + ., Class>create(); + types.put(StringOverlay.class, TextNode.class); + types.put(BooleanOverlay.class, BooleanNode.class); + types.putAll(IntegerOverlay.class, Arrays.asList(IntNode.class, ShortNode.class, BigIntegerNode.class)); + types.put(NumberOverlay.class, NumericNode.class); + types.putAll(PrimitiveOverlay.class, Arrays.asList(TextNode.class, NumericNode.class, BooleanNode.class)); + types.put(ObjectOverlay.class, JsonNode.class); + types.put(MapOverlay.class, ObjectNode.class); + types.put(ListOverlay.class, ArrayNode.class); + types.put(PropertiesOverlay.class, ObjectNode.class); + allowedJsonTypes = types; + } +} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ListValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ListValidator.java index 8c731f55..61f15abf 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ListValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ListValidator.java @@ -10,27 +10,26 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val; -import com.reprezen.jsonoverlay.JsonOverlay; +import java.util.List; + import com.reprezen.jsonoverlay.ListOverlay; import com.reprezen.jsonoverlay.Overlay; -public class ListValidator> extends OverlayValidator> { +public class ListValidator extends ValidatorBase> { - Validator elementValidator; + Validator itemValidator; public ListValidator(Validator elementeValidator) { - this.elementValidator = elementeValidator; + this.itemValidator = elementeValidator; } @Override - public void validate(ListOverlay overlay, ValidationResults results) { - int i = 0; - for (T value : Overlay.get(overlay)) { - elementValidator.validate(value, results, getElementCrumb(i++)); + public void runValidations() { + if (itemValidator != null) { + ListOverlay list = Overlay.getListOverlay(value); + for (int i = 0; i < list.size(); i++) { + itemValidator.validate(Overlay.of(list, i)); + } } } - - protected String getElementCrumb(int index) { - return "[" + index + "]"; - } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/MapValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/MapValidator.java index e1265e90..e85edf36 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/MapValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/MapValidator.java @@ -10,24 +10,26 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.reprezen.jsonoverlay.JsonOverlay; +import java.util.Map; + import com.reprezen.jsonoverlay.MapOverlay; import com.reprezen.jsonoverlay.Overlay; -public class MapValidator> extends OverlayValidator> { +public class MapValidator extends ValidatorBase> { - private Validator elementValidator; + private Validator valueValidator; - public MapValidator(Validator elementValidator) { - this.elementValidator = elementValidator; + public MapValidator(Validator valueValidator) { + this.valueValidator = valueValidator; } @Override - public void validate(MapOverlay overlay, ValidationResults results) { - super.validate(overlay, results, ObjectNode.class); - for (T value : Overlay.get(overlay).values()) { - elementValidator.validate(value, results, Overlay.getPathInParent(value)); + public void runValidations() { + MapOverlay mapOverlay = Overlay.getMapOverlay(value); + if (valueValidator != null) { + for (String key : mapOverlay.keySet()) { + valueValidator.validate(Overlay.of(mapOverlay, key)); + } } } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Messages.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Messages.java index c84a397e..be33e42a 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Messages.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Messages.java @@ -13,18 +13,18 @@ import java.util.Arrays; public class Messages { - public static Messages m = new Messages(); + public static Messages m = new Messages(); - public String msg(String text, Object... args) { - int pos = text.indexOf('|'); - if (pos >= 0) { - String nls = nls(text.substring(0, pos)); - text = nls != null ? nls : text.substring(pos + 1); - } - return String.format("%s %s", text, Arrays.asList(args)); - } + public String msg(String text, Object... args) { + int pos = text.indexOf('|'); + if (pos >= 0) { + String nls = nls(text.substring(0, pos)); + text = nls != null ? nls : text.substring(pos + 1); + } + return String.format("%s %s", text, Arrays.asList(args)); + } - public String nls(String text) { - return null; - } + public String nls(String text) { + return null; + } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumberValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumberValidator.java deleted file mode 100755 index 2650f6b7..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumberValidator.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import com.fasterxml.jackson.databind.node.NumericNode; -import com.reprezen.jsonoverlay.NumberOverlay; - -public class NumberValidator extends OverlayValidator { - - @Override - public void validate(NumberOverlay overlay, ValidationResults results) { - super.validate(overlay, results, NumericNode.class); - } - -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumericUtils.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumericUtils.java index 5b1d2152..afd61877 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumericUtils.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/NumericUtils.java @@ -17,134 +17,157 @@ import com.google.common.collect.Maps; public class NumericUtils { - - public static boolean isNumeric(Object obj) { - return NumericType.of(obj) != null; - } - - public static boolean isIntegral(Object obj) { - switch (NumericType.of(obj)) { - case BIG_INTEGER: - case BYTE: - case INTEGER: - case LONG: - case SHORT: - return true; - default: - return false; - } - } - - public static T zero(T value) { - Number result; - switch (NumericType.of(value)) { - case BIG_DECIMAL: - result = BigDecimal.ZERO; - break; - case BIG_INTEGER: - result = BigInteger.ZERO; - break; - case BYTE: - result = Byte.valueOf((byte) 0); - break; - case DOUBLE: - result = Double.valueOf(0.0); - break; - case FLOAT: - result = Float.valueOf(0.0f); - break; - case INTEGER: - result = Integer.valueOf(0); - break; - case LONG: - result = Long.valueOf(0L); - break; - case SHORT: - result = Short.valueOf((short) 0); - break; - default: - return null; // shouldn't ever happen - } - @SuppressWarnings("unchecked") - T tResult = (T) result; - return tResult; - } - - public static boolean gt(T x, T y) { - return compare(x, y) > 0; - } - - public static boolean ge(T x, T y) { - return compare(x, y) >= 0; - } - - public static boolean lt(T x, T y) { - return compare(x, y) < 0; - } - - public static boolean le(T x, T y) { - return compare(x, y) <= 0; - } - - public static boolean eq(T x, T y) { - return compare(x, y) == 0; - } - - public static boolean ne(T x, T y) { - return compare(x, y) != 0; - } - - public static int compare(T x, T y) { - NumericType type = NumericType.of(x); - if (type != NumericType.of(y)) { - throw new IllegalArgumentException(); - } - switch (type) { - case BIG_DECIMAL: - return ((BigDecimal) x).compareTo((BigDecimal) y); - case BIG_INTEGER: - return ((BigInteger) x).compareTo((BigInteger) y); - case BYTE: - return ((Byte) x).compareTo((Byte) y); - case DOUBLE: - return ((Double) x).compareTo((Double) y); - case FLOAT: - return ((Float) x).compareTo((Float) y); - case INTEGER: - return ((Integer) x).compareTo((Integer) y); - case LONG: - return ((Long) x).compareTo((Long) y); - case SHORT: - return ((Short) x).compareTo((Short) y); - default: - throw new IllegalArgumentException(); - } - } - - enum NumericType { - BIG_DECIMAL(BigDecimal.class), // - BIG_INTEGER(BigInteger.class), // - BYTE(Byte.class), // - DOUBLE(Double.class), // - FLOAT(Float.class), // - INTEGER(Integer.class), // - LONG(Long.class), // - SHORT(Short.class); - - private static Map, NumericType> types; - - private NumericType(Class cls) { - register(cls, this); - } - - private void register(Class cls, NumericType type) { - if (NumericType.types == null) - NumericType.types = Maps.newHashMap(); - types.put(cls, type); - } - - public static NumericType of(Object value) { - return value != null ? types.get(value.getClass()) : null; - } - } + public static boolean isNumeric(Object obj) { + return NumericType.of(obj) != null; + } + + public static boolean isIntegral(Object obj) { + switch (NumericType.of(obj)) { + case BIG_INTEGER: + case BYTE: + case INTEGER: + case LONG: + case SHORT: + return true; + default: + return false; + } + } + + public static T zero(T value) { + Number result; + switch (NumericType.of(value)) { + case BIG_DECIMAL: + result = BigDecimal.ZERO; + break; + case BIG_INTEGER: + result = BigInteger.ZERO; + break; + case BYTE: + result = Byte.valueOf((byte) 0); + break; + case DOUBLE: + result = Double.valueOf(0.0); + break; + case FLOAT: + result = Float.valueOf(0.0f); + break; + case INTEGER: + result = Integer.valueOf(0); + break; + case LONG: + result = Long.valueOf(0L); + break; + case SHORT: + result = Short.valueOf((short) 0); + break; + default: + return null; // shouldn't ever happen + } + @SuppressWarnings("unchecked") + T tResult = (T) result; + return tResult; + } + + public static boolean gt(T x, T y) { + return compare(x, y) > 0; + } + + public static boolean ge(T x, T y) { + return compare(x, y) >= 0; + } + + public static boolean lt(T x, T y) { + return compare(x, y) < 0; + } + + public static boolean le(T x, T y) { + return compare(x, y) <= 0; + } + + public static boolean eq(T x, T y) { + return compare(x, y) == 0; + } + + public static boolean ne(T x, T y) { + return compare(x, y) != 0; + } + + public static boolean isPositive(T x) { + return gt(x, zero(x)); + } + + public static boolean isZero(T x) { + return eq(x, zero(x)); + } + + public static boolean isNegative(T x) { + return lt(x, zero(x)); + } + + public static boolean isNonNegative(T x) { + return ge(x, zero(x)); + } + + public static boolean isnonZero(T x) { + return ne(x, zero(x)); + } + + public static boolean isNonPostive(T x) { + return le(x, zero(x)); + } + + public static int compare(T x, T y) { + NumericType type = NumericType.of(x); + if (type != NumericType.of(y)) { + throw new IllegalArgumentException(); + } + switch (type) { + case BIG_DECIMAL: + return ((BigDecimal) x).compareTo((BigDecimal) y); + case BIG_INTEGER: + return ((BigInteger) x).compareTo((BigInteger) y); + case BYTE: + return ((Byte) x).compareTo((Byte) y); + case DOUBLE: + return ((Double) x).compareTo((Double) y); + case FLOAT: + return ((Float) x).compareTo((Float) y); + case INTEGER: + return ((Integer) x).compareTo((Integer) y); + case LONG: + return ((Long) x).compareTo((Long) y); + case SHORT: + return ((Short) x).compareTo((Short) y); + default: + throw new IllegalArgumentException(); + } + } + + enum NumericType { + BIG_DECIMAL(BigDecimal.class), // + BIG_INTEGER(BigInteger.class), // + BYTE(Byte.class), // + DOUBLE(Double.class), // + FLOAT(Float.class), // + INTEGER(Integer.class), // + LONG(Long.class), // + SHORT(Short.class); + + private static Map, NumericType> types; + + private NumericType(Class cls) { + register(cls, this); + } + + private void register(Class cls, NumericType type) { + if (NumericType.types == null) + NumericType.types = Maps.newHashMap(); + types.put(cls, type); + } + + public static NumericType of(Object value) { + return value != null ? types.get(value.getClass()) : null; + } + } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidator.java deleted file mode 100755 index ab84d795..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidator.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -public class ObjectValidator extends OverlayValidator { - - @Override - public void validate(T overlay, ValidationResults results) { - super.validate(overlay, results, ObjectNode.class); - } -} \ No newline at end of file diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidatorBase.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidatorBase.java index c3f0c878..24c68e88 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidatorBase.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ObjectValidatorBase.java @@ -13,14 +13,16 @@ import java.util.IdentityHashMap; import java.util.Map; -import com.google.inject.Inject; -import com.reprezen.jsonoverlay.PropertiesOverlay; +public abstract class ObjectValidatorBase extends ValidatorBase { -public abstract class ObjectValidatorBase extends ValidatorBase { - @Inject(optional = true) - private ImplValidator implValidator; + @Override + public void runValidations() { + if (value.isElaborated() && visit(value)) { + runObjectValidations(); + } + } - public abstract void validateObject(T object, ValidationResults results); + public abstract void runObjectValidations(); protected static ThreadLocal validationVisits = new ThreadLocal(); @@ -31,20 +33,6 @@ protected static boolean visit(Object obj) { return validationVisits.get().visit(obj); } - @Override - public void validate(T value, ValidationResults results) { - if (!visit(value)) { - @SuppressWarnings("unchecked") - PropertiesOverlay propValue = (PropertiesOverlay) value; - if (propValue._isElaborated()) { - validateObject(value, results); - if (implValidator != null) { - implValidator.validateImpl(value, results); - } - } - } - } - protected static class ValidationVisits { private Map visits = new IdentityHashMap(); diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/OverlayValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/OverlayValidator.java deleted file mode 100755 index 322e39a2..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/OverlayValidator.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import static com.reprezen.kaizen.oasparser.val.Messages.m; - -import java.util.Collections; -import java.util.Set; - -import com.fasterxml.jackson.databind.JsonNode; -import com.reprezen.jsonoverlay.JsonOverlay; -import com.reprezen.jsonoverlay.ListOverlay; -import com.reprezen.jsonoverlay.MapOverlay; -import com.reprezen.jsonoverlay.Overlay; -import com.reprezen.jsonoverlay.PropertiesOverlay; -import com.reprezen.jsonoverlay.Reference; - -public class OverlayValidator extends ValidatorBase { - - @Override - public void validate(T overlay, ValidationResults results) { - checkReferences((JsonOverlay) overlay, results); - } - - public void validate(T overlay, ValidationResults results, Class allowedNodeType) { - validate(overlay, results, Collections.>singleton(allowedNodeType)); - } - - public void validate(T object, ValidationResults results, Set> allowedNodeTypes) { - JsonOverlay overlay = (JsonOverlay) object; - JsonNode json = Overlay.toJson(overlay); - boolean isValidJsonType = false; - for (Class type : allowedNodeTypes) { - if (type.isAssignableFrom(json.getClass())) { - isValidJsonType = true; - break; - } - } - isValidJsonType = isValidJsonType || json.isMissingNode(); - if (!isValidJsonType) { - results.addError(m.msg("WrongTypeJson|Property bound to incompatible JSON Node type", json.getNodeType(), - allowedNodeTypes)); - } - } - - private void checkReferences(JsonOverlay overlay, ValidationResults results) { - if (overlay instanceof ListOverlay) { - checkReferences((ListOverlay) overlay, results); - } else if (overlay instanceof MapOverlay) { - checkReferences((MapOverlay) overlay, results); - } else if (overlay instanceof PropertiesOverlay) { - checkReferences((PropertiesOverlay) overlay, results); - } - } - - private void checkReferences(ListOverlay list, ValidationResults results) { - Overlay listAdapter = Overlay.of(list); - for (int i = 0; i < list.size(); i++) { - if (listAdapter.isReference(i)) { - checkReference(listAdapter.getReference(i), results, Integer.toString(i)); - } - } - } - - private void checkReferences(MapOverlay map, ValidationResults results) { - Overlay mapAdapter = Overlay.of(map); - for (String key : map.keySet()) { - if (mapAdapter.isReference(key)) { - checkReference(mapAdapter.getReference(key), results, key); - } - } - } - - private void checkReferences(PropertiesOverlay props, ValidationResults results) { - if (props._isElaborated()) { - Overlay propsAdapter = Overlay.of(props); - for (String name : propsAdapter.getPropertyNames()) { - if (propsAdapter.isReference(name)) { - checkReference(propsAdapter.getReference(name), results, name); - } - } - } - } - - private void checkReference(Reference ref, ValidationResults results, String crumb) { - if (ref.isInvalid()) { - results.addError( - m.msg("BadRef|JSON reference node was not resolved", ref.getRefString(), ref.getInvalidReason()), - crumb); - } - - } -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ReferencesChecker.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ReferencesChecker.java new file mode 100755 index 00000000..081a6870 --- /dev/null +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ReferencesChecker.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2017 ModelSolv, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * ModelSolv, Inc. - initial API and implementation and/or initial documentation + *******************************************************************************/ +package com.reprezen.kaizen.oasparser.val; + +import static com.reprezen.kaizen.oasparser.val.Messages.m; + +import com.reprezen.jsonoverlay.ListOverlay; +import com.reprezen.jsonoverlay.MapOverlay; +import com.reprezen.jsonoverlay.Overlay; +import com.reprezen.jsonoverlay.PropertiesOverlay; +import com.reprezen.jsonoverlay.Reference; + +public class ReferencesChecker { + + public static void checkReferences(ListOverlay list, ValidationResults results) { + Overlay listAdapter = Overlay.of(list); + for (int i = 0; i < list.size(); i++) { + if (listAdapter.isReference(i)) { + checkReference(listAdapter.getReference(i), results, Overlay.of(list, i)); + } + } + } + + public static void checkReferences(MapOverlay map, ValidationResults results) { + Overlay mapAdapter = Overlay.of(map); + for (String key : map.keySet()) { + if (mapAdapter.isReference(key)) { + checkReference(mapAdapter.getReference(key), results, Overlay.of(map, key)); + } + } + } + + public static void checkReferences(PropertiesOverlay props, ValidationResults results) { + if (props._isElaborated()) { + Overlay propsAdapter = Overlay.of(props); + for (String name : propsAdapter.getPropertyNames()) { + if (propsAdapter.isReference(name)) { + checkReference(propsAdapter.getReference(name), results, Overlay.of(props, name, Object.class)); + } + } + } + } + + public static void checkReference(Reference ref, ValidationResults results, Overlay context) { + if (ref.isInvalid()) { + results.addError( + m.msg("BadRef|JSON reference node was not resolved", ref.getRefString(), ref.getInvalidReason()), + context); + } + } +} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/StringValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/StringValidator.java deleted file mode 100755 index acbbbb78..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/StringValidator.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val; - -import com.fasterxml.jackson.databind.node.TextNode; -import com.reprezen.jsonoverlay.StringOverlay; - -public class StringValidator extends OverlayValidator { - - @Override - public void validate(StringOverlay overlay, ValidationResults results) { - super.validate(overlay, results, TextNode.class); - } - -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidationResults.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidationResults.java index b4a19eec..195b8776 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidationResults.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidationResults.java @@ -17,150 +17,133 @@ import static com.reprezen.kaizen.oasparser.val.ValidationResults.Severity.WARNING; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.apache.commons.lang3.StringUtils; - import com.google.common.collect.Lists; -import com.reprezen.jsonoverlay.JsonOverlay; +import com.reprezen.jsonoverlay.Overlay; +import com.reprezen.jsonoverlay.PositionInfo; public class ValidationResults { - public enum Severity { - NONE, INFO, WARNING, ERROR; - - public static final Severity MAX_SEVERITY = ERROR; - - public boolean lt(Severity other) { - return this.compareTo(other) < 0; - } - - public boolean le(Severity other) { - return this.compareTo(other) <= 0; - } - - public boolean gt(Severity other) { - return this.compareTo(other) > 0; - } - - public boolean ge(Severity other) { - return this.compareTo(other) >= 0; - } - }; - - List items = Lists.newArrayList(); - List crumbs = Collections.emptyList(); - - public void addInfo(String msg) { - items.add(new ValidationItem(INFO, msg, crumbs)); - } - - public void addInfo(String msg, String crumb) { - items.add(new ValidationItem(INFO, msg, crumbs, crumb)); - } - - public void addWarning(String msg) { - items.add(new ValidationItem(WARNING, msg, crumbs)); - } - - public void addWarning(String msg, String crumb) { - items.add(new ValidationItem(WARNING, msg, crumbs, crumb)); - } - - public void addError(String msg) { - items.add(new ValidationItem(ERROR, msg, crumbs)); - } - - public void addError(String msg, String crumb) { - items.add(new ValidationItem(ERROR, msg, crumbs, crumb)); - } - - public void add(ValidationResults results) { - items.addAll(results.getItems()); - } - - public Collection getItems() { - return items; - } - - public Severity getSeverity() { - Severity severity = NONE; - for (ValidationItem item : items) { - if (item.getSeverity().gt(severity)) { - severity = item.getSeverity(); - if (severity == MAX_SEVERITY) { - break; - } - } - } - return severity; - } - - public > void validateWithCrumb(String crumb, Validator validator, T object) { - List priorCrumbs = crumbs; - try { - if (crumb != null) { - crumbs = appendCrumb(crumb, priorCrumbs); - } - validator.validate(object, this); - } finally { - crumbs = priorCrumbs; - } - } - - public void withCrumb(String crumb, Runnable code) { - List priorCrumbs = crumbs; - try { - crumbs = appendCrumb(crumb, priorCrumbs); - code.run(); - } finally { - crumbs = priorCrumbs; - } - } - - private static List appendCrumb(String crumb, List existingCrumbs) { - if (crumb != null) { - List newCrumbs = Lists.newArrayList(existingCrumbs); - newCrumbs.add(crumb); - return newCrumbs; - } else { - return existingCrumbs; - } - } - - public static class ValidationItem { - private Severity severity; - private String msg; - private List crumbs; - - public ValidationItem(Severity severity, String msg, List crumbs) { - super(); - this.severity = severity; - this.msg = msg; - this.crumbs = crumbs; - } - - public ValidationItem(Severity severity, String msg, List crumbs, String crumb) { - this(severity, msg, appendCrumb(crumb, crumbs)); - } - - public Severity getSeverity() { - return severity; - } - - public String getMsg() { - return msg; - } - - public List getCrumbs() { - return crumbs; - } - - @Override - public String toString() { - String label = crumbs != null & !crumbs.isEmpty() ? StringUtils.join(crumbs, '.') + ": " : ""; - return label + msg; - } - } + private static ThreadLocal threadInstance = new ThreadLocal(); + + private ValidationResults() { + } + + public static class ValidationResultsInstance implements AutoCloseable { + + private ValidationResults results; + + public ValidationResultsInstance() { + results = threadInstance.get(); + if (results == null) { + results = new ValidationResults(); + threadInstance.set(results); + } + } + + public ValidationResults get() { + return results; + } + + @Override + public void close() { + threadInstance.remove(); + } + } + + public static ValidationResultsInstance open() { + return new ValidationResultsInstance(); + } + + public static ValidationResults get() { + return threadInstance.get(); + } + + public enum Severity { + NONE, INFO, WARNING, ERROR; + + public static final Severity MAX_SEVERITY = ERROR; + + public boolean lt(Severity other) { + return this.compareTo(other) < 0; + } + + public boolean le(Severity other) { + return this.compareTo(other) <= 0; + } + + public boolean gt(Severity other) { + return this.compareTo(other) > 0; + } + + public boolean ge(Severity other) { + return this.compareTo(other) >= 0; + } + }; + + List items = Lists.newArrayList(); + + public void addInfo(String msg, Overlay context) { + items.add(new ValidationItem(INFO, msg, context)); + } + + public void addWarning(String msg, Overlay context) { + items.add(new ValidationItem(WARNING, msg, context)); + } + + public void addError(String msg, Overlay context) { + items.add(new ValidationItem(ERROR, msg, context)); + } + + public void add(ValidationResults results) { + items.addAll(results.getItems()); + } + + public Collection getItems() { + return items; + } + + public Severity getSeverity() { + Severity severity = NONE; + for (ValidationItem item : items) { + if (item.getSeverity().gt(severity)) { + severity = item.getSeverity(); + if (severity == MAX_SEVERITY) { + break; + } + } + } + return severity; + } + + public static class ValidationItem { + private Severity severity; + private String msg; + private PositionInfo positionInfo; + + public ValidationItem(Severity severity, String msg, Overlay context) { + this.severity = severity; + this.msg = msg; + this.positionInfo = context != null ? context.getPositionInfo().orElse(null) : null; + } + + public Severity getSeverity() { + return severity; + } + + public String getMsg() { + return msg; + } + + public PositionInfo getPositionInfo() { + return positionInfo; + } + + @Override + public String toString() { + String posString = positionInfo != null ? positionInfo.toString(true) + ": " : ""; + return posString + msg; + } + } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Validator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Validator.java index da890100..cbe260b6 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Validator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/Validator.java @@ -10,12 +10,8 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val; -public interface Validator { - - ValidationResults validate(T object); - - void validate(T object, ValidationResults results); - - void validate(T object, ValidationResults results, String crumb); +import com.reprezen.jsonoverlay.Overlay; +public interface Validator { + void validate(Overlay value); } \ No newline at end of file diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidatorBase.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidatorBase.java index 74ac625c..0e52ed60 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidatorBase.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/ValidatorBase.java @@ -1,330 +1,374 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ package com.reprezen.kaizen.oasparser.val; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import static com.reprezen.kaizen.oasparser.val.NumericUtils.le; -import static com.reprezen.kaizen.oasparser.val.NumericUtils.lt; -import static com.reprezen.kaizen.oasparser.val.NumericUtils.zero; import java.net.MalformedURLException; import java.net.URL; -import java.util.Collection; +import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; -import javax.print.attribute.standard.Severity; import com.google.common.collect.Sets; -import com.reprezen.jsonoverlay.JsonOverlay; +import com.reprezen.jsonoverlay.ListOverlay; +import com.reprezen.jsonoverlay.MapOverlay; import com.reprezen.jsonoverlay.Overlay; +import com.reprezen.jsonoverlay.PropertiesOverlay; import com.reprezen.kaizen.oasparser.val.oasparser.fake.scheme.Handler; -public abstract class ValidatorBase implements Validator { - - @Override - public ValidationResults validate(T object) { - ValidationResults results = new ValidationResults(); - validate(object, results); - return results; - } - - @Override - public void validate(final T object, final ValidationResults results, String crumb) { - results.withCrumb(crumb, new Runnable() { - @Override - public void run() { - validate(object, results); - } - }); - } - - public void validateString(final String value, final ValidationResults results, final boolean required, - final String crumb) { - validateString(value, results, required, (Pattern) null, crumb); - } - - public void validateString(final String value, final ValidationResults results, final boolean required, - final String pattern, final String crumb) { - validateString(value, results, required, Pattern.compile(pattern), crumb); - } - - public void validateString(final String value, final ValidationResults results, final boolean required, - final Pattern pattern, final String crumb) { - checkMissing(required, value, results, crumb); - if (value != null && pattern != null && !pattern.matcher(value).matches()) { - results.addError(m.msg("PatternMatchFail|String value does not match required pattern", value, pattern), - crumb); - } - } - - public void validateUrl(String value, ValidationResults results, boolean required, String crumb) { - validateUrl(value, results, required, crumb, false); - } - - public void validateUrl(String value, ValidationResults results, boolean required, String crumb, - boolean allowVars) { - validateUrl(value, results, required, crumb, allowVars, Severity.ERROR); - } - - public void validateUrl(final String value, final ValidationResults results, boolean required, String crumb, - final boolean allowVars, final Severity severity) { - validateString(value, results, required, (Pattern) null, crumb); - if (value != null) { - checkUrl(value, results, allowVars, severity, crumb); - } - } - - public void validateEmail(final String value, final ValidationResults results, boolean required, String crumb) { - validateString(value, results, required, (Pattern) null, crumb); - if (value != null) { - checkEmail(value, results, crumb); - } - } - - public void validatePositive(final N value, final ValidationResults results, - final boolean required, final String crumb) { - checkMissing(required, value, results, crumb); - if (value != null && le(value, zero(value))) { - results.addError(m.msg("ReqPositive|Value must be strictly positive", crumb, value), crumb); - } - } - - public void validateNonNegative(final N value, final ValidationResults results, - final boolean required, final String crumb) { - checkMissing(required, value, results, crumb); - if (value != null && lt(value, zero(value))) { - results.addError(m.msg("ReqPositive|Value must be strictly positive", crumb, value), crumb); - } - } - - public void validateNonEmpty(Collection values, boolean hasValues, ValidationResults results, String crumb) { - if (hasValues && values.isEmpty()) { - results.addError(m.msg("EmptyColl|Collection may not be empty"), crumb); - } - } - - public void validateUnique(final Collection values, final ValidationResults results, final String crumb) { - results.withCrumb(crumb, new Runnable() { - Set seen = Sets.newHashSet(); - - @Override - public void run() { - int i = 0; - for (V value : values) { - if (seen.contains(value)) { - results.addError(m.msg("DuplicateValue|Value appeared already", value, crumb), "[" + i + "]"); - } else { - seen.add(value); - } - i += 1; - } - } - }); - } - - public void validatePattern(final String pattern, final ValidationResults results, final boolean required, - final String crumb) { - checkMissing(required, pattern, results, crumb); - if (pattern != null) { - try { - Pattern.compile(pattern); - } catch (PatternSyntaxException e) { - results.addWarning( - m.msg("BadPattern|Pattern is not a valid Java Regular Expression but may be valid ECMA 262", - pattern), - crumb); - } - } - } - - public void validateField(final F value, final ValidationResults results, final boolean required, - final String crumb, final Validator validator) { - checkMissing(required, value, results, crumb); - if (isPresent(value)) { - validator.validate(value, results, crumb); - } - } - - public void validateList(final Collection value, final boolean isPresent, - final ValidationResults results, final boolean required, final String crumb, final Validator validator) { - if (required && !isPresent) { - results.addError(m.msg("MissingField|Required field is missing", crumb), crumb); - } - if (isPresent && validator != null) { - int i = 0; - for (V element : value) { - validator.validate(element, results, "[" + i++ + "]"); - } - } - } - - public void validateMap(final Map value, final ValidationResults results, - final boolean required, final String crumb, final Pattern pattern, final Validator validator) { - checkMissing(required, value, results, crumb); - results.withCrumb(crumb, new Runnable() { - - @Override - public void run() { - for (Entry entry : value.entrySet()) { - checkKey(entry.getKey(), pattern, results); - if (validator != null) { - validator.validate(entry.getValue(), results, entry.getKey()); - } - } - } - }); - } - - public void validateExtensions(final Map extensions, final ValidationResults results) { - validateExtensions(extensions, results, null); - } - - public void validateExtensions(final Map extensions, final ValidationResults results, - String crumb) { - validateMap(extensions, results, false, crumb, null, null); - } - - public void validateFormat(String format, String type, ValidationResults results, String crumb) { - if (format != null && type != null) { - String normalType = null; - switch (format) { - case "int32": - case "int64": - normalType = "integer"; - break; - case "float": - case "double": - normalType = "number"; - break; - case "byte": - case "binary": - case "date": - case "date-time": - case "password": - normalType = "string"; - break; - } - if (normalType != null && !type.equals(normalType)) { - results.addWarning(m.msg("WrongTypeFormat|OpenAPI-defined format used with nonstandard type", format, - type, normalType), crumb); - } - } - } - - public void validateDefault(Object defaultValue, String type, ValidationResults results, String crumb) { - if (defaultValue != null && type != null) { - boolean ok = false; - switch (type) { - case "string": - ok = defaultValue instanceof String; - break; - case "number": - ok = NumericUtils.isNumeric(defaultValue); - break; - case "integer": - ok = NumericUtils.isIntegral(defaultValue); - break; - case "boolean": - ok = defaultValue instanceof Boolean; - break; - case "object": - ok = defaultValue instanceof Map; - break; - case "array": - ok = defaultValue instanceof Collection; - break; - } - if (!ok) { - results.addError(m.msg("WrongTypeValue|Value is incompatible with schema type", type, defaultValue), - crumb); - } - } - } - - private void checkMissing(boolean required, final Object value, final ValidationResults results, - final String crumb) { - if (required && !isPresent(value)) { - results.addError(m.msg("MissingField|Required field is missing", crumb), crumb); - } - } - - private void checkKey(final String key, final Pattern pattern, final ValidationResults results) { - if (pattern != null && !pattern.matcher(key).matches()) { - results.addError(m.msg("BadKey|Invalid key in map", key, pattern), key); - } - } - - public static final String SPECIAL_SCHEME = Handler.class.getPackage().getName() - .substring(ValidatorBase.class.getPackage().getName().length() + 1); - private static boolean specialSchemeInited = false; - - private void checkUrl(String url, ValidationResults results, boolean allowVars, Severity severity, String crumb) { - // TODO Q: Any help from spec in being able to validate URLs with vars? E.g is our treatment here valid? We - // assume vars can only appear where simple text can appear, so handling vars means relacing {.*} with "1" and - // testing for URL validity. We use a digit instead of a letter because it covers vars in the port, and - // elsewhere digits are always allowed where letters are. - String origUrl = url; - if (allowVars) { - url = url.replaceAll("\\{[^}]+\\}", "1"); - if (url.startsWith("1:")) { - // "1" is not a valid scheme name, so we need to replace it with special scheme, for which we provide a - // do-nothing protocol handler implementation - url = SPECIAL_SCHEME + url.substring(1); - if (!specialSchemeInited) { - // register protocol handler for special scheme - initSpecialScheme(); - } - } - } - try { - new URL(url); - } catch (MalformedURLException e) { - results.addError(m.msg("BadUrl|Invalid URL", origUrl, e.toString()), crumb); - } - } - - private void initSpecialScheme() { - String prop = "java.protocol.handler.pkgs"; - String former = System.getProperty(prop); - try { - System.setProperty(prop, ValidatorBase.class.getPackage().getName()); - new URL(SPECIAL_SCHEME + ":"); - } catch (MalformedURLException e) { - } finally { - if (former != null) { - System.setProperty(prop, former); - } else { - System.getProperties().remove(prop); - } - } - specialSchemeInited = true; - } - - private void checkEmail(String email, ValidationResults results, String crumb) { - try { - InternetAddress addr = new InternetAddress(); - addr.setAddress(email); - addr.validate(); - } catch (AddressException e) { - results.addError(m.msg("BadEmail|Invalid email address", email, e.toString()), crumb); - } - } - - private boolean isPresent(Object value) { - return value instanceof JsonOverlay ? Overlay.isPresent((JsonOverlay) value) : value != null; +public abstract class ValidatorBase implements Validator { + protected Overlay value; + protected ValidationResults results; + + @Override + public final void validate(Overlay value) { + this.value = value; + this.results = ValidationResults.get(); + JsonTypeChecker.checkJsonType(value, results); + runValidations(); + } + + public abstract void runValidations(); + + public Overlay validateBooleanField(String name, boolean required) { + return validateField(name, required, Boolean.class, null); + } + + public Overlay validateStringField(String name, boolean required) { + return validateStringField(name, required, (Pattern) null); + } + + public Overlay validateStringField(String name, boolean required, String pattern) { + return validateStringField(name, required, Pattern.compile(pattern)); + } + + @SafeVarargs + public final Overlay validateStringField(String name, boolean required, Pattern pattern, + Consumer>... otherChecks) { + Overlay field = validateField(name, required, String.class, null); + checkMissing(field, required); + if (field != null && field.isPresent()) { + if (pattern != null) { + checkPattern(field, pattern); + } + for (Consumer> otherCheck : otherChecks) { + otherCheck.accept(field); + } + } + return field; + } + + void checkPattern(Overlay field, Pattern pattern) { + if (!pattern.matcher(field.get()).matches()) { + results.addError( + m.msg("PatternMatchFail|String value does not match required pattern", field.get(), pattern), + field); + } + } + + public Overlay validatePatternField(String name, boolean required) { + return validateStringField(name, required, null, this::checkRegex); + } + + private void checkRegex(Overlay field) { + String regex = field.get(); + try { + Pattern.compile(regex); + } catch (PatternSyntaxException e) { + results.addWarning( + m.msg("BadPattern|Pattern is not a valid Java Regular Expression but may be valid ECMA 262", regex), + field); + } + } + + public Overlay validateUrlField(String name, boolean required, boolean allowVars) { + return validateUrlField(name, required, allowVars, (Pattern) null); + } + + public Overlay validateUrlField(String name, boolean required, boolean allowVars, String pattern) { + return validateUrlField(name, required, allowVars, Pattern.compile(pattern)); + } + + public Overlay validateUrlField(String name, boolean required, boolean allowVars, Pattern pattern) { + return validateStringField(name, required, pattern, field -> checkUrl(field, allowVars)); + } + + public static final String SPECIAL_SCHEME = Handler.class.getPackage().getName() + .substring(ValidatorBase.class.getPackage().getName().length() + 1); + private static boolean specialSchemeInited = false; + + private void checkUrl(Overlay overlay, boolean allowVars) { + // TODO Q: Any help from spec in being able to validate URLs with vars? E.g is + // our treatment here valid? We assume vars can only appear where simple text + // can appear, so handling vars means relacing {.*} with "1" and testing for URL + // validity. We use a digit instead of a letter because it covers vars in the + // port, and elsewhere digits are always allowed where letters are. + String origUrl = overlay.get(); + String url = origUrl; + if (allowVars) { + url = url.replaceAll("\\{[^}]+\\}", "1"); + if (url.startsWith("1:")) { + // "1" is not a valid scheme name, so we need to replace it with special scheme, + // for which we provide a do-nothing protocol handler implementation + url = SPECIAL_SCHEME + url.substring(1); + if (!specialSchemeInited) { + // register protocol handler for special scheme + initSpecialScheme(); + } + } + } + try { + new URL(url); + } catch (MalformedURLException e) { + results.addError(m.msg("BadUrl|Invalid URL", origUrl, e.toString()), overlay); + } + } + + private void initSpecialScheme() { + String prop = "java.protocol.handler.pkgs"; + String former = System.getProperty(prop); + try { + System.setProperty(prop, ValidatorBase.class.getPackage().getName()); + new URL(SPECIAL_SCHEME + ":"); + } catch (MalformedURLException e) { + } finally { + if (former != null) { + System.setProperty(prop, former); + } else { + System.getProperties().remove(prop); + } + } + specialSchemeInited = true; + } + + public Overlay validateEmailField(String name, boolean required) { + return validateEmailField(name, required, (Pattern) null); + } + + public Overlay validateUrlField(String name, boolean required, String pattern) { + return validateEmailField(name, required, Pattern.compile(pattern)); + } + + public Overlay validateEmailField(String name, boolean required, Pattern pattern) { + return validateStringField(name, required, pattern, this::checkEmail); + } + + private void checkEmail(Overlay overlay) { + String email = overlay.get(); + try { + InternetAddress addr = new InternetAddress(); + addr.setAddress(email); + addr.validate(); + } catch (AddressException e) { + results.addError(m.msg("BadEmail|Invalid email address", email, e.toString()), overlay); + } + } + + public Overlay validatePositiveField(String name, boolean required) { + return validateNumericField(name, required, NumericUtils::isPositive, "be positive"); + } + + public Overlay validateNonNegativeField(String name, boolean required) { + return validateNumericField(name, required, NumericUtils::isNonNegative, "not be positive"); + } + + public Overlay validateNumericField(String name, boolean required, Function test, + String desc) { + Overlay field = validateField(name, required, Number.class, null); + checkMissing(field, required); + if (field != null && field.isPresent() && test != null) { + Number n = field.get(); + if (!test.apply(n)) { + results.addError(m.msg("ReqPositive|Value must be " + desc, n), field); + } + } + return field; + } + + @SafeVarargs + public final Overlay validateField(String name, boolean required, Class fieldClass, + Validator validator, Consumer>... otherChecks) { + @SuppressWarnings("unchecked") + PropertiesOverlay propValue = (PropertiesOverlay) value.get(); + Overlay field = Overlay.of(propValue, name, fieldClass); + JsonTypeChecker.checkJsonType(field, results); + checkMissing(field, required); + if (value != null && value.isPresent() && validator != null) { + validator.validate(field); + for (Consumer> otherCheck : otherChecks) { + otherCheck.accept(field); + } + } + return field; + } + + public Overlay> validateListField(String name, boolean nonEmpty, boolean unique, Class itemClass, + Validator itemValidator) { + @SuppressWarnings("unchecked") + Overlay> list = (Overlay>) (Object) Overlay.of((PropertiesOverlay) value.get(), name, + List.class); + validateList(list, nonEmpty, unique, itemValidator); + return list; + } + + private void validateList(Overlay> list, boolean nonEmpty, boolean unique, Validator itemValidator) { + new ListValidator(itemValidator).validate(list); + checkListNotEmpty(list, nonEmpty); + checkListUnique(list, unique); + } + + private void checkListNotEmpty(Overlay> list, boolean nonEmpty) { + if (nonEmpty) { + ListOverlay listOverlay = Overlay.getListOverlay(list); + if (list != null && !list.isPresent()) { + if (nonEmpty && listOverlay.size() == 0) { + results.addError(m.msg("EmptyList|List may not be empty"), list); + } + } + } + } + + private void checkListUnique(Overlay> list, boolean unique) { + if (unique) { + ListOverlay listOverlay = Overlay.getListOverlay(list); + Set seen = Sets.newHashSet(); + for (int i = 0; i < listOverlay.size(); i++) { + X item = listOverlay.get(i); + if (seen.contains(item)) { + results.addError(m.msg("DuplicateValue|Value appeared already", item, i), + Overlay.of(listOverlay, i)); + } else { + seen.add(item); + } + } + } + } + + public Overlay> validateMapField(String name, boolean nonEmpty, boolean unique, + Class valueClass, Validator valueValidator) { + @SuppressWarnings("unchecked") + Overlay> map = (Overlay>) (Object) Overlay.of((PropertiesOverlay) value.get(), + name, Map.class); + validateMap(map, nonEmpty, unique, valueValidator); + return map; + } + + private void validateMap(Overlay> map, boolean nonEmpty, boolean unique, + Validator valueValidator) { + new MapValidator(valueValidator).validate(map); + checkMapNotEmpty(map, nonEmpty); + checkMapUnique(map, unique); + } + + private void checkMapNotEmpty(Overlay> list, boolean nonEmpty) { + if (nonEmpty) { + MapOverlay mapOverlay = Overlay.getMapOverlay(list); + if (list != null && !list.isPresent()) { + if (nonEmpty && mapOverlay.size() == 0) { + results.addError(m.msg("EmptyList|List may not be empty"), list); + } + } + } + } + + private void checkMapUnique(Overlay> map, boolean unique) { + if (unique) { + MapOverlay mapOverlay = Overlay.getMapOverlay(map); + Set seen = Sets.newHashSet(); + for (String key : mapOverlay.keySet()) { + X value = mapOverlay.get(key); + if (seen.contains(value)) { + results.addError(m.msg("DuplicateValue|Value appeared already", value, key), + Overlay.of(mapOverlay, key)); + } else { + seen.add(value); + } + } + } + } + + void checkMissing(Overlay field, boolean required) { + if (required && (field == null || !field.isPresent())) { + results.addError(m.msg("MissingField|required field is missing", field.getPathInParent()), value); + } + } + + public Overlay> validateExtensions(Map extensions) { + return validateExtensions(extensions, null); + } + + public Overlay> validateExtensions(Map extensions, String crumb) { + Overlay> mapOverlay = Overlay.of(extensions); + validateMap(mapOverlay, false, false, null); + return mapOverlay; + } + + public Overlay validateFormatField(String name, boolean required, String type) { + Overlay field = validateStringField(name, required); + if (field != null && field.isPresent()) { + String normalType = null; + switch (field.get()) { + case "int32": + case "int64": + normalType = "integer"; + break; + case "float": + case "double": + normalType = "number"; + break; + case "byte": + case "binary": + case "date": + case "date-time": + case "password": + normalType = "string"; + } + if (normalType != null) { + if (type == null || !type.equals(normalType)) { + results.addWarning( + m.msg("WrongTypeFormat|OpenAPI-defined format used with nonstandard or missing type", field, + type, normalType), + field); + } + } + } + return field; + } + + public void checkDefault(Overlay overlay, String type) { + if (overlay != null && overlay.isPresent() && type != null) { + Object defaultValue = overlay.get(); + boolean ok = false; + switch (type) { + case "string": + ok = defaultValue instanceof String; + break; + case "number": + ok = NumericUtils.isNumeric(defaultValue); + break; + case "integer": + ok = NumericUtils.isIntegral(defaultValue); + break; + case "boolean": + ok = defaultValue instanceof Boolean; + break; + case "object": + ok = defaultValue instanceof Map; + break; + case "array": + ok = defaultValue instanceof List; + break; + } + if (!ok) { + results.addError(m.msg("WrongTypeValue|Value is incompatible with schema type", type, defaultValue), + overlay); + } + } } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/oasparser/fake/scheme/Handler.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/oasparser/fake/scheme/Handler.java index 7ae271ea..3f7801b6 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/oasparser/fake/scheme/Handler.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val/oasparser/fake/scheme/Handler.java @@ -16,8 +16,8 @@ import java.net.URLStreamHandler; public class Handler extends URLStreamHandler { - @Override - protected URLConnection openConnection(URL u) throws IOException { - return null; - } + @Override + protected URLConnection openConnection(URL u) throws IOException { + return null; + } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/CallbackValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/CallbackValidator.java index 557536e3..11d464ab 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/CallbackValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/CallbackValidator.java @@ -10,22 +10,19 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.CallbackImpl.F_callbackPaths; + import com.reprezen.kaizen.oasparser.model3.Callback; import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class CallbackValidator extends ObjectValidatorBase { - @Inject - private Validator pathValidator; - @Override - public void validateObject(Callback callback, ValidationResults results) { - validateMap(callback.getCallbackPaths(), results, false, null, Regexes.NOEXT_REGEX, pathValidator); - validateExtensions(callback.getExtensions(), results); + public void runObjectValidations() { + Callback callback = (Callback) value.getOverlay(); + validateMapField(F_callbackPaths, false, false, Path.class, new PathValidator()); + validateExtensions(callback.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ContactValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ContactValidator.java index 3d65b5a0..805d5a00 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ContactValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ContactValidator.java @@ -10,17 +10,19 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.ContactImpl.F_email; +import static com.reprezen.kaizen.oasparser.ovl3.ContactImpl.F_url; + import com.reprezen.kaizen.oasparser.model3.Contact; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class ContactValidator extends ObjectValidatorBase { @Override - public void validateObject(Contact contact, ValidationResults results) { - validateUrl(contact.getUrl(), results, false, "url"); - validateEmail(contact.getEmail(), results, false, "email"); - validateExtensions(contact.getExtensions(), results); + public void runObjectValidations() { + Contact contact = (Contact) value.getOverlay(); + validateUrlField(F_url, false, false); + validateEmailField(F_email, false); + validateExtensions(contact.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/EncodingPropertyValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/EncodingPropertyValidator.java index 50f7e86f..d63ce909 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/EncodingPropertyValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/EncodingPropertyValidator.java @@ -10,20 +10,33 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.EncodingPropertyImpl.F_contentType; +import static com.reprezen.kaizen.oasparser.ovl3.EncodingPropertyImpl.F_explode; +import static com.reprezen.kaizen.oasparser.ovl3.EncodingPropertyImpl.F_headers; +import static com.reprezen.kaizen.oasparser.ovl3.EncodingPropertyImpl.F_style; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_allowReserved; + import com.reprezen.kaizen.oasparser.model3.EncodingProperty; +import com.reprezen.kaizen.oasparser.model3.Header; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class EncodingPropertyValidator extends ObjectValidatorBase { @Override - public void validateObject(EncodingProperty encodingProperty, ValidationResults results) { - // no validation for: contentType, explode - // TODO Q: spec says "Headers" (capitalized) for peroperty name -assuming it's a + public void runObjectValidations() { + EncodingProperty encodingProperty = (EncodingProperty) value.getOverlay(); + + // TODO ought to have a pattern for acceptable values "a/b", "a/*", comma-lists + // of those. + validateStringField(F_contentType, false); + + // TODO Q: spec says "Headers" (capitalized) for property name -assuming it's a // typo - validateMap(encodingProperty.getHeaders(), results, false, "headers", Regexes.NOEXT_REGEX, null); - validateString(encodingProperty.getStyle(), results, false, Regexes.STYLE_REGEX, "style"); - validateExtensions(encodingProperty.getExtensions(), results); + validateMapField(F_headers, false, false, Header.class, null); + validateStringField(F_style, false, Regexes.STYLE_REGEX); + validateBooleanField(F_explode, false); + validateBooleanField(F_allowReserved, false); + validateExtensions(encodingProperty.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExampleValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExampleValidator.java index 3998a858..1bf38836 100644 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExampleValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExampleValidator.java @@ -12,13 +12,12 @@ import com.reprezen.kaizen.oasparser.model3.Example; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class ExampleValidator extends ObjectValidatorBase { @Override - public void validateObject(Example object, ValidationResults results) { - // TODO Auto-generated method stub + public void runObjectValidations() { + // nothing to check } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExternalDocsValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExternalDocsValidator.java index 296a2a24..561c11b9 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExternalDocsValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ExternalDocsValidator.java @@ -10,17 +10,19 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.ExternalDocsImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.ExternalDocsImpl.F_url; + import com.reprezen.kaizen.oasparser.model3.ExternalDocs; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class ExternalDocsValidator extends ObjectValidatorBase { @Override - public void validateObject(ExternalDocs externalDocs, ValidationResults results) { - // no validation for: description - validateUrl(externalDocs.getUrl(), results, true, "externalDocs"); - validateExtensions(externalDocs.getExtensions(), results); + public void runObjectValidations() { + ExternalDocs externalDocs = (ExternalDocs) value.getOverlay(); + validateStringField(F_description, false); + validateUrlField(F_url, true, false); + validateExtensions(externalDocs.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/HeaderValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/HeaderValidator.java index 44f36155..01faccd2 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/HeaderValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/HeaderValidator.java @@ -10,40 +10,46 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_allowEmptyValue; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_contentMediaTypes; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_deprecated; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_example; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_examples; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_explode; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_schema; +import static com.reprezen.kaizen.oasparser.ovl3.HeaderImpl.F_style; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.jsonoverlay.PropertiesOverlay; +import com.reprezen.kaizen.oasparser.model3.Example; import com.reprezen.kaizen.oasparser.model3.Header; import com.reprezen.kaizen.oasparser.model3.MediaType; import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.model3.Schema; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class HeaderValidator extends ObjectValidatorBase
{ - @Inject - private Validator schemaValidator; - @Inject - private Validator mediaTypeValidator; - @Override - public void validateObject(Header header, ValidationResults results) { - // no validations for: description, deprecated, allowEmptyValue, explode, - // example, examples - validateString(header.getName(), results, false, "name"); - validateString(header.getIn(), results, false, Regexes.PARAM_IN_REGEX, "in"); + public void runObjectValidations() { + Header header = (Header) value.getOverlay(); + validateStringField(F_description, false); + validateBooleanField(F_deprecated, false); + validateBooleanField(F_allowEmptyValue, false); + validateBooleanField(F_explode, false); + validateField(F_example, false, Example.class, new ExampleValidator()); + validateMapField(F_examples, false, false, Example.class, new ExampleValidator()); checkPathParam(header, results); checkRequired(header, results); - validateString(header.getStyle(), results, false, Regexes.STYLE_REGEX, "style"); + validateStringField(F_style, false, Regexes.STYLE_REGEX); checkAllowReserved(header, results); // TODO Q: Should schema be required in header object? - validateField(header.getSchema(false), results, false, "schema", schemaValidator); - validateMap(header.getContentMediaTypes(), results, false, "content", Regexes.NOEXT_REGEX, mediaTypeValidator); - validateExtensions(header.getExtensions(), results); + validateField(F_schema, false, Schema.class, new SchemaValidator()); + validateMapField(F_contentMediaTypes, false, false, MediaType.class, new MediaTypeValidator()); + validateExtensions(header.getExtensions()); } private void checkPathParam(Header header, ValidationResults results) { @@ -52,11 +58,11 @@ private void checkPathParam(Header header, ValidationResults results) { if (path != null) { if (!path.matches(".*/\\{" + header.getName() + "\\}(/.*)?")) { results.addError(m.msg("MissingPathTplt|No template for path parameter in path string", - header.getName(), path), "name"); + header.getName(), path), value); } } else { results.addWarning( - m.msg("NoPath|Could not locate path for parameter", header.getName(), header.getIn())); + m.msg("NoPath|Could not locate path for parameter", header.getName(), header.getIn()), value); } } } @@ -66,7 +72,7 @@ private void checkRequired(Header header, ValidationResults results) { if (header.getRequired() != Boolean.TRUE) { results.addError( m.msg("PathParamReq|Path param must have 'required' property set true", header.getName()), - "required"); + value); } } } @@ -74,7 +80,7 @@ private void checkRequired(Header header, ValidationResults results) { private void checkAllowReserved(Header header, ValidationResults results) { if (header.isAllowReserved() && !"query".equals(header.getIn())) { results.addWarning(m.msg("NonQryAllowRsvd|AllowReserved is ignored for non-query parameter", - header.getName(), header.getIn()), "allowReserved"); + header.getName(), header.getIn()), value); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/InfoValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/InfoValidator.java index dec1ba29..6d0e9ffe 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/InfoValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/InfoValidator.java @@ -10,27 +10,25 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.InfoImpl.F_contact; +import static com.reprezen.kaizen.oasparser.ovl3.InfoImpl.F_license; +import static com.reprezen.kaizen.oasparser.ovl3.InfoImpl.F_title; +import static com.reprezen.kaizen.oasparser.ovl3.InfoImpl.F_version; + import com.reprezen.kaizen.oasparser.model3.Contact; import com.reprezen.kaizen.oasparser.model3.Info; import com.reprezen.kaizen.oasparser.model3.License; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class InfoValidator extends ObjectValidatorBase { - @Inject - private Validator contactValidator; - @Inject - private Validator licenseValidator; - @Override - public void validateObject(Info info, ValidationResults results) { - validateString(info.getTitle(), results, true, "title"); - validateField(info.getContact(false), results, false, "contact", contactValidator); - validateField(info.getLicense(false), results, false, "license", licenseValidator); - validateString(info.getVersion(), results, true, "version"); - validateExtensions(info.getExtensions(), results); + public void runObjectValidations() { + Info info = (Info) value.getOverlay(); + validateStringField(F_title, true); + validateField(F_contact, false, Contact.class, new ContactValidator()); + validateField(F_license, false, License.class, new LicenseValidator()); + validateStringField(F_version, true); + validateExtensions(info.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LicenseValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LicenseValidator.java index a8c52b6b..0dcca5b5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LicenseValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LicenseValidator.java @@ -10,17 +10,20 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.LicenseImpl.F_name; +import static com.reprezen.kaizen.oasparser.ovl3.LicenseImpl.F_url; + import com.reprezen.kaizen.oasparser.model3.License; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class LicenseValidator extends ObjectValidatorBase { @Override - public void validateObject(License license, ValidationResults results) { - validateString(license.getName(), results, true, "name"); - validateUrl(license.getUrl(), results, false, "url"); - validateExtensions(license.getExtensions(), results); + public void runObjectValidations() { + License license = (License) value.getOverlay(); + validateStringField(F_name, true); + validateUrlField(F_url, false, false); + validateExtensions(license.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LinkValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LinkValidator.java index e3d12c1a..d9623e28 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LinkValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/LinkValidator.java @@ -10,13 +10,13 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.LinkImpl.F_headers; import static com.reprezen.kaizen.oasparser.val.Messages.m; import java.util.Collection; import java.util.Map; import com.google.common.collect.Maps; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.kaizen.oasparser.model3.Header; import com.reprezen.kaizen.oasparser.model3.Link; @@ -26,24 +26,20 @@ import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class LinkValidator extends ObjectValidatorBase { - @Inject - private Validator
headerValidator; - @Override - public void validateObject(Link link, ValidationResults results) { - // no validation for: description + public void runObjectValidations() { // TODO: Validate operationRef value (why didn't they must make it a ref // object???!) + Link link = (Link) value.getOverlay(); Operation op = checkValidOperation(link, results); if (op != null) { checkParameters(link, op, results); } - validateMap(link.getHeaders(), results, false, "headers", Regexes.NOEXT_REGEX, headerValidator); - validateExtensions(link.getExtensions(), results); + validateMapField(F_headers, false, false, Header.class, new HeaderValidator()); + validateExtensions(link.getExtensions()); } private Operation checkValidOperation(Link link, ValidationResults results) { @@ -52,10 +48,12 @@ private Operation checkValidOperation(Link link, ValidationResults results) { Operation op = null; if (opId == null && operationRef == null) { results.addError( - m.msg("NoOpIdNoOpRefInLink|Link must contain eitehr 'operationRef' or 'operationId' properties")); + m.msg("NoOpIdNoOpRefInLink|Link must contain eitehr 'operationRef' or 'operationId' properties"), + value); } else if (opId != null && operationRef != null) { results.addError( - m.msg("OpIdAndOpRefInLink|Link may not contain both 'operationRef' and 'operationId' properties")); + m.msg("OpIdAndOpRefInLink|Link may not contain both 'operationRef' and 'operationId' properties"), + value); } if (opId != null) { op = findOperationById(Overlay.of(link).getModel(), opId); @@ -63,7 +61,7 @@ private Operation checkValidOperation(Link link, ValidationResults results) { results.addError( m.msg("OpIdNotFound|OperationId in Link does not identify an operation in the containing model", opId), - "operationId"); + value); } } String relativePath = getRelativePath(operationRef, results); @@ -72,7 +70,7 @@ private Operation checkValidOperation(Link link, ValidationResults results) { if (op == null) { results.addError(m.msg( "OpPathNotFound|Relative OperationRef in Link does not identify a GET operation in the containing model", - operationRef), "operationRef"); + operationRef), value); } // } @@ -80,20 +78,22 @@ private Operation checkValidOperation(Link link, ValidationResults results) { } private void checkParameters(Link link, Operation op, ValidationResults results) { - // TODO Q: parameter name is not sufficient to identify param in operation; will + // TODO Q: parameter name is not sufficient to identify param in + // operation; will // allow if it's unique, warn if // it's not Map opParamCounts = getParamNameCounts(op.getParameters()); - for (String paramName : link.getParameters().keySet()) { + Map params = link.getParameters(); + for (String paramName : params.keySet()) { int count = opParamCounts.get(paramName); if (count == 0) { results.addError(m.msg("BadLinkParam|Link parameter does not appear in linked operation", paramName), - paramName); + Overlay.of(params, paramName)); } else if (count > 1) { results.addWarning( m.msg("AmbigLinkParam|Link parameter name appears more than once in linked operation", paramName), - paramName); + Overlay.of(params, paramName)); } } } @@ -117,7 +117,7 @@ private Operation findOperationByPath(OpenApi3 model, String relativePath, Valid private String getRelativePath(String operationRef, ValidationResults results) { // TODO Q: will braces be pct-encoded as required for URIs? if (operationRef != null) { - results.addWarning("OperationRefUnSupp|Link.operationRef is not yet supported", "operationRef"); + results.addWarning(m.msg("OperationRefUnSupp|Link.operationRef is not yet supported"), value); } return null; } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/MediaTypeValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/MediaTypeValidator.java index 58fb7874..1c82e728 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/MediaTypeValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/MediaTypeValidator.java @@ -10,11 +10,14 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl.F_encodingProperties; +import static com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl.F_examples; +import static com.reprezen.kaizen.oasparser.ovl3.MediaTypeImpl.F_schema; import static com.reprezen.kaizen.oasparser.val.Messages.m; +import java.util.Map; import java.util.Set; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.kaizen.oasparser.model3.EncodingProperty; import com.reprezen.kaizen.oasparser.model3.Example; @@ -22,27 +25,18 @@ import com.reprezen.kaizen.oasparser.model3.Schema; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class MediaTypeValidator extends ObjectValidatorBase { - @Inject - private Validator schemaValidator; - @Inject - private Validator encodingPropertyValidator; - @Inject - private Validator exampleValidator; - @Override - public void validateObject(MediaType mediaType, ValidationResults results) { - // no validation for: example, examples + public void runObjectValidations() { + MediaType mediaType = (MediaType) value.getOverlay(); // TODO Q: Should schema be required in media type? - validateField(mediaType.getSchema(false), results, false, "schema", schemaValidator); - validateMap(mediaType.getEncodingProperties(), results, false, "encoding", Regexes.NOEXT_NAME_REGEX, - encodingPropertyValidator); + validateField(F_schema, false, Schema.class, new SchemaValidator()); + validateMapField(F_encodingProperties, false, false, EncodingProperty.class, new EncodingPropertyValidator()); checkEncodingPropsAreProps(mediaType, results); - validateExtensions(mediaType.getExtensions(), results); - validateMap(mediaType.getExamples(), results, false, "examples", Regexes.NOEXT_NAME_REGEX, exampleValidator); + validateExtensions(mediaType.getExtensions()); + validateMapField(F_examples, false, false, Example.class, new ExampleValidator()); } void checkEncodingPropsAreProps(MediaType mediaType, ValidationResults results) { @@ -51,11 +45,12 @@ void checkEncodingPropsAreProps(MediaType mediaType, ValidationResults results) Schema schema = mediaType.getSchema(false); if (Overlay.of(schema).isElaborated()) { Set propNames = schema.getProperties().keySet(); - for (String encodingPropertyName : mediaType.getEncodingProperties().keySet()) { + Map encProps = mediaType.getEncodingProperties(); + for (String encodingPropertyName : encProps.keySet()) { if (!propNames.contains(encodingPropertyName)) { results.addError(m.msg( "EncPropNotSchemaProp|Encoding property does not name a schema property for the media type", - encodingPropertyName), encodingPropertyName); + encodingPropertyName), Overlay.of(encProps, encodingPropertyName)); } } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OAuthFlowValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OAuthFlowValidator.java index a77fcd88..22ada652 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OAuthFlowValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OAuthFlowValidator.java @@ -10,19 +10,23 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.OAuthFlowImpl.F_authorizationUrl; +import static com.reprezen.kaizen.oasparser.ovl3.OAuthFlowImpl.F_refreshUrl; +import static com.reprezen.kaizen.oasparser.ovl3.OAuthFlowImpl.F_scopes; +import static com.reprezen.kaizen.oasparser.ovl3.OAuthFlowImpl.F_tokenUrl; + import com.reprezen.kaizen.oasparser.model3.OAuthFlow; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class OAuthFlowValidator extends ObjectValidatorBase { @Override - public void validateObject(OAuthFlow oauthFlow, ValidationResults results) { - validateUrl(oauthFlow.getAuthorizationUrl(), results, true, "authorizationUrl"); - validateUrl(oauthFlow.getTokenUrl(), results, true, "tokenUrl"); - validateUrl(oauthFlow.getRefreshUrl(), results, true, "refreshUrl"); - validateMap(oauthFlow.getScopes(), results, true, "scopes", Regexes.NOEXT_REGEX, null); - validateExtensions(oauthFlow.getExtensions(), results); + public void runObjectValidations() { + OAuthFlow oauthFlow = (OAuthFlow) value.getOverlay(); + validateUrlField(F_authorizationUrl, true, false); + validateUrlField(F_tokenUrl, true, false); + validateUrlField(F_refreshUrl, true, false); + validateMapField(F_scopes, true, false, String.class, null); + validateExtensions(oauthFlow.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OpenApi3Validator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OpenApi3Validator.java index f4f93909..5f9b3af0 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OpenApi3Validator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OpenApi3Validator.java @@ -10,12 +10,25 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import static com.reprezen.kaizen.oasparser.val3.Regexes.EXT_REGEX; -import static com.reprezen.kaizen.oasparser.val3.Regexes.NAME_REGEX; -import static com.reprezen.kaizen.oasparser.val3.Regexes.PATH_REGEX; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_callbacks; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_examples; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_externalDocs; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_headers; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_info; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_links; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_openApi; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_parameters; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_paths; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_requestBodies; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_responses; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_schemas; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_securityRequirements; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_securitySchemes; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_servers; +import static com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.F_tags; -import com.google.inject.Inject; import com.reprezen.kaizen.oasparser.model3.Callback; +import com.reprezen.kaizen.oasparser.model3.Example; import com.reprezen.kaizen.oasparser.model3.ExternalDocs; import com.reprezen.kaizen.oasparser.model3.Header; import com.reprezen.kaizen.oasparser.model3.Info; @@ -31,71 +44,31 @@ import com.reprezen.kaizen.oasparser.model3.Server; import com.reprezen.kaizen.oasparser.model3.Tag; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class OpenApi3Validator extends ObjectValidatorBase { - @Inject - private Validator infoValidator; - @Inject - private Validator serverValidator; - @Inject - private Validator pathValidator; - @Inject - private Validator schemaValidator; - @Inject - private Validator responseValidator; - @Inject - private Validator parameterValidator; - @Inject - private Validator requestBodyValidator; - @Inject - private Validator
headerValidator; - @Inject - private Validator securitySchemeValidator; - @Inject - private Validator linkValidator; - @Inject - private Validator callbackValidator; - @Inject - private Validator securityRequirementValidator; - @Inject - private Validator tagValidator; - @Inject - private Validator externalDocsValidator; - @Override - public void validateObject(final OpenApi3 swagger, final ValidationResults results) { - results.withCrumb("model", new Runnable() { - @Override - public void run() { - validateString(swagger.getOpenApi(), results, true, "3\\.\\d+(\\.\\d+.*)?", "openapi"); - validateField(swagger.getInfo(false), results, true, "info", infoValidator); - validateList(swagger.getServers(), swagger.hasServers(), results, false, "servers", serverValidator); - validateMap(swagger.getPaths(), results, true, "paths", PATH_REGEX, pathValidator); - validateMap(swagger.getPathsExtensions(), results, false, "paths", EXT_REGEX, null); - validateMap(swagger.getSchemas(), results, false, "collections/schemas", NAME_REGEX, schemaValidator); - validateMap(swagger.getResponses(), results, false, "collections/responses", NAME_REGEX, - responseValidator); - validateMap(swagger.getParameters(), results, false, "collections/parameters", NAME_REGEX, - parameterValidator); - validateMap(swagger.getExamples(), results, false, "collections/examples", NAME_REGEX, null); - validateMap(swagger.getRequestBodies(), results, false, "collection/requestBodies", NAME_REGEX, - requestBodyValidator); - validateMap(swagger.getHeaders(), results, false, "collections/headers", NAME_REGEX, headerValidator); - validateMap(swagger.getSecuritySchemes(), results, false, "collections/securitySchemes", NAME_REGEX, - securitySchemeValidator); - validateMap(swagger.getLinks(), results, false, "collections/links", NAME_REGEX, linkValidator); - validateMap(swagger.getCallbacks(), results, false, "collections/callbacks", NAME_REGEX, - callbackValidator); - validateMap(swagger.getComponentsExtensions(), results, false, "collections", EXT_REGEX, null); - validateList(swagger.getSecurityRequirements(), swagger.hasSecurityRequirements(), results, false, - "security", securityRequirementValidator); - validateList(swagger.getTags(), swagger.hasTags(), results, false, "tags", tagValidator); - validateField(swagger.getExternalDocs(false), results, false, "externalDocs", externalDocsValidator); - validateExtensions(swagger.getExtensions(), results); - } - }); + public void runObjectValidations() { + OpenApi3 model = (OpenApi3) value.getOverlay(); + validateStringField(F_openApi, true, "3\\.\\d+(\\.\\d+.*)?"); + validateField(F_info, true, Info.class, new InfoValidator()); + validateListField(F_servers, false, false, Server.class, new ServerValidator()); + validateMapField(F_paths, true, false, Path.class, new PathValidator()); + validateExtensions(model.getPathsExtensions()); + validateMapField(F_schemas, false, false, Schema.class, new SchemaValidator()); + validateMapField(F_responses, false, false, Response.class, new ResponseValidator()); + validateMapField(F_parameters, false, false, Parameter.class, new ParameterValidator()); + validateMapField(F_examples, false, false, Example.class, new ExampleValidator()); + validateMapField(F_requestBodies, false, false, RequestBody.class, new RequestBodyValidator()); + validateMapField(F_headers, false, false, Header.class, new HeaderValidator()); + validateMapField(F_securitySchemes, false, false, SecurityScheme.class, new SecuritySchemeValidator()); + validateMapField(F_links, false, false, Link.class, new LinkValidator()); + validateMapField(F_callbacks, false, false, Callback.class, new CallbackValidator()); + validateExtensions(model.getComponentsExtensions()); + validateListField(F_securityRequirements, false, false, SecurityRequirement.class, + new SecurityRequirementValidator()); + validateListField(F_tags, false, false, Tag.class, new TagValidator()); + validateField(F_externalDocs, false, ExternalDocs.class, new ExternalDocsValidator()); + validateExtensions(model.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OperationValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OperationValidator.java index 4aaa8b1e..51dbfa70 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OperationValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/OperationValidator.java @@ -10,9 +10,21 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_callbacks; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_externalDocs; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_operationId; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_parameters; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_requestBody; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_responses; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_securityRequirements; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_servers; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_summary; +import static com.reprezen.kaizen.oasparser.ovl3.OperationImpl.F_tags; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import com.google.inject.Inject; +import java.util.regex.Pattern; + +import com.reprezen.jsonoverlay.Overlay; import com.reprezen.kaizen.oasparser.model3.Callback; import com.reprezen.kaizen.oasparser.model3.ExternalDocs; import com.reprezen.kaizen.oasparser.model3.Operation; @@ -22,49 +34,30 @@ import com.reprezen.kaizen.oasparser.model3.SecurityRequirement; import com.reprezen.kaizen.oasparser.model3.Server; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class OperationValidator extends ObjectValidatorBase { - @Inject - private Validator externalDocsValidator; - @Inject - private Validator parameterValidator; - @Inject - private Validator requestBodyValidator; - @Inject - private Validator responseValidator; - @Inject - private Validator callbackValidator; - @Inject - private Validator securityRequirementValidator; - @Inject - private Validator serverValidator; - @Override - public void validateObject(Operation operation, ValidationResults results) { - // no validation for: tags, description, deprecated - checkSummaryLength(operation, results); - validateField(operation.getExternalDocs(false), results, false, "externalDocs", externalDocsValidator); + public void runObjectValidations() { + validateListField(F_tags, false, false, String.class, null); + validateStringField(F_summary, false, (Pattern) null, this::checkSummaryLength); + validateField(F_externalDocs, false, ExternalDocs.class, new ExternalDocsValidator()); // TODO Q: Not marked as required in spec, but spec says they all must be unique // within the API. Seems like it // should be required. - validateString(operation.getOperationId(), results, false, "operationId"); - validateList(operation.getParameters(), operation.hasParameters(), results, false, "parameters", - parameterValidator); - validateField(operation.getRequestBody(false), results, false, "requestBody", requestBodyValidator); - validateMap(operation.getResponses(), results, true, "responses", Regexes.RESPONSE_REGEX, responseValidator); - validateMap(operation.getCallbacks(), results, false, "callbacks", Regexes.NOEXT_REGEX, callbackValidator); - validateList(operation.getSecurityRequirements(), operation.hasSecurityRequirements(), results, false, - "security", securityRequirementValidator); - validateList(operation.getServers(), operation.hasServers(), results, false, "servers", serverValidator); + validateStringField(F_operationId, false); + validateListField(F_parameters, false, false, Parameter.class, new ParameterValidator()); + validateField(F_requestBody, false, RequestBody.class, new RequestBodyValidator()); + validateMapField(F_responses, true, false, Response.class, new ResponseValidator()); + validateMapField(F_callbacks, false, false, Callback.class, new CallbackValidator()); + validateListField(F_securityRequirements, false, false, SecurityRequirement.class, + new SecurityRequirementValidator()); + validateListField(F_servers, false, false, Server.class, new ServerValidator()); } - private void checkSummaryLength(Operation operation, ValidationResults results) { - String summary = operation.getSummary(); - if (summary != null && summary.length() > 120) { - results.addWarning(m.msg("LongSummary|Sumamry exceeds recommended limit of 120 chars"), "summary"); + private void checkSummaryLength(Overlay summary) { + if (summary != null && summary.isPresent() && summary.get().length() > 120) { + results.addWarning(m.msg("LongSummary|Sumamry exceeds recommended limit of 120 chars"), summary); } } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ParameterValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ParameterValidator.java index c94da505..50d56691 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ParameterValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ParameterValidator.java @@ -10,72 +10,81 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_allowEmptyValue; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_contentMediaTypes; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_deprecated; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_example; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_examples; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_explode; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_in; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_name; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_schema; +import static com.reprezen.kaizen.oasparser.ovl3.ParameterImpl.F_style; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.jsonoverlay.PropertiesOverlay; +import com.reprezen.kaizen.oasparser.model3.Example; import com.reprezen.kaizen.oasparser.model3.MediaType; import com.reprezen.kaizen.oasparser.model3.Parameter; import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.model3.Schema; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class ParameterValidator extends ObjectValidatorBase { - @Inject - private Validator schemaValidator; - @Inject - private Validator mediaTypeValidator; - @Override - public void validateObject(Parameter parameter, ValidationResults results) { - // no validations for: description, deprecated, allowEmptyValue, explode, - // example, examples - validateString(parameter.getName(), results, true, "name"); - validateString(parameter.getIn(), results, true, Regexes.PARAM_IN_REGEX, "in"); - checkPathParam(parameter, results); - checkRequired(parameter, results); - validateString(parameter.getStyle(), results, false, Regexes.STYLE_REGEX, "style"); - checkAllowReserved(parameter, results); + public void runObjectValidations() { + Parameter parameter = (Parameter) value.getOverlay(); + validateStringField(F_description, false); + validateBooleanField(F_deprecated, false); + validateBooleanField(F_allowEmptyValue, false); + validateBooleanField(F_explode, false); + validateField(F_example, false, Example.class, new ExampleValidator()); + validateMapField(F_examples, false, false, Example.class, new ExampleValidator()); + validateStringField(F_name, true); + validateStringField(F_in, true, Regexes.PARAM_IN_REGEX); + checkPathParam(parameter); + checkRequired(parameter); + validateStringField(F_style, false, Regexes.STYLE_REGEX); + checkAllowReserved(parameter); // TODO Q: Should schema be required in parameter object? - validateField(parameter.getSchema(false), results, false, "schema", schemaValidator); - validateMap(parameter.getContentMediaTypes(), results, false, "content", Regexes.NOEXT_REGEX, - mediaTypeValidator); - validateExtensions(parameter.getExtensions(), results); + validateField(F_schema, false, Schema.class, new SchemaValidator()); + validateMapField(F_contentMediaTypes, false, false, MediaType.class, new MediaTypeValidator()); + validateExtensions(parameter.getExtensions()); } - private void checkPathParam(Parameter parameter, ValidationResults results) { + private void checkPathParam(Parameter parameter) { if (parameter.getIn() != null && parameter.getIn().equals("path") && parameter.getName() != null) { String path = getPathString(parameter); if (path != null) { if (!path.matches(".*/\\{" + parameter.getName() + "\\}(/.*)?")) { results.addError(m.msg("MissingPathTplt|No template for path parameter in path string", - parameter.getName(), path), "name"); + parameter.getName(), path), value); } } else { results.addWarning( - m.msg("NoPath|Could not locate path for parameter", parameter.getName(), parameter.getIn())); + m.msg("NoPath|Could not locate path for parameter", parameter.getName(), parameter.getIn()), + value); } } } - private void checkRequired(Parameter parameter, ValidationResults results) { + private void checkRequired(Parameter parameter) { if ("path".equals(parameter.getIn())) { if (parameter.getRequired() != Boolean.TRUE) { results.addError( m.msg("PathParamReq|Path param must have 'required' property set true", parameter.getName()), - "required"); + value); } } } - private void checkAllowReserved(Parameter parameter, ValidationResults results) { + private void checkAllowReserved(Parameter parameter) { if (parameter.isAllowReserved() && !"query".equals(parameter.getIn())) { results.addWarning(m.msg("NonQryAllowRsvd|AllowReserved is ignored for non-query parameter", - parameter.getName(), parameter.getIn()), "allowReserved"); + parameter.getName(), parameter.getIn()), value); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/PathValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/PathValidator.java index 6a76ef82..89321549 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/PathValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/PathValidator.java @@ -10,30 +10,28 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.PathImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.PathImpl.F_operations; +import static com.reprezen.kaizen.oasparser.ovl3.PathImpl.F_parameters; +import static com.reprezen.kaizen.oasparser.ovl3.PathImpl.F_servers; +import static com.reprezen.kaizen.oasparser.ovl3.PathImpl.F_summary; + import com.reprezen.kaizen.oasparser.model3.Operation; import com.reprezen.kaizen.oasparser.model3.Parameter; import com.reprezen.kaizen.oasparser.model3.Path; import com.reprezen.kaizen.oasparser.model3.Server; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class PathValidator extends ObjectValidatorBase { - @Inject - private Validator operationValidator; - @Inject - private Validator serverValidator; - @Inject - private Validator parameterValidator; - @Override - public void validateObject(Path path, ValidationResults results) { - // no validation for: summary, description - validateMap(path.getOperations(), results, false, null, Regexes.METHOD_REGEX, operationValidator); - validateList(path.getServers(), path.hasServers(), results, false, "servers", serverValidator); - validateList(path.getParameters(), path.hasParameters(), results, false, "parameters", parameterValidator); - validateExtensions(path.getExtensions(), results); + public void runObjectValidations() { + Path path = (Path) value.getOverlay(); + validateStringField(F_summary, false); + validateStringField(F_description, false); + validateMapField(F_operations, false, false, Operation.class, new OperationValidator()); + validateListField(F_servers, false, false, Server.class, new ServerValidator()); + validateListField(F_parameters, false, false, Parameter.class, new ParameterValidator()); + validateExtensions(path.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/RequestBodyValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/RequestBodyValidator.java index a2cd1830..2c150d56 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/RequestBodyValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/RequestBodyValidator.java @@ -10,24 +10,22 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.RequestBodyImpl.F_contentMediaTypes; +import static com.reprezen.kaizen.oasparser.ovl3.RequestBodyImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.RequestBodyImpl.F_required; + import com.reprezen.kaizen.oasparser.model3.MediaType; import com.reprezen.kaizen.oasparser.model3.RequestBody; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class RequestBodyValidator extends ObjectValidatorBase { - @Inject - private Validator mediaTypeValidator; - @Override - public void validateObject(RequestBody requestBody, ValidationResults results) { - // no validation for: description, required - validateMap(requestBody.getContentMediaTypes(), results, false, "content", Regexes.NOEXT_REGEX, - mediaTypeValidator); - validateExtensions(requestBody.getExtensions(), results); + public void runObjectValidations() { + RequestBody requestBody = (RequestBody) value.getOverlay(); + validateStringField(F_description, false); + validateBooleanField(F_required, false); + validateMapField(F_contentMediaTypes, false, false, MediaType.class, new MediaTypeValidator()); + validateExtensions(requestBody.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ResponseValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ResponseValidator.java index 50dd046c..83fb4f33 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ResponseValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ResponseValidator.java @@ -10,30 +10,24 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.ResponseImpl.F_contentMediaTypes; +import static com.reprezen.kaizen.oasparser.ovl3.ResponseImpl.F_headers; +import static com.reprezen.kaizen.oasparser.ovl3.ResponseImpl.F_links; + import com.reprezen.kaizen.oasparser.model3.Header; import com.reprezen.kaizen.oasparser.model3.Link; import com.reprezen.kaizen.oasparser.model3.MediaType; import com.reprezen.kaizen.oasparser.model3.Response; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class ResponseValidator extends ObjectValidatorBase { - @Inject - private Validator
headerValidator; - @Inject - private Validator mediaTypeValidator; - @Inject - private Validator linkValidator; - @Override - public void validateObject(Response response, ValidationResults results) { - validateMap(response.getHeaders(), results, false, "headers", null, headerValidator); - validateMap(response.getContentMediaTypes(), results, false, "content", Regexes.NOEXT_REGEX, - mediaTypeValidator); - validateMap(response.getLinks(), results, false, "links", Regexes.NOEXT_NAME_REGEX, linkValidator); - validateExtensions(response.getExtensions(), results); + public void runObjectValidations() { + Response response = (Response) value.getOverlay(); + validateMapField(F_headers, false, false, Header.class, new HeaderValidator()); + validateMapField(F_contentMediaTypes, false, false, MediaType.class, new MediaTypeValidator()); + validateMapField(F_links, false, false, Link.class, new LinkValidator()); + validateExtensions(response.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SchemaValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SchemaValidator.java index 7a365f84..50840b06 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SchemaValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SchemaValidator.java @@ -10,85 +10,111 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_allOfSchemas; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_anyOfSchemas; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_defaultValue; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_deprecated; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_discriminator; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_enums; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_example; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_examples; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_exclusiveMaximum; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_exclusiveMinimum; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_externalDocs; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_format; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_itemsSchema; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_maxItems; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_maxLength; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_maxProperties; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_maximum; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_minItems; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_minLength; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_minProperties; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_minimum; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_multipleOf; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_notSchema; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_nullable; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_oneOfSchemas; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_pattern; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_properties; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_requiredFields; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_title; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_type; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_uniqueItems; +import static com.reprezen.kaizen.oasparser.ovl3.SchemaImpl.F_xml; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import com.google.inject.Inject; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.kaizen.oasparser.model3.Example; import com.reprezen.kaizen.oasparser.model3.ExternalDocs; import com.reprezen.kaizen.oasparser.model3.Schema; import com.reprezen.kaizen.oasparser.model3.Xml; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class SchemaValidator extends ObjectValidatorBase { - @Inject - private Validator xmlValidator; - @Inject - private Validator externalDocsValidator; - @Inject - private Validator exampleValidator; - @Override - public void validateObject(Schema schema, ValidationResults results) { - // no validation for: title, description, maximum, exclusiveMaximum, minimum - // exclusiveMinimum, uniqueItems, - // nullable, example, deprecated - validatePositive(schema.getMultipleOf(), results, false, "multipleOf"); - validateNonNegative(schema.getMaxLength(), results, false, "maxLength"); - validateNonNegative(schema.getMinLength(), results, false, "minLength"); - validatePattern(schema.getPattern(), results, false, "pattern"); - validateNonNegative(schema.getMaximum(), results, false, "maxItems"); - validateNonNegative(schema.getMaximum(), results, false, "minItems"); - validateNonNegative(schema.getMaxProperties(), results, false, "maxProperties"); - validateNonNegative(schema.getMinProperties(), results, false, "minProperties"); - validateUnique(schema.getRequiredFields(), results, "required"); - validateList(schema.getEnums(), schema.hasEnums(), results, false, "enum", null); - validateNonEmpty(schema.getEnums(), schema.hasEnums(), results, "enum"); - validateUnique(schema.getEnums(), results, "enum"); - validateString(schema.getType(), results, false, "boolean|object|array|number|integer|string", "type"); - validateList(schema.getAllOfSchemas(), schema.hasAllOfSchemas(), results, false, "allOf", this); - validateList(schema.getOneOfSchemas(), schema.hasOneOfSchemas(), results, false, "oneOf", this); - validateList(schema.getAnyOfSchemas(), schema.hasAnyOfSchemas(), results, false, "anyOf", this); - if (schema.getNotSchema(false) != null && Overlay.of(schema.getNotSchema(false)).isPresent()) { - validate(schema.getNotSchema(false), results, "not"); - } - if (schema.getItemsSchema(false) != null && Overlay.of(schema.getItemsSchema(false)).isPresent()) { - validate(schema.getItemsSchema(false), results, "items"); + public void runObjectValidations() { + Schema schema = (Schema) value.getOverlay(); + validateStringField(F_title, false); + validateStringField(F_description, false); + validateNumericField(F_maximum, false, null, null); + validateBooleanField(F_exclusiveMaximum, false); + validateNumericField(F_minimum, false, null, null); + validateBooleanField(F_exclusiveMinimum, false); + validateBooleanField(F_uniqueItems, false); + validateBooleanField(F_nullable, false); + validateField(F_example, false, Example.class, new ExampleValidator()); + validateBooleanField(F_deprecated, false); + validatePositiveField(F_multipleOf, false); + validateNonNegativeField(F_maxLength, false); + validateNonNegativeField(F_minLength, false); + validatePatternField(F_pattern, false); + validateNonNegativeField(F_maxItems, false); + validateNonNegativeField(F_minItems, false); + validateNonNegativeField(F_maxProperties, false); + validateNonNegativeField(F_minProperties, false); + validateListField(F_requiredFields, false, true, String.class, null); + validateListField(F_enums, false, true, Object.class, null); + validateStringField(F_type, false, "boolean|object|array|number|integer|string"); + { + SchemaValidator schemaValidator = new SchemaValidator(); + validateListField(F_allOfSchemas, false, false, Schema.class, schemaValidator); + validateListField(F_oneOfSchemas, false, false, Schema.class, schemaValidator); + validateListField(F_anyOfSchemas, false, false, Schema.class, schemaValidator); + validateField(F_notSchema, false, Schema.class, schemaValidator); + validateField(F_itemsSchema, false, Schema.class, schemaValidator); + validateMapField(F_properties, false, false, Schema.class, schemaValidator); } - validateMap(schema.getProperties(), results, false, "properties", null, this); - validateFormat(schema.getFormat(), schema.getType(), results, "format"); - validateDefault(schema.getDefault(), schema.getType(), results, "default"); - checkDiscriminator(schema, results, "discriminator"); - checkReadWrite(schema, results); - validateField(schema.getXml(false), results, false, "xml", xmlValidator); - validateField(schema.getExternalDocs(false), results, false, "externalDocs", externalDocsValidator); - validateMap(schema.getExamples(), results, false, "examples", Regexes.NOEXT_NAME_REGEX, exampleValidator); - validateExtensions(schema.getExtensions(), results); + validateFormatField(F_format, false, schema.getType()); + validateField(F_defaultValue, false, Object.class, null, field -> checkDefault(field, schema.getType())); + checkDiscriminator(schema, validateStringField(F_discriminator, false)); + checkReadWrite(schema); + validateField(F_xml, false, Xml.class, new XmlValidator()); + validateField(F_externalDocs, false, ExternalDocs.class, new ExternalDocsValidator()); + validateMapField(F_examples, false, false, Example.class, new ExampleValidator()); + validateExtensions(schema.getExtensions()); } - private void checkDiscriminator(Schema schema, ValidationResults results, String crumb) { + private void checkDiscriminator(Schema schema, Overlay context) { String discriminator = schema.getDiscriminator(); if (discriminator != null) { if (!schema.getProperties().keySet().contains(discriminator)) { results.addError(m.msg("DiscNotProp|The discriminator is not a property of this schema", discriminator), - crumb); + context); } if (!schema.getRequiredFields().contains(discriminator)) { results.addError( m.msg("DiscNotReq|The discriminator property is not required in this schema", discriminator), - crumb); + context); } } } - private void checkReadWrite(Schema schema, ValidationResults results) { + private void checkReadWrite(Schema schema) { if (schema.isReadOnly() && schema.isWriteOnly()) { - // don't set crumb... this validation involves multiple fields so is tied to - // schema - results.addError(m.msg("ROnlyAndWOnly|Schema cannot be both ReadOnly and WriteOnly")); + results.addError(m.msg("ROnlyAndWOnly|Schema cannot be both ReadOnly and WriteOnly"), value); } } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityParameterValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityParameterValidator.java new file mode 100644 index 00000000..47048238 --- /dev/null +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityParameterValidator.java @@ -0,0 +1,14 @@ +package com.reprezen.kaizen.oasparser.val3; + +import static com.reprezen.kaizen.oasparser.ovl3.SecurityParameterImpl.F_parameters; + +import com.reprezen.kaizen.oasparser.model3.SecurityParameter; +import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; + +public class SecurityParameterValidator extends ObjectValidatorBase { + + @Override + public void runObjectValidations() { + validateListField(F_parameters, false, false, String.class, null); + } +} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityRequirementValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityRequirementValidator.java index ba3bdd7d..2e81444a 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityRequirementValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecurityRequirementValidator.java @@ -10,44 +10,38 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; +import static com.reprezen.kaizen.oasparser.ovl3.SecurityRequirementImpl.F_requirements; import static com.reprezen.kaizen.oasparser.val.Messages.m; -import java.util.Map.Entry; +import java.util.Map; import java.util.Set; +import com.reprezen.jsonoverlay.MapOverlay; import com.reprezen.jsonoverlay.Overlay; import com.reprezen.kaizen.oasparser.model3.OpenApi3; import com.reprezen.kaizen.oasparser.model3.SecurityParameter; import com.reprezen.kaizen.oasparser.model3.SecurityRequirement; -import com.reprezen.kaizen.oasparser.val.Messages; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class SecurityRequirementValidator extends ObjectValidatorBase { @Override - public void validateObject(SecurityRequirement securityRequirement, ValidationResults results) { - OpenApi3 model = Overlay.of(securityRequirement).getModel(); + public void runObjectValidations() { + Overlay> requirements = validateMapField(F_requirements, false, false, + SecurityParameter.class, new SecurityParameterValidator()); + checkAllSchemesDefined(requirements); + } + + public void checkAllSchemesDefined(Overlay> requirements) { + OpenApi3 model = value.getModel(); Set definedSchemes = model.getSecuritySchemes().keySet(); - for (Entry entry : securityRequirement.getRequirements().entrySet()) { - if (!definedSchemes.contains(entry.getKey())) { - results.addError( - m.msg("UnkSecScheme|Security scheme not defined in components object", entry.getKey())); - } else { - String type = model.getSecurityScheme(entry.getKey()).getType(); - switch (type) { - case "oauth2": - case "openIdConnect": - // TODO Q: anything to test here? do we know what the allowed scope names are? - break; - default: - if (!entry.getValue().getParameters().isEmpty()) { - results.addError(Messages.m.msg( - "NonEmptySecReqParms|Security requirement parameters must be empty unless scheme type is oauth2 or openIdConnect", - entry.getKey(), type)); - } - } + MapOverlay mapOverlay = Overlay.getMapOverlay(requirements); + for (String name : mapOverlay.keySet()) { + if (!definedSchemes.contains(name)) { + results.addError(m.msg("UnkSecScheme|Security scheme not defined in model", name), + Overlay.of(mapOverlay, name)); } } + } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecuritySchemeValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecuritySchemeValidator.java index e12878f5..fb14807d 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecuritySchemeValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/SecuritySchemeValidator.java @@ -10,47 +10,53 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_authorizationCodeOAuthFlow; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_bearerFormat; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_clientCredentialsOAuthFlow; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_implicitOAuthFlow; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_in; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_name; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_openIdConnectUrl; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_passwordOAuthFlow; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_scheme; +import static com.reprezen.kaizen.oasparser.ovl3.SecuritySchemeImpl.F_type; + import com.reprezen.kaizen.oasparser.model3.OAuthFlow; import com.reprezen.kaizen.oasparser.model3.SecurityScheme; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class SecuritySchemeValidator extends ObjectValidatorBase { - @Inject - private Validator oauthFlowValidator; - @Override - public void validateObject(SecurityScheme securityScheme, ValidationResults results) { - // no validation for: description, bearerFormat - validateString(securityScheme.getType(), results, true, "apiKey|http|oauth2|openIdConnect", "type"); - switch (securityScheme.getType()) { - case "http": - validateString(securityScheme.getScheme(), results, true, "scheme"); - // If bearer validate bearerFormat - break; - case "apiKey": - validateString(securityScheme.getName(), results, true, "name"); - validateString(securityScheme.getIn(), results, true, "query|header|cookie", "in"); - break; - case "oauth2": - validateField(securityScheme.getImplicitOAuthFlow(false), results, false, "flow.implicit", - oauthFlowValidator); - validateField(securityScheme.getImplicitOAuthFlow(false), results, false, "flow.password", - oauthFlowValidator); - validateField(securityScheme.getImplicitOAuthFlow(false), results, false, "flow.clientCredentials", - oauthFlowValidator); - validateField(securityScheme.getImplicitOAuthFlow(false), results, false, "authorizationCode", - oauthFlowValidator); - validateExtensions(securityScheme.getOAuthFlowsExtensions(), results, "flow"); - break; - case "openIdConnect": - validateUrl(securityScheme.getOpenIdConnectUrl(), results, true, "openIdConnectUrl"); - break; + public void runObjectValidations() { + SecurityScheme securityScheme = (SecurityScheme) value.getOverlay(); + validateStringField(F_description, false); + validateStringField(F_type, true, "apiKey|http|oauth2|openIdConnect"); + String type = securityScheme.getType(); + if (type != null) { + switch (type) { + case "http": + validateStringField(F_scheme, true); + validateStringField(F_bearerFormat, false); + break; + case "apiKey": + validateStringField(F_name, true); + validateStringField(F_in, true, "query|header|cookie"); + break; + case "oauth2": { + OAuthFlowValidator oauthFlowValidator = new OAuthFlowValidator(); + validateField(F_implicitOAuthFlow, false, OAuthFlow.class, oauthFlowValidator); + validateField(F_passwordOAuthFlow, false, OAuthFlow.class, oauthFlowValidator); + validateField(F_clientCredentialsOAuthFlow, false, OAuthFlow.class, oauthFlowValidator); + validateField(F_authorizationCodeOAuthFlow, false, OAuthFlow.class, oauthFlowValidator); + break; + } + case "openIdConnect": + validateUrlField(F_openIdConnectUrl, true, false); + break; + } } - validateExtensions(securityScheme.getExtensions(), results); + validateExtensions(securityScheme.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerValidator.java index 6f4ad44c..621efa18 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerValidator.java @@ -10,25 +10,22 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import static com.reprezen.kaizen.oasparser.val3.Regexes.NAME_REGEX; +import static com.reprezen.kaizen.oasparser.ovl3.ServerImpl.F_description; +import static com.reprezen.kaizen.oasparser.ovl3.ServerImpl.F_serverVariables; +import static com.reprezen.kaizen.oasparser.ovl3.ServerImpl.F_url; -import com.google.inject.Inject; import com.reprezen.kaizen.oasparser.model3.Server; import com.reprezen.kaizen.oasparser.model3.ServerVariable; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class ServerValidator extends ObjectValidatorBase { - @Inject - private Validator serverVariableValidator; - @Override - public void validateObject(Server server, ValidationResults results) { - // no validation for: description - validateUrl(server.getUrl(), results, false, "url", true); - validateMap(server.getServerVariables(), results, false, "variables", NAME_REGEX, serverVariableValidator); - validateExtensions(server.getExtensions(), results); + public void runObjectValidations() { + Server server = (Server) value.getOverlay(); + validateStringField(F_description, false); + validateUrlField(F_url, false, true); + validateMapField(F_serverVariables, false, false, ServerVariable.class, new ServerVariableValidator()); + validateExtensions(server.getExtensions()); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerVariableValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerVariableValidator.java index eec428f7..26377eef 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerVariableValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ServerVariableValidator.java @@ -10,48 +10,18 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import javax.lang.model.type.NullType; +import static com.reprezen.kaizen.oasparser.ovl3.ServerVariableImpl.F_defaultValue; +import static com.reprezen.kaizen.oasparser.ovl3.ServerVariableImpl.F_enumValues; +import com.reprezen.jsonoverlay.Primitive; import com.reprezen.kaizen.oasparser.model3.ServerVariable; -import com.reprezen.kaizen.oasparser.val.Messages; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class ServerVariableValidator extends ObjectValidatorBase { @Override - public void validateObject(final ServerVariable variable, final ValidationResults results) { - results.withCrumb("enum", new Runnable() { - @Override - public void run() { - int i = 0; - for (Object primitive : variable.getEnumValues()) { - checkPrimitive(primitive, results, i++); - } - } - }); - results.withCrumb("default", new Runnable() { - @Override - public void run() { - checkPrimitive(variable.getDefault(), results, "default"); - } - }); - validateString(variable.getDescription(), results, false, "description"); - } - - private void checkPrimitive(Object primitive, ValidationResults results, int index) { - checkPrimitive(primitive, results, "[" + index + "]"); - } - - private void checkPrimitive(final Object primitive, ValidationResults results, String crumb) { - if (!(primitive instanceof String || primitive instanceof Number || primitive instanceof Boolean)) { - results.withCrumb(crumb, new Runnable() { - @Override - public void run() { - Messages.m.msg("BadPrimitive|Invalid primitive value", String.valueOf(primitive), - (primitive != null ? primitive.getClass() : NullType.class).getName()); - } - }); - } + public void runObjectValidations() { + validateListField(F_enumValues, false, false, Primitive.class, null); + validateField(F_defaultValue, false, Primitive.class, null); } } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/TagValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/TagValidator.java index 73e99494..2583d3cf 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/TagValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/TagValidator.java @@ -10,23 +10,20 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import com.google.inject.Inject; +import static com.reprezen.kaizen.oasparser.ovl3.TagImpl.F_externalDocs; +import static com.reprezen.kaizen.oasparser.ovl3.TagImpl.F_name; + import com.reprezen.kaizen.oasparser.model3.ExternalDocs; import com.reprezen.kaizen.oasparser.model3.Tag; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; -import com.reprezen.kaizen.oasparser.val.Validator; public class TagValidator extends ObjectValidatorBase { - @Inject - private Validator externalDocsValidator; - @Override - public void validateObject(Tag tag, ValidationResults results) { - validateString(tag.getName(), results, true, "name"); - validateField(tag.getExternalDocs(false), results, false, "externalDocs", externalDocsValidator); - validateExtensions(tag.getExtensions(), results); + public void runObjectValidations() { + Tag tag = (Tag) value.getOverlay(); + validateStringField(F_name, true); + validateField(F_externalDocs, false, ExternalDocs.class, new ExternalDocsValidator()); + validateExtensions(tag.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ValidationConfigurator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ValidationConfigurator.java deleted file mode 100755 index f5ff137c..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ValidationConfigurator.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val3; - -import com.google.inject.AbstractModule; -import com.google.inject.TypeLiteral; -import com.reprezen.kaizen.oasparser.model3.Callback; -import com.reprezen.kaizen.oasparser.model3.Contact; -import com.reprezen.kaizen.oasparser.model3.EncodingProperty; -import com.reprezen.kaizen.oasparser.model3.Example; -import com.reprezen.kaizen.oasparser.model3.ExternalDocs; -import com.reprezen.kaizen.oasparser.model3.Header; -import com.reprezen.kaizen.oasparser.model3.Info; -import com.reprezen.kaizen.oasparser.model3.License; -import com.reprezen.kaizen.oasparser.model3.Link; -import com.reprezen.kaizen.oasparser.model3.MediaType; -import com.reprezen.kaizen.oasparser.model3.OAuthFlow; -import com.reprezen.kaizen.oasparser.model3.OpenApi3; -import com.reprezen.kaizen.oasparser.model3.Operation; -import com.reprezen.kaizen.oasparser.model3.Parameter; -import com.reprezen.kaizen.oasparser.model3.Path; -import com.reprezen.kaizen.oasparser.model3.RequestBody; -import com.reprezen.kaizen.oasparser.model3.Response; -import com.reprezen.kaizen.oasparser.model3.Schema; -import com.reprezen.kaizen.oasparser.model3.SecurityRequirement; -import com.reprezen.kaizen.oasparser.model3.SecurityScheme; -import com.reprezen.kaizen.oasparser.model3.Server; -import com.reprezen.kaizen.oasparser.model3.ServerVariable; -import com.reprezen.kaizen.oasparser.model3.Tag; -import com.reprezen.kaizen.oasparser.model3.Xml; -import com.reprezen.kaizen.oasparser.val.Validator; - -public abstract class ValidationConfigurator extends AbstractModule { - - @Override - protected void configure() { - bind(new TypeLiteral>() { - }).to(CallbackValidator.class); - bind(new TypeLiteral>() { - }).to(ContactValidator.class); - bind(new TypeLiteral>() { - }).to(EncodingPropertyValidator.class); - bind(new TypeLiteral>() { - }).to(ExampleValidator.class); - bind(new TypeLiteral>() { - }).to(ExternalDocsValidator.class); - bind(new TypeLiteral>() { - }).to(HeaderValidator.class); - bind(new TypeLiteral>() { - }).to(InfoValidator.class); - bind(new TypeLiteral>() { - }).to(LicenseValidator.class); - bind(new TypeLiteral>() { - }).to(LinkValidator.class); - bind(new TypeLiteral>() { - }).to(MediaTypeValidator.class); - bind(new TypeLiteral>() { - }).to(OAuthFlowValidator.class); - bind(new TypeLiteral>() { - }).to(OperationValidator.class); - bind(new TypeLiteral>() { - }).to(ParameterValidator.class); - bind(new TypeLiteral>() { - }).to(PathValidator.class); - bind(new TypeLiteral>() { - }).to(RequestBodyValidator.class); - bind(new TypeLiteral>() { - }).to(ResponseValidator.class); - bind(new TypeLiteral>() { - }).to(SchemaValidator.class); - bind(new TypeLiteral>() { - }).to(SecurityRequirementValidator.class); - bind(new TypeLiteral>() { - }).to(SecuritySchemeValidator.class); - bind(new TypeLiteral>() { - }).to(ServerValidator.class); - bind(new TypeLiteral>() { - }).to(ServerVariableValidator.class); - bind(new TypeLiteral>() { - }).to(OpenApi3Validator.class); - bind(new TypeLiteral>() { - }).to(TagValidator.class); - bind(new TypeLiteral>() { - }).to(XmlValidator.class); - - configureImplValidators(); - } - - protected abstract void configureImplValidators(); -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/XmlValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/XmlValidator.java index f2f65776..990762b5 100755 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/XmlValidator.java +++ b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/XmlValidator.java @@ -10,19 +10,23 @@ *******************************************************************************/ package com.reprezen.kaizen.oasparser.val3; -import javax.print.attribute.standard.Severity; +import static com.reprezen.kaizen.oasparser.ovl3.XmlImpl.F_attribute; +import static com.reprezen.kaizen.oasparser.ovl3.XmlImpl.F_name; +import static com.reprezen.kaizen.oasparser.ovl3.XmlImpl.F_namespace; +import static com.reprezen.kaizen.oasparser.ovl3.XmlImpl.F_prefix; import com.reprezen.kaizen.oasparser.model3.Xml; import com.reprezen.kaizen.oasparser.val.ObjectValidatorBase; -import com.reprezen.kaizen.oasparser.val.ValidationResults; public class XmlValidator extends ObjectValidatorBase { @Override - public void validateObject(Xml xml, ValidationResults results) { - // no validation for: name, prefix, attribute, wrapped - validateUrl(xml.getNamespace(), results, false, "namespace", false, Severity.WARNING); - validateExtensions(xml.getExtensions(), results); + public void runObjectValidations() { + Xml xml = (Xml) value.getOverlay(); + validateStringField(F_name, false); + validateStringField(F_prefix, false); + validateBooleanField(F_attribute, false); + validateUrlField(F_namespace, false, false); + validateExtensions(xml.getExtensions()); } - } diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/ContactOverlayValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/ContactOverlayValidator.java deleted file mode 100755 index f0506d1b..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/ContactOverlayValidator.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val3.ovl; - -import com.reprezen.kaizen.oasparser.model3.Contact; -import com.reprezen.kaizen.oasparser.ovl3.ContactImpl; -import com.reprezen.kaizen.oasparser.val.ImplValidator; -import com.reprezen.kaizen.oasparser.val.ObjectValidator; -import com.reprezen.kaizen.oasparser.val.ValidationResults; - -public class ContactOverlayValidator extends ObjectValidator implements ImplValidator { - - @Override - public void validateImpl(Contact contact, ValidationResults results) { - super.validate((ContactImpl) contact, results); - } - -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/InfoOverlayValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/InfoOverlayValidator.java deleted file mode 100755 index a0bc87c3..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/InfoOverlayValidator.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val3.ovl; - -import com.reprezen.kaizen.oasparser.model3.Info; -import com.reprezen.kaizen.oasparser.ovl3.InfoImpl; -import com.reprezen.kaizen.oasparser.val.ImplValidator; -import com.reprezen.kaizen.oasparser.val.ObjectValidator; -import com.reprezen.kaizen.oasparser.val.ValidationResults; - -public class InfoOverlayValidator extends ObjectValidator implements ImplValidator { - - @Override - public void validateImpl(Info info, ValidationResults results) { - super.validate((InfoImpl) info, results); - } - -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/OverlayValidationConfigurator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/OverlayValidationConfigurator.java deleted file mode 100755 index b89bf379..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/OverlayValidationConfigurator.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val3.ovl; - -import com.google.inject.TypeLiteral; -import com.reprezen.kaizen.oasparser.model3.Contact; -import com.reprezen.kaizen.oasparser.model3.Info; -import com.reprezen.kaizen.oasparser.model3.OpenApi3; -import com.reprezen.kaizen.oasparser.val.ImplValidator; -import com.reprezen.kaizen.oasparser.val3.ValidationConfigurator; - -public class OverlayValidationConfigurator extends ValidationConfigurator { - - @Override - protected void configureImplValidators() { - bind(new TypeLiteral>() { - }).to(Swagger3OverlayValidator.class); - bind(new TypeLiteral>() { - }).to(InfoOverlayValidator.class); - bind(new TypeLiteral>() { - }).to(ContactOverlayValidator.class); - } -} diff --git a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/Swagger3OverlayValidator.java b/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/Swagger3OverlayValidator.java deleted file mode 100755 index 42a8bf87..00000000 --- a/kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/ovl/Swagger3OverlayValidator.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 ModelSolv, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * ModelSolv, Inc. - initial API and implementation and/or initial documentation - *******************************************************************************/ -package com.reprezen.kaizen.oasparser.val3.ovl; - -import com.reprezen.kaizen.oasparser.model3.OpenApi3; -import com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl; -import com.reprezen.kaizen.oasparser.val.ImplValidator; -import com.reprezen.kaizen.oasparser.val.ObjectValidator; -import com.reprezen.kaizen.oasparser.val.ValidationResults; - -public class Swagger3OverlayValidator extends ObjectValidator implements ImplValidator { - - @Override - public void validate(OpenApi3Impl overlay, ValidationResults results) { - super.validate(overlay, results); - } - - @Override - public void validateImpl(OpenApi3 swagger3, ValidationResults results) { - validate((OpenApi3Impl) swagger3, results); - } - -} diff --git a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/BigParseTest.java b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/BigParseTest.java index 6b0fc5d5..69940f62 100755 --- a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/BigParseTest.java +++ b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/BigParseTest.java @@ -65,6 +65,7 @@ public boolean apply(JsonNode node) { WalkMethod valueChecker = new WalkMethod() { @Override public void run(JsonNode node, JsonPointer path) { + @SuppressWarnings("unchecked") JsonOverlay overlay = Overlay.find((JsonOverlay) model, path); Object value = overlay != null ? Overlay.get(overlay) : null; assertNotNull("No overlay object found for path: " + path, overlay); diff --git a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/OverlayAdapterTests.java b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/OverlayAdapterTests.java index 46f9bb74..8882f73c 100644 --- a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/OverlayAdapterTests.java +++ b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/OverlayAdapterTests.java @@ -1,7 +1,6 @@ package com.reprezen.swaggerparser.test; import java.net.URL; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -47,10 +46,11 @@ public void testFieldAdapter() { @Test public void testMapAdapter() { - Overlay mapOverlay = Overlay.of(model, "paths", Map.class); - assertTrue(mapOverlay.getMapOverlay() instanceof MapOverlay); @SuppressWarnings("unchecked") - MapOverlay castMapOverlay = (MapOverlay) mapOverlay.getMapOverlay(); + Overlay> mapOverlay = (Overlay>) (Object) Overlay.of(model, "paths", + Map.class); + MapOverlay castMapOverlay = Overlay.getMapOverlay(mapOverlay); + assertTrue(castMapOverlay instanceof MapOverlay); Path path = Overlay.of(castMapOverlay, "/2.0/users/{username}").get(); assertTrue(model.getPath("/2.0/users/{username}") == path); } @@ -58,10 +58,11 @@ public void testMapAdapter() { @Test public void testListAdapter() { Operation method = model.getPath("/2.0/repositories/{username}/{slug}").getGet(); - Overlay listOverlay = Overlay.of(method, "parameters", Collection.class); - assertTrue(listOverlay.getListOverlay() instanceof ListOverlay); @SuppressWarnings("unchecked") - ListOverlay castListOverlay = (ListOverlay) listOverlay.getListOverlay(); + Overlay> listOverlay = (Overlay>) (Object) Overlay.of(method, "parameters", + List.class); + ListOverlay castListOverlay = Overlay.getListOverlay(listOverlay); + assertTrue(castListOverlay instanceof ListOverlay); Parameter param = Overlay.of(castListOverlay, 1).get(); assertTrue(method.getParameter(1) == param); } diff --git a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/SimpleSerializationTest.java b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/SimpleSerializationTest.java index 03b49016..6f56a5d1 100644 --- a/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/SimpleSerializationTest.java +++ b/kaizen-openapi-parser/src/test/java/com/reprezen/swaggerparser/test/SimpleSerializationTest.java @@ -102,7 +102,8 @@ public void toJsonNoticesChanges() throws Exception { OpenApi3 model = parseLocalModel("simpleTest"); assertEquals("simple model", model.getInfo().getTitle()); assertEquals("simple model", Overlay.of(model).toJson().at("/info/title").asText()); - // this changes the overlay value but does not refresh cached JSON - just marks + // this changes the overlay value but does not refresh cached JSON - + // just marks // it as out-of-date model.getInfo().setTitle("changed title"); assertEquals("changed title", model.getInfo().getTitle()); diff --git a/kaizen-openapi-parser/src/test/resources/models/examplesTest.yaml b/kaizen-openapi-parser/src/test/resources/models/examplesTest.yaml index af7fb0c8..a1195929 100644 --- a/kaizen-openapi-parser/src/test/resources/models/examplesTest.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/examplesTest.yaml @@ -1,36 +1,36 @@ -openapi: "3.0.0" -info: - title: Simple API overview - version: v2 -paths: - /v2: - get: - operationId: getVersionDetailsv2 - summary: Show API version details - responses: - 200: - description: |- - 200 response - content: - application/json: - examples: - foo: - summary: First Example - description: An Example - value: { - "foo": "bar", - "person": { - "name": "Paul" - } - } - 203: - description: |- - 203 response - content: - application/json: - example: { - "foo": "bar", - "person": { - "name": "Paul" - } - } +openapi: "3.0.0" +info: + title: Simple API overview + version: v2 +paths: + /v2: + get: + operationId: getVersionDetailsv2 + summary: Show API version details + responses: + 200: + description: |- + 200 response + content: + application/json: + examples: + foo: + summary: First Example + description: An Example + value: { + "foo": "bar", + "person": { + "name": "Paul" + } + } + 203: + description: |- + 203 response + content: + application/json: + example: { + "foo": "bar", + "person": { + "name": "Paul" + } + } diff --git a/kaizen-openapi-parser/src/test/resources/models/issue131.yaml b/kaizen-openapi-parser/src/test/resources/models/issue131.yaml index 89cc00f1..674dfe56 100644 --- a/kaizen-openapi-parser/src/test/resources/models/issue131.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/issue131.yaml @@ -1,41 +1,41 @@ -openapi: 3.0.0 -servers: - - url: 'https://localhost:8081/devonfw-server/services/rest' -info: - title: Devon Example - description: Example of a API definition - version: 1.0.0 -paths: - /sampledatamanagement/v1/sampledata/custom/{id}: - get: - operationId: customMethod - parameters: - - name: id - in: path - required: true - schema: - type: integer - format: int64 - minimum: 0 - maximum: 100 - responses: - '200': - description: Custom Method - content: - application/json: - schema: - $ref: '#/components/schemas/SampleData' -components: - schemas: - SampleData: - x-component: sampledatamanagement - type: object - properties: - mainData: - $ref: '#/components/schemas/MoreData' - MoreData: - x-component: moredatamanagement - type: object - properties: - master: +openapi: 3.0.0 +servers: + - url: 'https://localhost:8081/devonfw-server/services/rest' +info: + title: Devon Example + description: Example of a API definition + version: 1.0.0 +paths: + /sampledatamanagement/v1/sampledata/custom/{id}: + get: + operationId: customMethod + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: int64 + minimum: 0 + maximum: 100 + responses: + '200': + description: Custom Method + content: + application/json: + schema: + $ref: '#/components/schemas/SampleData' +components: + schemas: + SampleData: + x-component: sampledatamanagement + type: object + properties: + mainData: + $ref: '#/components/schemas/MoreData' + MoreData: + x-component: moredatamanagement + type: object + properties: + master: $ref: '#/components/schemas/SampleData' \ No newline at end of file diff --git a/kaizen-openapi-parser/src/test/resources/models/linksTest.yaml b/kaizen-openapi-parser/src/test/resources/models/linksTest.yaml index b4a1cf9e..d8916c08 100644 --- a/kaizen-openapi-parser/src/test/resources/models/linksTest.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/linksTest.yaml @@ -1,191 +1,191 @@ -openapi: 3.0.0 -info: - title: Link Example - version: 1.0.0 -paths: - /2.0/users/{username}: - get: - operationId: getUserByName - parameters: - - $ref: "#/components/parameters/username" - responses: - '200': - description: The User - content: - application/json: - schema: - $ref: '#/components/schemas/user' - links: - userRepositories: - $ref: '#/components/links/UserRepositories' - /2.0/repositories/{username}: - get: - operationId: getRepositoriesByOwner - parameters: - - $ref: "#/components/parameters/username" - responses: - '200': - description: repositories owned by the supplied user - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/repository' - links: - userRepository: - $ref: '#/components/links/UserRepository' - /2.0/repositories/{username}/{slug}: - get: - operationId: getRepository - parameters: - - $ref: "#/components/parameters/username" - - name: slug - in: path - required: true - schema: - type: string - responses: - '200': - description: The repository - content: - application/json: - schema: - $ref: '#/components/schemas/repository' - links: - repositoryPullRequests: - $ref: '#/components/links/RepositoryPullRequests' - /2.0/repositories/{username}/{slug}/pullrequests: - get: - operationId: getPullRequestsByRepository - parameters: - - $ref: "#/components/parameters/username" - - name: slug - in: path - required: true - schema: - type: string - - name: state - in: query - schema: - type: string - enum: - - open - - merged - - declined - responses: - '200': - description: an array of pull request objects - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/pullrequest' - /2.0/repositories/{username}/{slug}/pullrequests/{pid}: - get: - operationId: getPullRequestsById - parameters: - - $ref: "#/components/parameters/username" - - name: slug - in: path - required: true - schema: - type: string - - name: pid - in: path - required: true - schema: - type: string - responses: - '200': - description: a pull request object - content: - application/json: - schema: - $ref: '#/components/schemas/pullrequest' - links: - pullRequestMerge: - $ref: '#/components/links/PullRequestMerge' - /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge: - post: - operationId: mergePullRequest - parameters: - - $ref: "#/components/parameters/username" - - name: slug - in: path - required: true - schema: - type: string - - name: pid - in: path - required: true - schema: - type: string - responses: - '204': - description: the PR was successfully merged -components: - parameters: - username: - name: username - in: path - required: true - schema: - type: string - - links: - UserRepositories: - # returns array of '#/components/schemas/repository' - operationId: getRepositoriesByOwner - parameters: - username: $response.body#/username - UserRepository: - # returns '#/components/schemas/repository' - operationId: getRepository - parameters: - username: $response.body#/owner/username - slug: $response.body#/slug - RepositoryPullRequests: - # returns '#/components/schemas/pullrequest' - operationId: getPullRequestsByRepository - parameters: - username: $response.body#/owner/username - slug: $response.body#/slug - PullRequestMerge: - # executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge - operationId: mergePullRequest - operationRef: "#/paths/~12.0~1repositories~1%7Busername%7D~1%7Bslug%7D~1pullrequests~1%7Bpid%7D~1merge" - server: - url: http://localhost - description: server - parameters: - username: $response.body#/author/username - slug: $response.body#/repository/slug - pid: $response.body#/id - schemas: - user: - type: object - properties: - username: - type: string - uuid: - type: string - repository: - type: object - properties: - slug: - type: string - owner: - $ref: '#/components/schemas/user' - pullrequest: - type: object - properties: - id: - type: integer - title: - type: string - repository: - $ref: '#/components/schemas/repository' - author: +openapi: 3.0.0 +info: + title: Link Example + version: 1.0.0 +paths: + /2.0/users/{username}: + get: + operationId: getUserByName + parameters: + - $ref: "#/components/parameters/username" + responses: + '200': + description: The User + content: + application/json: + schema: + $ref: '#/components/schemas/user' + links: + userRepositories: + $ref: '#/components/links/UserRepositories' + /2.0/repositories/{username}: + get: + operationId: getRepositoriesByOwner + parameters: + - $ref: "#/components/parameters/username" + responses: + '200': + description: repositories owned by the supplied user + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/repository' + links: + userRepository: + $ref: '#/components/links/UserRepository' + /2.0/repositories/{username}/{slug}: + get: + operationId: getRepository + parameters: + - $ref: "#/components/parameters/username" + - name: slug + in: path + required: true + schema: + type: string + responses: + '200': + description: The repository + content: + application/json: + schema: + $ref: '#/components/schemas/repository' + links: + repositoryPullRequests: + $ref: '#/components/links/RepositoryPullRequests' + /2.0/repositories/{username}/{slug}/pullrequests: + get: + operationId: getPullRequestsByRepository + parameters: + - $ref: "#/components/parameters/username" + - name: slug + in: path + required: true + schema: + type: string + - name: state + in: query + schema: + type: string + enum: + - open + - merged + - declined + responses: + '200': + description: an array of pull request objects + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/pullrequest' + /2.0/repositories/{username}/{slug}/pullrequests/{pid}: + get: + operationId: getPullRequestsById + parameters: + - $ref: "#/components/parameters/username" + - name: slug + in: path + required: true + schema: + type: string + - name: pid + in: path + required: true + schema: + type: string + responses: + '200': + description: a pull request object + content: + application/json: + schema: + $ref: '#/components/schemas/pullrequest' + links: + pullRequestMerge: + $ref: '#/components/links/PullRequestMerge' + /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge: + post: + operationId: mergePullRequest + parameters: + - $ref: "#/components/parameters/username" + - name: slug + in: path + required: true + schema: + type: string + - name: pid + in: path + required: true + schema: + type: string + responses: + '204': + description: the PR was successfully merged +components: + parameters: + username: + name: username + in: path + required: true + schema: + type: string + + links: + UserRepositories: + # returns array of '#/components/schemas/repository' + operationId: getRepositoriesByOwner + parameters: + username: $response.body#/username + UserRepository: + # returns '#/components/schemas/repository' + operationId: getRepository + parameters: + username: $response.body#/owner/username + slug: $response.body#/slug + RepositoryPullRequests: + # returns '#/components/schemas/pullrequest' + operationId: getPullRequestsByRepository + parameters: + username: $response.body#/owner/username + slug: $response.body#/slug + PullRequestMerge: + # executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge + operationId: mergePullRequest + operationRef: "#/paths/~12.0~1repositories~1%7Busername%7D~1%7Bslug%7D~1pullrequests~1%7Bpid%7D~1merge" + server: + url: http://localhost + description: server + parameters: + username: $response.body#/author/username + slug: $response.body#/repository/slug + pid: $response.body#/id + schemas: + user: + type: object + properties: + username: + type: string + uuid: + type: string + repository: + type: object + properties: + slug: + type: string + owner: + $ref: '#/components/schemas/user' + pullrequest: + type: object + properties: + id: + type: integer + title: + type: string + repository: + $ref: '#/components/schemas/repository' + author: $ref: '#/components/schemas/user' \ No newline at end of file diff --git a/kaizen-openapi-parser/src/test/resources/models/parseTest.yaml b/kaizen-openapi-parser/src/test/resources/models/parseTest.yaml index f96f9268..df854ce3 100755 --- a/kaizen-openapi-parser/src/test/resources/models/parseTest.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/parseTest.yaml @@ -1,348 +1,346 @@ -openapi: 3.0.0 -info: - title: Ha ha! - description: description - termsOfService: termsOfService - contact: - name: name - url: url - email: email - x-foo: foo - license: - name: name - url: url - x-foo: foo - version: version - x-foo: foo -servers: &id001 -- url: url - description: description - variables: - var1: - enum: - - string - - number - default: string - description: description - x-foo: foo - var2: - enum: - - string - - number - default: string - description: description - x-foo: foo - x-foo: foo - x-foo: foo -- url: url2 - description: description2 - x-foo: foo -paths: - /foo: - summary: summary - description: description - get: - tags: - - foo - - bar - summary: summary - description: description - externalDocs: - description: description - url: url - x-foo: foo - operationId: operationId - parameters: &id002 - - name: name - in: in - description: description - required: true - deprecated: false - allowEmptyValue: true - style: style - explode: true - allowReserved: true - examples: - first: - value: example - second: - value: 10 - third: - value: 5.5 - example: example - content: - application/json: - schema: - title: title - examples: - x: - value: x - y: - value: y - z: - value: z - example: 10 - encoding: - fooEncoding: - contentType: contentType - headers: - foo: foo - bar: bar - style: style - explode: true - x-foo: foo - x-foo: foo - x-foo: foo - requestBody: - description: description - required: ture - content: - application/json: - schema: - title: title - text/plain: - schema: - title: title - required: true - responses: - default: - description: description - headers: - xxx: - description: description - yyy: - description: description - content: - application/json: - schema: - title: title - links: - name: - operationRef: operationRef - operationId: operationId - parameters: - param1: xxxx - param2: yyyy - headers: - foo: - description: description - bar: - description: description - description: description - x-foo: foo - 200: - description: description - callbacks: - xxx: - expr1: - summary: summary - description: description - get: - summary: summary - operationId: operationId - expr2: - summary: summary - description: description - get: - operationId: operationid - yyy: - expr1: - summary: summary - description: description - get: - summary: summary - operationId: operationId - expr2: - summary: summary - description: description - get: - operationId: operationid - deprecated: false - security: - - sec1: [a, b, c] - sec2: [] - - sec3: [] - servers: *id001 - x-foo: foo - x-foo: foo - parameters: *id002 - x-foo: foo -components: - schemas: - schema1: - title: title - multipleOf: 3.5 - maximum: 15000000000000000000000000000000000000.0 - exclusiveMaximum: true - minimum: -3333333333333333333333333333333333333333333333333333 - exclusiveMinimum: false - maxLength: 100 - minLength: 20 - pattern: "\\d\\d\\d-xyzzy" - maxItems: 30 - minItems: 43 - uniqueItems: true - maxProperties: 30 - minProperties: 15 - required: - - x - - "y" - - z - enum: [ a, b, c] - type: object - allOf: - - type: object - - type: object - oneOf: - - type: object - - type: object - anyOf: - - type: object - - type: object - not: - type: object - items: - type: object - properties: - a: - type: string - b: - type: string - c: - type: string - additionalProperties: true - description: description - format: format - default: xyzzy - nullable: true - discriminator: foo - readOnly: true - writeOnly: false - xml: - name: name - namespace: namespace - prefix: prefix - attribute: true - wrapped: false - externalDocs: - description: description - url: url - example: xxx - examples: - first: - value: 1.0 - second: - value: true - third: - value: null - fourth: - value: xyzzy - deprecated: true - x-foo: foo - schema2: - title: title - additionalProperties: - type: integer - responses: - resp1: - description: description - resp2: - description: description - parameters: - param1: - name: name - in: in - param2: - name: name - in: in - examples: - example1: - value: null - example2: - value: xyzzy - requestBodies: - reqBody1: - description: description - reqBody2: - description: description - headers: - header1: - description: description - header2: - description: description - securitySchemes: - scheme1: - type: apiKey - description: description - name: name - in: query - scheme: http - bearerFormat: bearerFormat - openIdConnectUrl: openIdConnect - x-foo: foo - scheme2: - type: oauth2 - description: description - name: name - in: query - scheme: http - bearerFormat: bearerFormat - flow: - implicit: - authorizationUrl: authorizationUrl - tokenUrl: tokenUrl - refreshUrl: refreshUrl - scopes: - xxx: xxx - yyy: yyy - x-foo: [] - x-foo: foo - password: - authorizationUrl: authorizationUrl - tokenUrl: tokenUrl - refreshUrl: refreshUrl - scopes: - xxx: xxx - yyy: yyy - x-foo: [] - x-foo: foo - clientCredentials: - authorizationUrl: authorizationUrl - tokenUrl: tokenUrl - refreshUrl: refreshUrl - scopes: - xxx: xxx - yyy: yyy - x-foo: [] - x-foo: foo - authorizationCode: - authorizationUrl: authorizationUrl - tokenUrl: tokenUrl - refreshUrl: refreshUrl - scopes: - xxx: xxx - yyy: yyy - x-foo: [] - x-foo: foo - x-foo: foo - openIdConnectUrl: openIdConnect - x-foo: foo - links: - link1: - operationRef: operationRef - link2: - operationRef: operationRef - callbacks: - cb1: - expr1: - summary: summary - expr2: - summary: summary - x-foo: foo -security: [] -tags: [] -externalDocs: - description: description - url: url - x-foo: foo +openapi: 3.0.0 +info: + title: Ha ha! + description: description + termsOfService: termsOfService + contact: + name: name + url: url + email: email + x-foo: foo + license: + name: name + url: url + x-foo: foo + version: version + x-foo: foo +servers: +- url: url + description: description + variables: + var1: + enum: + - string + - number + default: string + description: description + x-foo: foo + var2: + enum: + - string + - number + default: string + description: description + x-foo: foo + x-foo: foo + x-foo: foo +- url: url2 + description: description2 + x-foo: foo +paths: + /foo: + summary: summary + description: description + get: + tags: + - foo + - bar + summary: summary + description: description + externalDocs: + description: description + url: url + x-foo: foo + operationId: operationId + parameters: + - name: name + in: in + description: description + required: true + deprecated: false + allowEmptyValue: true + style: style + explode: true + allowReserved: true + examples: + first: + value: example + second: + value: 10 + third: + value: 5.5 + example: example + content: + application/json: + schema: + title: title + examples: + x: + value: x + y: + value: "y" + z: + value: z + example: 10 + encoding: + fooEncoding: + contentType: contentType + headers: + foo: foo + bar: bar + style: style + explode: true + x-foo: foo + x-foo: foo + x-foo: foo + requestBody: + description: description + required: ture + content: + application/json: + schema: + title: title + text/plain: + schema: + title: title + required: true + responses: + default: + description: description + headers: + xxx: + description: description + yyy: + description: description + content: + application/json: + schema: + title: title + links: + name: + operationRef: operationRef + operationId: operationId + parameters: + param1: xxxx + param2: yyyy + headers: + foo: + description: description + bar: + description: description + description: description + x-foo: foo + 200: + description: description + callbacks: + xxx: + expr1: + summary: summary + description: description + get: + summary: summary + operationId: operationId + expr2: + summary: summary + description: description + get: + operationId: operationid + yyy: + expr1: + summary: summary + description: description + get: + summary: summary + operationId: operationId + expr2: + summary: summary + description: description + get: + operationId: operationid + deprecated: false + security: + - sec1: [a, b, c] + sec2: [] + - sec3: [] + x-foo: foo + x-foo: foo + x-foo: foo +components: + schemas: + schema1: + title: title + multipleOf: 3.5 + maximum: 15000000000000000000000000000000000000.0 + exclusiveMaximum: true + minimum: -3333333333333333333333333333333333333333333333333333 + exclusiveMinimum: false + maxLength: 100 + minLength: 20 + pattern: "\\d\\d\\d-xyzzy" + maxItems: 30 + minItems: 43 + uniqueItems: true + maxProperties: 30 + minProperties: 15 + required: + - x + - "y" + - z + enum: [ a, b, c] + type: object + allOf: + - type: object + - type: object + oneOf: + - type: object + - type: object + anyOf: + - type: object + - type: object + not: + type: object + items: + type: object + properties: + a: + type: string + b: + type: string + c: + type: string + additionalProperties: true + description: description + format: format + default: xyzzy + nullable: true + discriminator: foo + readOnly: true + writeOnly: false + xml: + name: name + namespace: namespace + prefix: prefix + attribute: true + wrapped: false + externalDocs: + description: description + url: url + example: xxx + examples: + first: + value: 1.0 + second: + value: true + third: + value: null + fourth: + value: xyzzy + deprecated: true + x-foo: foo + schema2: + title: title + additionalProperties: + type: integer + responses: + resp1: + description: description + resp2: + description: description + parameters: + param1: + name: name + in: in + param2: + name: name + in: in + examples: + example1: + value: null + example2: + value: xyzzy + requestBodies: + reqBody1: + description: description + reqBody2: + description: description + headers: + header1: + description: description + header2: + description: description + securitySchemes: + scheme1: + type: apiKey + description: description + name: name + in: query + scheme: http + bearerFormat: bearerFormat + openIdConnectUrl: openIdConnect + x-foo: foo + scheme2: + type: oauth2 + description: description + name: name + in: query + scheme: http + bearerFormat: bearerFormat + flow: + implicit: + authorizationUrl: authorizationUrl + tokenUrl: tokenUrl + refreshUrl: refreshUrl + scopes: + xxx: xxx + yyy: yyy + x-foo: [] + x-foo: foo + password: + authorizationUrl: authorizationUrl + tokenUrl: tokenUrl + refreshUrl: refreshUrl + scopes: + xxx: xxx + yyy: yyy + x-foo: [] + x-foo: foo + clientCredentials: + authorizationUrl: authorizationUrl + tokenUrl: tokenUrl + refreshUrl: refreshUrl + scopes: + xxx: xxx + yyy: yyy + x-foo: [] + x-foo: foo + authorizationCode: + authorizationUrl: authorizationUrl + tokenUrl: tokenUrl + refreshUrl: refreshUrl + scopes: + xxx: xxx + yyy: yyy + x-foo: [] + x-foo: foo + x-foo: foo + openIdConnectUrl: openIdConnect + x-foo: foo + links: + link1: + operationRef: operationRef + link2: + operationRef: operationRef + callbacks: + cb1: + expr1: + summary: summary + expr2: + summary: summary + x-foo: foo +security: [] +tags: [] +externalDocs: + description: description + url: url + x-foo: foo x-foo: foo \ No newline at end of file diff --git a/kaizen-openapi-parser/src/test/resources/models/pathsTest.yaml b/kaizen-openapi-parser/src/test/resources/models/pathsTest.yaml index 81fe2484..b4c39d0f 100644 --- a/kaizen-openapi-parser/src/test/resources/models/pathsTest.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/pathsTest.yaml @@ -1,19 +1,19 @@ -openapi: "3.0.0" -info: - title: Simple API overview - version: v2 -paths: - /: - get: - operationId: listVersionsv2 - summary: List API versions - responses: - 200: - description: Ok - /v2: - get: - operationId: getVersionDetailsv2 - summary: Show API version details - responses: - 200: +openapi: "3.0.0" +info: + title: Simple API overview + version: v2 +paths: + /: + get: + operationId: listVersionsv2 + summary: List API versions + responses: + 200: + description: Ok + /v2: + get: + operationId: getVersionDetailsv2 + summary: Show API version details + responses: + 200: description: Ok \ No newline at end of file diff --git a/kaizen-openapi-parser/src/test/resources/models/simpleTest.yaml b/kaizen-openapi-parser/src/test/resources/models/simpleTest.yaml index e1671e02..e7315918 100644 --- a/kaizen-openapi-parser/src/test/resources/models/simpleTest.yaml +++ b/kaizen-openapi-parser/src/test/resources/models/simpleTest.yaml @@ -1,16 +1,16 @@ -openapi: "3.0.0" -info: - version: 1.0.0 - title: simple model -paths: {} -components: - schemas: - X: - type: object - properties: - x: - type: string - y: - $ref: "#/components/schemas/Y" - Y: - type: integer +openapi: "3.0.0" +info: + version: 1.0.0 + title: simple model +paths: {} +components: + schemas: + X: + type: object + properties: + x: + type: string + y: + $ref: "#/components/schemas/Y" + Y: + type: integer