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

Fix exception in ConsoleRender when property has been removed #7

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
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 @@ -213,12 +213,19 @@ private String properties(
String propPrefix, String title, Map<String, Schema> properties, DiffContext context) {
StringBuilder sb = new StringBuilder();
if (properties != null) {
properties.forEach(
(key, value) -> sb.append(property(propPrefix + key, title, resolve(value))));
properties.forEach((key, value) -> sb.append(resolveProperty(propPrefix, value, key, title)));
}
return sb.toString();
}

private String resolveProperty(String propPrefix, Schema value, String key, String title) {
try {
return property(propPrefix + key, title, resolve(value));
} catch (Exception e) {
return property(propPrefix + key, title, type(value));
}
}

protected String property(String name, String title, Schema schema) {
return property(name, title, type(schema));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.qdesrame.openapi.test;

import static org.assertj.core.api.Assertions.assertThat;

import com.qdesrame.openapi.diff.core.OpenApiCompare;
import com.qdesrame.openapi.diff.core.model.ChangedOpenApi;
import com.qdesrame.openapi.diff.core.output.ConsoleRender;
import org.junit.jupiter.api.Test;

public class ConsoleRenderTest {
@Test
public void renderDoesNotFailWhenPropertyHasBeenRemoved() {
ConsoleRender render = new ConsoleRender();
ChangedOpenApi diff =
OpenApiCompare.fromLocations("missing_property_1.yaml", "missing_property_2.yaml");
assertThat(render.render(diff)).isNotBlank();
}
}
31 changes: 31 additions & 0 deletions core/src/test/resources/missing_property_1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.1
info:
title: Title
version: 1.0.0
description: Description
paths:
/:
get:
summary: Simple GET
operationId: simpleGet
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Wrapper'
description: Simple GET
components:
schemas:
Wrapper:
type: object
properties:
id:
type: string
childProperty:
$ref: '#/components/schemas/ChildProperty'
ChildProperty:
type: object
properties:
id:
type: string
24 changes: 24 additions & 0 deletions core/src/test/resources/missing_property_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
openapi: 3.0.1
info:
title: Title
version: 1.0.0
description: Description
paths:
/:
get:
summary: Simple GET
operationId: simpleGet
responses:
default:
content:
application/json:
schema:
$ref: '#/components/schemas/Wrapper'
description: Simple GET
components:
schemas:
Wrapper:
type: object
properties:
id:
type: string