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

Closes #113 #115

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import org.opengis.cite.ogcapiedr10.CommonFixture;
Expand All @@ -27,6 +29,7 @@
import com.reprezen.kaizen.oasparser.OpenApi3Parser;

import com.reprezen.kaizen.oasparser.val.ValidationResults;
import com.reprezen.kaizen.oasparser.val.ValidationResults.ValidationItem;

import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
Expand Down Expand Up @@ -102,17 +105,35 @@ public void apiDefinitionValidation( ITestContext testContext )
assertTrue( false, "The API definition linked from the Landing Page resulted in "+apiUrl+" \n"+e.getMessage() );
}

if(apiModel.isValid() )
boolean apiModelValid = apiModel.isValid();

if(apiModelValid )
{
testContext.getSuite().setAttribute( API_MODEL.getName(), apiModel );
}

if(apiModel.isValid() && (!apiUrl.getType().equals(OPEN_API_MIME_TYPE)))
if(apiModelValid && (!apiUrl.getType().equals(OPEN_API_MIME_TYPE)))
{
throw new SkipException("The API Definition was found to be valid. However, the Media Type identified by the Link to the API Definition document was not "+OPEN_API_MIME_TYPE);
}

assertTrue( apiModel.isValid(), createValidationMsg( apiModel ) );

Collection<ValidationItem> validationItems = new ArrayList<ValidationResults.ValidationItem>();

// https://github.com/opengeospatial/ets-ogcapi-edr10/issues/113
// Check if validation only found errors regarding null values
// Remove them from the list of validation items
if (!apiModelValid) {
boolean onlyNullErrors = true;
for (ValidationResults.ValidationItem item : apiModel.getValidationItems()) {
if (!item.getMsg().contains("Value 'null' does not match required pattern")) {
onlyNullErrors = false;
validationItems.add(item);
}
}
apiModelValid = onlyNullErrors;
}

assertTrue(apiModelValid, createValidationMsg( validationItems ) );

}

Expand Down Expand Up @@ -144,14 +165,12 @@ else if ("service-doc".equals( rel ))
return null;
}

private String createValidationMsg( OpenApi3 model ) {
private String createValidationMsg(Collection<ValidationItem> validationItems) {
StringBuilder sb = new StringBuilder();
sb.append( "API definition is not valid. Found following validation items:" );
if ( !model.isValid() ) {
for ( ValidationResults.ValidationItem item : model.getValidationItems() ) {
sb.append( " @ " ).append( item.getPositionInfo() ).append( " - " ).append( item.getSeverity() ).append( ": " ).append( item.getMsg() );

}
sb.append("API definition is not valid. Found following validation items:");
for (ValidationResults.ValidationItem item : validationItems) {
sb.append(" @ ").append(item.getPositionInfo()).append(" - ").append(item.getSeverity()).append(": ")
.append(item.getMsg());
}
return sb.toString();
}
Expand Down