Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZEN-4339] Implement optional 2nd phase of validation with KZOP #457

Merged
merged 12 commits into from
Aug 21, 2018

Conversation

ghillairet
Copy link
Member

This PR adds an advanced validation mode for OpenAPI 3 documents. The advanced validation is provided by KaiZen Parser (KZOP). The advanced validation is only performed when the advanced option is passed to the OpenAPi3Validator constructor (which it is now true by default).

This PR should not be merged until we update the target platform to include latest version of KZOP and JsonOverlay. Those are present in this PR but are added as jars in the openapi3 project lib folder.

Add Validation preference page for OpenAPI v3. The page contains the option to use the advanced validation from KZOP. This option is enable by default.
@ghillairet
Copy link
Member Author

I added a preference page for setting the advanced validation option for OpenAPI3.

screen shot 2018-08-16 at 10 23 40

Some examples of validation messages provided by KZOP:

screen shot 2018-08-16 at 15 35 22

Some of them are still missing position in document so they are placed on the first line:

screen shot 2018-08-16 at 15 35 17

@@ -9,7 +9,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.jface.text,
org.dadacoalition.yedit,
com.google.guava;bundle-version="15.0.0",
com.google.guava;bundle-version="21.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghillairet , we use Guava 16 in the API Studio, see https://github.com/ModelSolv/RepreZen/commit/42f0f2eb0e954dd1c0516e945050ff54c579e901#r30206252 . How was version 21 of Guava chosen?

And... Do we still need Guava, even after migration to Java 8? :)

return errors;
}

protected JsonSchema getSchema(JsonDocument doc, String type, Map<String, JsonSchema> schemas) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was extracted to JsonSchemaValidator , is that right?

try {
OpenApi3 result = new OpenApi3Parser().parse(baseURI.toURL(), true);

for (ValidationItem item : result.getValidationResults().getItems()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@tfesenko
Copy link
Member

Passed code review.
@ghillairet , I also added a new p2 update site for KZOP and JOVL to our target platform. However, with these changes:

  1. I cannot launch KZOE from Eclipse because of a problem with Jackson:
org.osgi.framework.BundleException: Could not resolve module: com.reprezen.swagedit.openapi3 [3982]
  Unresolved requirement: Require-Bundle: com.reprezen.kaizen.openapi-parser; bundle-version="3.0.1"
    -> Bundle-SymbolicName: com.reprezen.kaizen.openapi-parser; bundle-version="3.0.1.201808201424"
       com.reprezen.kaizen.openapi-parser [3979]
         Unresolved requirement: Import-Package: com.fasterxml.jackson.core; resolution="optional"
  1. We now have test failures in maven build in com.reprezen.swagedit.openapi3.tests.

Can you please have a look?

@ghillairet
Copy link
Member Author

@tfesenko @andylowry It seems that the issue is with KZOP that declares the imported packages as optional. I made a local p2 repository for KZOP that removes the optional declaration in the p2/pom.xml file and now KZOE is working.

The problem I'm facing now is during validation with KZOP, I am having the javax.mail package not being found, although it is declared in the MANIFEST.

java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
	at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.validate(OpenApi3Impl.java:58)
	at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:91)
	at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:71)
	at com.reprezen.kaizen.oasparser.OpenApi3Parser.parse(OpenApi3Parser.java:59)
	at com.reprezen.swagedit.openapi3.validation.OpenApi3Validator.validate(OpenApi3Validator.java:93)
	at com.reprezen.swagedit.core.validation.Validator.validate(Validator.java:75)
	at com.reprezen.swagedit.core.editor.ValidationOperation.validateSwagger(ValidationOperation.java:110)
	at com.reprezen.swagedit.core.editor.ValidationOperation.run(ValidationOperation.java:91)
	at com.reprezen.swagedit.core.editor.JsonEditor$6.doRunInWorkspace(JsonEditor.java:418)
	at com.reprezen.swagedit.core.editor.JsonEditor$SafeWorkspaceJob.runInWorkspace(JsonEditor.java:492)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: java.lang.ClassNotFoundException: javax.mail.internet.AddressException cannot be found by com.reprezen.kaizen.openapi-parser_2.2.0.20180821110849
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 12 more

@ghillairet
Copy link
Member Author

@tfesenko @andylowry This PR RepreZen/KaiZen-OpenApi-Parser#188 could fix the issue with import-packages not being resolved. It solves my previous issue with javax.mail package.

But I'm still having the tests to fail.

Remove propertyListener from preference store should be done before preference store is deleted.
Activate advanced validation when there are no previous errors (not warnings).
@ghillairet ghillairet changed the title [ZEN-4339] Implement optional 2nd phase of validation with KZOP (DO NOT MERGE) [ZEN-4339] Implement optional 2nd phase of validation with KZOP Aug 21, 2018
@ghillairet
Copy link
Member Author

@tfesenko Ready to review and QA.

getPreferenceStore().removePropertyChangeListener(advancedValidationListener);
super.dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tfesenko
Copy link
Member

The recent commits passed code review.
Local maven build succeeds.
I am getting this error when launching from Eclipse.

java.lang.NoSuchMethodError: com.reprezen.kaizen.oasparser.val.ValidationResults.open()Lcom/reprezen/kaizen/oasparser/val/ValidationResults$ValidationResultsInstance;
	at com.reprezen.kaizen.oasparser.ovl3.OpenApi3Impl.validate(OpenApi3Impl.java:56)
	at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:91)
	at com.reprezen.kaizen.oasparser.OpenApiParser.parse(OpenApiParser.java:71)
	at com.reprezen.kaizen.oasparser.OpenApi3Parser.parse(OpenApi3Parser.java:59)
	at com.reprezen.swagedit.openapi3.validation.OpenApi3Validator.validate(OpenApi3Validator.java:98)
	at com.reprezen.swagedit.core.validation.Validator.validate(Validator.java:75)
	at com.reprezen.swagedit.core.editor.ValidationOperation.validateSwagger(ValidationOperation.java:110)
	at com.reprezen.swagedit.core.editor.ValidationOperation.run(ValidationOperation.java:91)
	at com.reprezen.swagedit.core.editor.JsonEditor$6.doRunInWorkspace(JsonEditor.java:419)
	at com.reprezen.swagedit.core.editor.JsonEditor$SafeWorkspaceJob.runInWorkspace(JsonEditor.java:493)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)

@tfesenko
Copy link
Member

This strange exception is not present on KZOE installed from a local update site on top of a clean eclipse. Merging

@tfesenko tfesenko merged commit b452db3 into master Aug 21, 2018
@tfesenko tfesenko deleted the task/ZEN-4339 branch August 21, 2018 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants