Repository navigation
[OpenAPI] Allow for invalid documents - #9022
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modifies the OpenAPI adapter to allow invalid documents to still create endpoints that return HTTP 500 instead of HTTP 404. Previously, invalid documents would prevent endpoints from being added entirely. The PR simplifies the validation approach by:
- Removing cross-document validation rules (e.g., model name uniqueness, route uniqueness, model references existence)
- Converting validation from async to sync operations
- Adding runtime validation when endpoints are invoked to return HTTP 500 for invalid documents
- Handling duplicate routes, operation names, and model names by using "first-wins" semantics with TryAdd
Key Changes
- Simplified validation to per-document basis only, removing cross-document validation rules
- Endpoints with invalid documents are now created but return HTTP 500 when invoked
- Changed validation methods from async to sync throughout the validation infrastructure
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| ValidationTestBase.cs | Removed tests for cross-document validation rules that were deleted |
| OpenApiIntegrationTestBase.cs | Added new tests for handling invalid documents (missing fields, missing model references, duplicated routes/operations/models) |
| HttpEndpointIntegrationTestBase.cs | Added tests verifying invalid endpoints return HTTP 500; minor formatting change to dictionary initializer |
| OpenApiDefinitionValidator.cs | Simplified validator to only include per-document validation rules; changed from async to sync |
| OpenApiDefinitionRegistry.cs | Removed complex cross-document validation logic; added duplicate detection for routes; uses TryAdd for model lookup |
| OpenApiEndpointFactory.cs | Added runtime document validation and stores validation result in endpoint descriptor; handles missing model references gracefully |
| OpenApiEndpointDescriptor.cs | Added HasValidDocument flag to track validation status |
| DynamicEndpointMiddleware.cs | Added check to return HTTP 500 for invalid documents before executing requests |
| DynamicOpenApiDocumentTransformer.cs | Added error handling with try-catch blocks; handles duplicate operation IDs with counters; uses TryAdd for components |
| Multiple validation rule files | Deleted cross-document validation rules (model name uniqueness, route uniqueness, model references, schema compilation) |
| Multiple validation interface files | Changed from async to sync validation methods |
| Multiple snapshot files | Added expected OpenAPI outputs for invalid document scenarios |
Comments suppressed due to low confidence (1)
src/HotChocolate/Adapters/src/Adapters.OpenApi.Core/OpenApiDefinitionRegistry.cs:166
- The catch block silently swallows all exceptions without logging or diagnostics. This makes it difficult to debug issues when endpoint construction fails. Consider logging the exception or emitting a diagnostic event to help developers understand why an endpoint failed to be created.
catch
{
// If the construction of an endpoint fails, we just skip over it.
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🚀 Fusion Gateway Performance ResultsSimple Composite QueryConstant Load (50 VUs)
📊 Response Time Metrics
Ramping Load (0→50→500→50 VUs)
📊 Response Time Metrics
Executed Query fragment User on User {
id
username
name
}
fragment Review on Review {
id
body
}
fragment Product on Product {
inStock
name
price
shippingEstimate
upc
weight
}
query TestQuery {
topProducts(first: 5) {
...Product
reviews {
...Review
author {
...User
}
}
}
}Deep Recursion QueryConstant Load (50 VUs)
📊 Response Time Metrics
Ramping Load (0→50→500→50 VUs)
📊 Response Time Metrics
Executed Query fragment User on User {
id
username
name
}
fragment Review on Review {
id
body
}
fragment Product on Product {
inStock
name
price
shippingEstimate
upc
weight
}
query TestQuery {
users {
...User
reviews {
...Review
product {
...Product
reviews {
...Review
author {
...User
reviews {
...Review
product {
...Product
}
}
}
}
}
}
}
topProducts(first: 5) {
...Product
reviews {
...Review
author {
...User
reviews {
...Review
product {
...Product
}
}
}
}
}
}Variable Batching ThroughputConstant Load (50 VUs)
📊 Response Time Metrics
Ramping Load (0→50→500→50 VUs)
📊 Response Time Metrics
Executed Query query TestQuery_8f7a46ce_2(
$__fusion_1_upc: ID!
$__fusion_2_price: Long!
$__fusion_2_weight: Long!
) {
productByUpc(upc: $__fusion_1_upc) {
inStock
shippingEstimate(weight: $__fusion_2_weight, price: $__fusion_2_price)
}
}Variables (5 sets batched in single request) [
{ "__fusion_1_upc": "1", "__fusion_2_price": 899, "__fusion_2_weight": 100 },
{ "__fusion_1_upc": "2", "__fusion_2_price": 1299, "__fusion_2_weight": 1000 },
{ "__fusion_1_upc": "3", "__fusion_2_price": 15, "__fusion_2_weight": 20 },
{ "__fusion_1_upc": "4", "__fusion_2_price": 499, "__fusion_2_weight": 100 },
{ "__fusion_1_upc": "5", "__fusion_2_price": 1299, "__fusion_2_weight": 1000 }
]No baseline data available for comparison. Run 20575417663 • Commit a6e50fc • Mon, 29 Dec 2025 14:57:18 GMT |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9022 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Previously invalid documents would cause an endpoint to not be added. This means that a consumer would suddenly get a 404 instead of a more appropriate 500 statuscode.
This PR also removes validation that spans all documents and simplifies the validator to only validate on a per document basis.