OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Rest-assured] Add log to request and response bodies.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generated in rest-assured, the api-client does not have a log for the request and response body. And when you run the test, you can't see the request and response parameters. Rest-assured is used only for testing, and without information about requests and responses, it's hard to know the problem.
openapi-generator version
v. 6.0.0
OpenAPI declaration file content or url
Generation Details
use openapi-generator-maven-plugin
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>pet</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/index.json</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
<dateLibrary>java8</dateLibrary>
<returnResponse>true</returnResponse>
</configOptions>
<library>rest-assured</library>
<skipValidateSpec>true</skipValidateSpec>
<skipIfSpecIsUnchanged>false</skipIfSpecIsUnchanged>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
petApi = PetApi.pet(() -> new RequestSpecBuilder()
.setBaseUri("http://localhost:8080"));
petApi.getPetById()
.petIdPath("1")
.executeAs(validatedWith(shouldBeCode(SC_OK)));
actual:
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> but was <404>.
but expected:
Request method: GET
Request URI: http://localhost:8085/pet/1
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: petId=1
Headers: Accept=application/json
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 404
MON_METHOD: GET
MON_URL: /pet/1
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 13 Aug 2022 17:32:12 GMT
Keep-Alive: timeout=60
Connection: keep-alive
{
"timestamp": "2022-08-13T17:32:12.209+00:00",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/pet/1"
}
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> but was <404>.
Suggest a fix
One possible solution is to add this code to the generated api client
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
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 by generating the Java client with the Maven plugin using the rest-assured library and the provided petstore specification, then inspect how the generated client configures requests. Reproduce the 404 example and verify that request and response details, including their bodies, are logged.
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
- 45/100