Skip to content

Commit

Permalink
717 issue fix (#718)
Browse files Browse the repository at this point in the history
* Improve change detection to consider changeDefault field in ChangedSchema

* Add test for defaults handling in Schema

* Add test for defaults handling in Schema
  • Loading branch information
DrSatyr authored Jan 27, 2025
1 parent e415cf3 commit a8ef8e0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private DiffResult calculateCoreChanged() {
if (!changedType
&& (oldSchema == null && newSchema == null || oldSchema != null && newSchema != null)
&& !changeFormat
&& !changeDefault
&& increasedProperties.isEmpty()
&& missingProperties.isEmpty()
&& changedProperties.values().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.openapitools.openapidiff.core;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
import org.openapitools.openapidiff.core.model.ChangedSchema;

public class SchemaDefaultsTest {

@Test
public void issue717DefaultsInSchema() {
ChangedOpenApi changedOpenApi =
OpenApiCompare.fromLocations(
"issue-717-schema-defaults-handling-1.yaml",
"issue-717-schema-defaults-handling-2.yaml");

assertEquals(1, changedOpenApi.getChangedOperations().size());
assertEquals(1, changedOpenApi.getChangedSchemas().size());
ChangedSchema changedSchema = changedOpenApi.getChangedSchemas().get(0);
assertEquals(1, changedSchema.getChangedProperties().size());
assertTrue(changedSchema.getChangedProperties().containsKey("field1"));
assertTrue(changedSchema.getChangedProperties().get("field1").isChangeDefault());
}
}
21 changes: 21 additions & 0 deletions core/src/test/resources/issue-717-schema-defaults-handling-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.1.0
info:
description: Schema defaults handling
title: defaults
version: 1.0.0
paths:
/defaults/property-schema/:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TestDTO'
components:
schemas:
TestDTO:
type: object
properties:
field1:
default: default value
type: string
21 changes: 21 additions & 0 deletions core/src/test/resources/issue-717-schema-defaults-handling-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.1.0
info:
description: Schema defaults handling
title: defaults
version: 1.0.0
paths:
/defaults/property-schema/:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/TestDTO'
components:
schemas:
TestDTO:
type: object
properties:
field1:
default: default value updated
type: string

0 comments on commit a8ef8e0

Please sign in to comment.