Fixed issue with .. jsonpath operator; fixes gh-1754
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.cloud.contract.docs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -93,33 +94,35 @@ public class Main {
|
||||
mapper.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Class metadatum : metadata) {
|
||||
Constructor constructor = null;
|
||||
try {
|
||||
SpringCloudContractMetadata newInstance = (SpringCloudContractMetadata) metadatum
|
||||
.getDeclaredConstructor(null).newInstance();
|
||||
String description = newInstance.description();
|
||||
String key = newInstance.key();
|
||||
List<Class> additionalClasses = classesToLookAt(metadatum, newInstance);
|
||||
// @formatter:off
|
||||
sb
|
||||
.append("[[metadata-").append(key).append("]]\n")
|
||||
.append("##### Metadata `").append(key).append("`\n\n")
|
||||
.append("* key: `").append(key).append("`").append("\n")
|
||||
.append("* description:\n\n").append(description).append("\n\n")
|
||||
.append("Example:\n\n")
|
||||
.append("```yaml\n").append(mapper.writeValueAsString(newInstance)).append("\n```\n\n")
|
||||
// To make the schema collapsable
|
||||
.append("+++ <details><summary> +++\nClick here to expand the JSON schema:\n+++ </summary><div> +++\n")
|
||||
.append("```json\n").append(generateJsonSchemaForClass(metadatum)).append("\n```\n")
|
||||
.append("+++ </div></details> +++\n\n")
|
||||
.append("If you are interested in learning more about the types and its properties, check out the following classes:\n\n")
|
||||
.append(additionalClasses.stream().map(aClass -> "* `" + aClass.getName() + "`").collect(Collectors.joining("\n")))
|
||||
.append("\n\n");
|
||||
// @formatter:on
|
||||
constructor = metadatum.getDeclaredConstructor(null);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
log.error("Exception occurred while trying to parse [" + metadatum + "]");
|
||||
throw exception;
|
||||
catch (Exception ex) {
|
||||
log.warn("Failed to find a no-args constructor for matadatum [" + metadatum + "]", ex);
|
||||
continue;
|
||||
}
|
||||
Object instance = constructor.newInstance();
|
||||
SpringCloudContractMetadata newInstance = (SpringCloudContractMetadata) instance;
|
||||
String description = newInstance.description();
|
||||
String key = newInstance.key();
|
||||
List<Class> additionalClasses = classesToLookAt(metadatum, newInstance);
|
||||
// @formatter:off
|
||||
sb
|
||||
.append("[[metadata-").append(key).append("]]\n")
|
||||
.append("##### Metadata `").append(key).append("`\n\n")
|
||||
.append("* key: `").append(key).append("`").append("\n")
|
||||
.append("* description:\n\n").append(description).append("\n\n")
|
||||
.append("Example:\n\n")
|
||||
.append("```yaml\n").append(mapper.writeValueAsString(newInstance)).append("\n```\n\n")
|
||||
// To make the schema collapsable
|
||||
.append("+++ <details><summary> +++\nClick here to expand the JSON schema:\n+++ </summary><div> +++\n")
|
||||
.append("```json\n").append(generateJsonSchemaForClass(metadatum)).append("\n```\n")
|
||||
.append("+++ </div></details> +++\n\n")
|
||||
.append("If you are interested in learning more about the types and its properties, check out the following classes:\n\n")
|
||||
.append(additionalClasses.stream().map(aClass -> "* `" + aClass.getName() + "`").collect(Collectors.joining("\n")))
|
||||
.append("\n\n");
|
||||
// @formatter:on
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingType
|
||||
import org.springframework.cloud.contract.spec.internal.OptionalProperty
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.util.SerializationUtils
|
||||
|
||||
/**
|
||||
* I would like to apologize to anyone who is reading this class. Since JSON is a hectic structure
|
||||
* this class is also hectic. The idea is to traverse the JSON structure and build a set of
|
||||
@@ -157,7 +155,6 @@ class JsonToJsonPathsConverter {
|
||||
containsOnlyEmptyElements(object)
|
||||
&& isNotRootArray(matcherPath)) {
|
||||
String pathToDelete = pathToDelete(pathWithoutAnyArray)
|
||||
context.delete(pathToDelete)
|
||||
if (pathToDelete.contains(DESCENDANT_OPERATOR)) {
|
||||
Object root = context.read('$')
|
||||
if (rootContainsEmptyContainers(root)) {
|
||||
@@ -166,6 +163,8 @@ class JsonToJsonPathsConverter {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
} else {
|
||||
context.delete(pathToDelete)
|
||||
}
|
||||
return removeTrailingContainers(pathToDelete, context)
|
||||
}
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.junit.Rule
|
||||
import org.spockframework.runtime.extension.builtin.PreconditionContext
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.IgnoreIf
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Retry
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
@@ -1763,7 +1759,6 @@ response:
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Issue("#1414")
|
||||
def "should work with empty arrays after doing array matching [#methodBuilderName]"() {
|
||||
given:
|
||||
|
||||
Reference in New Issue
Block a user