Skip to content

[OpenAPI] Allow for invalid documents - #9022

Merged
tobias-tengler merged 3 commits into
mainfrom
tte/cleanup-openapi-validator
Dec 29, 2025
Merged

tobias-tengler merged 3 commits into
mainfrom
tte/cleanup-openapi-validator

Conversation

@tobias-tengler

Copy link
Copy Markdown
Member

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.

@tobias-tengler
tobias-tengler marked this pull request as ready for review December 29, 2025 14:30
Copilot AI review requested due to automatic review settings December 29, 2025 14:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Fusion Gateway Performance Results

Simple Composite Query

Constant Load (50 VUs)

Requests/sec Error Rate
5837.58 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
0.79ms 7.09ms 160.41ms 8.41ms 12.99ms 18.27ms

Ramping Load (0→50→500→50 VUs)

Requests/sec Error Rate
4602.75 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
0.85ms 37.77ms 264.83ms 48.26ms 108.73ms 125.59ms

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 Query

Constant Load (50 VUs)

Requests/sec Error Rate
266.94 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
12.97ms 175.17ms 609.36ms 181.60ms 227.25ms 255.62ms

Ramping Load (0→50→500→50 VUs)

Requests/sec Error Rate
308.29 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
3.03ms 675.95ms 1728.61ms 687.86ms 1392.43ms 1495.89ms

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 Throughput

Constant Load (50 VUs)

Requests/sec Error Rate
24000.08 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
0.09ms 1.68ms 41.82ms 2.03ms 3.89ms 4.74ms

Ramping Load (0→50→500→50 VUs)

Requests/sec Error Rate
18898.56 req/s 0.00%
📊 Response Time Metrics
Min Med Max Avg P90 P95
0.09ms 9.22ms 97.23ms 11.20ms 23.17ms 27.92ms

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

@tobias-tengler
tobias-tengler merged commit eff192a into main Dec 29, 2025
114 checks passed
@tobias-tengler
tobias-tengler deleted the tte/cleanup-openapi-validator branch December 29, 2025 15:19
@codecov

codecov Bot commented Dec 29, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (3b85c32) to head (13b6113).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #9022   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants