OpenAPITools / OpenAPITools/openapi-diff
Doesn't detect/render additions to the API
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 190
- PR merge metrics
- No merged PRs in 30d
Description
Try this....
See last exploratory test I added to the existing test case.
As a user it just seems totally broken?
package org.openapitools.openapidiff.core;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.tags.Tag;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import org.junit.jupiter.api.Test;
import org.openapitools.openapidiff.core.model.Changed;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
import org.openapitools.openapidiff.core.output.ConsoleRender;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;
import static org.openapitools.openapidiff.core.model.DiffResult.COMPATIBLE;
public class PathDiffTest {
private final String OPENAPI_PATH1 = "path_1.yaml";
private final String OPENAPI_PATH2 = "path_2.yaml";
private final String OPENAPI_PATH3 = "path_3.yaml";
private final String OPENAPI_PATH4 = "path_4.yaml";
@Test
public void testEqual() {
assertOpenApiAreEquals(OPENAPI_PATH1, OPENAPI_PATH2);
}
@Test
public void testMultiplePathWithSameSignature() {
assertThrows(
IllegalArgumentException.class, () -> assertOpenApiAreEquals(OPENAPI_PATH3, OPENAPI_PATH3));
}
@Test
public void testSameTemplateDifferentMethods() {
ChangedOpenApi changedOpenApi = OpenApiCompare.fromLocations(OPENAPI_PATH1, OPENAPI_PATH4);
assertThat(changedOpenApi.getNewEndpoints())
.hasSize(1)
.satisfiesExactly(endpoint -> assertThat(endpoint.getOperation().getOperationId()).isEqualTo("deletePet"));
assertThat(changedOpenApi.isCompatible()).isTrue();
}
@Test
void exploratoryTest() {
// clean original spec
OpenAPIParser parser = new OpenAPIParser();
SwaggerParseResult origDoc = parser.readLocation(OPENAPI_PATH1, null, null);
OpenAPI origOpenAPI = origDoc.getOpenAPI();
// hacked copy of the same original
SwaggerParseResult newDoc = parser.readLocation(OPENAPI_PATH1, null, null);
OpenAPI newOpenAPI = newDoc.getOpenAPI();
Tag tag = new Tag();
tag.setDescription("ADDED TAG");
tag.setName("ADDED TAGNAME");
newOpenAPI.addTagsItem(tag);
PathItem addedPathItem = new PathItem();
addedPathItem.setDescription("ADDED PATH");
Operation op = new Operation();
op.setOperationId("ADDEDOPID");
addedPathItem.setGet(op);
newOpenAPI.getPaths().addPathItem("ADDEDPATH", addedPathItem);
// now compare them
ChangedOpenApi changedOpenApi = OpenApiCompare.fromSpecifications(origOpenAPI, newOpenAPI);
assertThat(changedOpenApi.isChanged()).isEqualTo(COMPATIBLE); // ok so it knows something has changed??
assertThat(changedOpenApi.isDifferent()).isEqualTo(true); // yep something has changed
// but the reporting doesn't tell me what
assertThat(changedOpenApi.getChangedElements()).hasSizeGreaterThan(0);
System.out.println("---");
System.out.println("CHANGES SIZE : " + changedOpenApi.getChangedElements().size());
System.out.println("---");
System.out.println("??!! THIS COMES BACK A [null] ie a null element !!: " + changedOpenApi.getChangedElements());
System.out.println("---");
System.out.println("diffs should surely render the additional elements that I added?? - but it does nothing??");
ConsoleRender cr = new ConsoleRender();
cr.render(changedOpenApi);
System.out.println("!! some diff should have been printed above ");
//assertThat(changedOpenApi.getMissingEndpoints()).hasSize(1);
///assertThat(changedOpenApi.isCompatible()).isTrue();
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the exploratoryTest in PathDiffTest and trace OpenApiCompare.fromSpecifications into ConsoleRender.render. Run the test to inspect changedElements and the console output for the added tag, path, and operation; done means those additions are represented and rendered rather than producing a null element or no diff.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100