citrusframework / citrusframework/citrus

OpenApiClientAction should not require optional fields

Open
#1,190 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
485
Forks
155
Avg merge
4d 22h
Merged PRs (30d)
6

Description

**Citrus Version**
4.2.1

**Expected behavior**
Given an openapi endpoint
And the response of the endpoint has the required fields: "category", "name", "status"
And the response of the endpoint has the optional fields: "id", "photoUrls", "tags"

When a valid request is executed
And the following json body is returned:
{
"category": {},
"name": "",
"status": "sold"
}

Then the test should pass green

**Actual behavior**
The Test always fails with `Number of entries is not equal in element: '$', expected '[photoUrls, name, id, category, tags, status]' but was '[name, category, status]'`

**Test case sample**

```java
@Test
public class OpenApiClientIT extends TestNGCitrusSpringSupport {

private final int port = SocketUtils.findAvailableTcpPort(8080);

@BindToRegistry
private final HttpServer httpServer = new HttpServerBuilder()
.port(port)
.timeout(5000L)
.autoStart(true)
.defaultStatus(HttpStatus.NO_CONTENT)
.build();

@BindToRegistry
private final HttpClient httpClient = new HttpClientBuilder()
.requestUrl("http://localhost:%d".formatted(port))
.build();

private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from(
Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-v3.json"));

@CitrusTest
public void BUG_should_only_validate_the_presence_of_required_properties() {
variable("petId", "1001");

when(openapi(petstoreSpec)
.client(httpClient)
.send("getPetById")
.message()
.accept("application/json")
.fork(true));

then(http().server(httpServer)
.receive()
.get("/pet/${petId}")
.message()
.accept("@contains('application/json')@"));

then(http().server(httpServer)
.send()
.response(HttpStatus.OK)
.message()
// TODO BUG this should be valid, according to the spec-file
.body("""
{
"category": {},
"name": "",
"status": "sold"
}
""")
.contentType("application/json"));

then(openapi(petstoreSpec)
.client(httpClient)
.receive("getPetById", HttpStatus.OK)
.message()
);
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the OpenApiClientIT test case and the referenced petstore-v3.json specification to reproduce the validation failure. Trace the OpenApiClientAction response-validation entry point used by receive("getPetById"). Done means the sample response passes while required properties remain validated and absent optional properties do not cause failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.