citrusframework / citrusframework/citrus

OpenApiClient should allow multiple content-types

Open
#1,189 0 comments 0 reactions 0 assignees View on GitHub
enhancement
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 that endpoint can respond in `application/json`
And that endpoint can respond in `application/xml`

When a request with `accept: application/xml` is executed
And a valid XML is returned

Then the content-type of the response should be valid
And test should pass green

**Actual behavior**

The test always fails with `Values not equal for header element 'Content-Type', expected 'application/json' but was 'application/xml'`

**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_be_possible_to_switch_content_type__to_xml() {
variable("petId", "1001");

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

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

then(http().server(httpServer)
.send()
.response(HttpStatus.OK)
.message()
.body("")
.contentType("application/xml"));

then(openapi(petstoreSpec)
.client(httpClient)
.receive("getPetById", HttpStatus.OK)
.message()
// TODO BUG XML bodies do not seem to work, even if there is just XML as "produces" in the spec
.body("")
// TODO BUG the type/contentType statements are useless, if there is another type in the spec.
// even if there are two. i.E:
// # this will always use JSON as type
// produces:
// - application/json
// - application/xml
.contentType("application/xml")
.type(XML));
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied OpenApiClientIT case with the petstore-v3.json OpenAPI specification and inspect how the openapi send and receive steps select content types. Verify behavior for endpoints producing application/json and application/xml, including the XML body and response Content-Type. Done means the test accepts application/xml when requested without breaking JSON handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.