Fix issue #16: OpenAPI response body type#18
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughApplyMetadata now unwraps Response to the body type when auto-registering Produces(...) and treats EmptyResponse as no-body; tests and test factories add OpenAPI registration and assertions; language-service cache files updated to reflect added source files and analyzer/features for OpenAPI. ChangesOpenAPI Response Type Unwrapping & Tests 200 behavior and guidance for IResult/ProducesSuccess overrides.
Language-service Cache Updates (independent)
Sequence Diagram(s)sequenceDiagram
participant EndpointRegistry
participant OpenApiGenerator
participant App
participant TestClient
Note over EndpointRegistry,OpenApiGenerator: Startup-time metadata registration
EndpointRegistry->>OpenApiGenerator: RegisterProduces(statusCode, bodyType)
OpenApiGenerator->>App: Expose /openapi/v1.json
TestClient->>App: GET /openapi/v1.json
App->>TestClient: JSON with components.schemas referencing unwrapped body types
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)and handling EmptyResponse appropriately.
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/AxisEndpoints/Internal/EndpointRegistry.cs (1)
472-505:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winHandle
EmptyResponsebefore auto-registeringProduces.
ResponseExecutorturnsResponse<EmptyResponse>into a status-only result, but this path now advertisesEmptyResponseas a JSON payload. Please skipProduces(200, ...)for no-body responses so the OpenAPI contract matches runtime behavior.Suggested adjustment
- if (!isIResult) + if (!isIResult && openApiResponseType != typeof(EmptyResponse)) { routeBuilder.Produces(200, openApiResponseType); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/AxisEndpoints/Internal/EndpointRegistry.cs` around lines 472 - 505, The auto-registration should skip no-body responses: update the logic that uses GetOpenApiResponseType(config.ResponseType) (used before calling routeBuilder.Produces) to treat Response<EmptyResponse> (or EmptyResponse returned directly) as a no-body case and not call routeBuilder.Produces(200, ...); specifically, after computing openApiResponseType (via GetOpenApiResponseType) check for EmptyResponse (e.g., openApiResponseType == typeof(EmptyResponse) || typeof(EmptyResponse).IsAssignableFrom(openApiResponseType)) and bail out of the Produces(200, ...) registration when true so the OpenAPI contract matches ResponseExecutor’s status-only behavior; leave the ExtraProducesEntries loop unchanged.
🧹 Nitpick comments (1)
tests/AxisEndpoints.Tests/Integration/EndpointIntegrationTests.cs (1)
74-86: ⚡ Quick winAdd a regression for the no-body response path.
This test only covers
Response<HelloResponse>. Please add a case forResponse<EmptyResponse>/NoContentas well, since that is the branch most likely to regress with the new unwrapping logic.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/AxisEndpoints.Tests/Integration/EndpointIntegrationTests.cs` around lines 74 - 86, The test OpenApi_UsesResponseBodyTypeInsteadOfResponseWrapper only asserts unwrapping for Response<HelloResponse>; add a second assertion or a new test that covers the no-body path (Response<EmptyResponse> / NoContent) by calling _client.GetFromJsonAsync<JsonObject>("/openapi/v1.json") and verifying the /hello endpoint (or the endpoint that returns EmptyResponse) does not emit a body schema (or uses the correct no-content representation) and that components.schemas does not contain a ResponseOfEmptyResponse entry; reference the existing test pattern (document, schema lookup via document["paths"]?["/hello"]?["get"]?["responses"]?["204" or "200"]?["content"]?) and mirror the FluentAssertions checks used in OpenApi_UsesResponseBodyTypeInsteadOfResponseWrapper to validate the no-body branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/AxisEndpoints/Internal/EndpointRegistry.cs`:
- Around line 472-505: The auto-registration should skip no-body responses:
update the logic that uses GetOpenApiResponseType(config.ResponseType) (used
before calling routeBuilder.Produces) to treat Response<EmptyResponse> (or
EmptyResponse returned directly) as a no-body case and not call
routeBuilder.Produces(200, ...); specifically, after computing
openApiResponseType (via GetOpenApiResponseType) check for EmptyResponse (e.g.,
openApiResponseType == typeof(EmptyResponse) ||
typeof(EmptyResponse).IsAssignableFrom(openApiResponseType)) and bail out of the
Produces(200, ...) registration when true so the OpenAPI contract matches
ResponseExecutor’s status-only behavior; leave the ExtraProducesEntries loop
unchanged.
---
Nitpick comments:
In `@tests/AxisEndpoints.Tests/Integration/EndpointIntegrationTests.cs`:
- Around line 74-86: The test
OpenApi_UsesResponseBodyTypeInsteadOfResponseWrapper only asserts unwrapping for
Response<HelloResponse>; add a second assertion or a new test that covers the
no-body path (Response<EmptyResponse> / NoContent) by calling
_client.GetFromJsonAsync<JsonObject>("/openapi/v1.json") and verifying the
/hello endpoint (or the endpoint that returns EmptyResponse) does not emit a
body schema (or uses the correct no-content representation) and that
components.schemas does not contain a ResponseOfEmptyResponse entry; reference
the existing test pattern (document, schema lookup via
document["paths"]?["/hello"]?["get"]?["responses"]?["204" or
"200"]?["content"]?) and mirror the FluentAssertions checks used in
OpenApi_UsesResponseBodyTypeInsteadOfResponseWrapper to validate the no-body
branch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 16f180e5-70a0-4de7-b54e-89877476ca86
📒 Files selected for processing (7)
src/AxisEndpoints.Extensions.CsvHelper/AxisEndpoints.Extensions.CsvHelper.csproj.lscachesrc/AxisEndpoints/Internal/EndpointRegistry.cstests/AxisEndpoints.Example/AxisEndpoints.Example.csproj.lscachetests/AxisEndpoints.Tests/AxisEndpoints.Tests.csprojtests/AxisEndpoints.Tests/AxisEndpoints.Tests.csproj.lscachetests/AxisEndpoints.Tests/Integration/EndpointIntegrationTests.cstests/AxisEndpoints.Tests/Integration/TestWebApplicationFactory.cs
💤 Files with no reviewable changes (1)
- tests/AxisEndpoints.Example/AxisEndpoints.Example.csproj.lscache
Summary by CodeRabbit
Bug Fixes
New Features
Tests