Skip to content

Commit

Permalink
fix: Improve detection of self-refence properties and properly stop g…
Browse files Browse the repository at this point in the history
…eneration after --selfReferenceDepth
  • Loading branch information
en-milie committed Sep 17, 2024
1 parent 40568cd commit f937248
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ <T> Object formatExampleIfNeeded(Schema<T> property) {

private Object resolveProperties(Schema<?> schema) {
if (schema.getProperties() != null) {
String previousPropertyValue = currentProperty;

Map<String, Object> result = new HashMap<>();
for (Map.Entry<String, Schema> property : schema.getProperties().entrySet()) {
currentProperty = StringUtils.isBlank(previousPropertyValue) ? String.valueOf(property.getKey()) : previousPropertyValue + "#" + property.getKey();
result.put(property.getKey(), this.resolvePropertyToExample(property.getKey(), property.getValue()));
}

currentProperty = previousPropertyValue;
schema.setExample(result);
return result;
}
return schema.getExample();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void shouldFilterDeprecatedOperations() throws Exception {

@Test
void shouldAvoidCyclicDependenciesOnAdditionalProperties() throws Exception {
Mockito.when(processingArguments.getSelfReferenceDepth()).thenReturn(5);
Mockito.when(processingArguments.getSelfReferenceDepth()).thenReturn(6);
Mockito.when(processingArguments.getDefaultContentType()).thenReturn("application/json");

List<FuzzingData> dataList = setupFuzzingData("/containers", "src/test/resources/petstore.yml");
Expand All @@ -551,8 +551,8 @@ void shouldAvoidCyclicDependenciesOnAdditionalProperties() throws Exception {
Object existing = JsonUtils.getVariableFromJson(payload, "$.containers#key#containers#key#containers#key#containers#key#containers#key#containers#key");
Object nonExisting = JsonUtils.getVariableFromJson(payload, "$.containers#key#containers#key#containers#key#containers#key#containers#key#containers#key#containers");

Assertions.assertThat(existing).doesNotHaveToString("{}");
Assertions.assertThat(nonExisting).hasToString("{}");
Assertions.assertThat(existing).hasToString("{}");
Assertions.assertThat(nonExisting).hasToString("NOT_SET");
}

@Test
Expand Down

0 comments on commit f937248

Please sign in to comment.