ISSUE DESCRIPTION Treat OpenAPI path parameters as required in v4 import This tracks…
- User
ISSUE DESCRIPTION
Treat OpenAPI path parameters as required in v4 import This tracks unresolved feedback identified by cubic on PR #1149: https://github.com/withcoral/coral/pull/1149#discussion_r3347190640
Context: This appears to be pre-existing DSL v4 behavior surfaced by the refactor review, not a regression from the module split.
Problem: OpenAPI path parameters are imported as optional when
requiredis omitted, even though path parameters are required by OpenAPI. This can misclassify required path inputs as optional SQL filters.Acceptance criteria: Import path parameters as required regardless of an omitted
requiredfield, preserve explicit behavior for non-path parameters, and add focused importer/projection coverage.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /coral, current file: none) bash-$
- Assistant
I'll start by exploring the repository to understand the structure and locate relevant files related to OpenAPI import and path parameters. Let me first look at the overall directory.
- Assistant
Let me explore the repository structure more broadly to understand what we're working with.
- Assistant
This is a Rust project (Cargo.toml). The issue is about OpenAPI path parameters being imported as optional. Let me search for OpenAPI-related code.
- Assistant
Let me examine the OpenAPI import code, especially the file related to path parameters.
- Assistant
Let me look at the OpenAPI import code, which is the most relevant file.
- Assistant
Let me look at the operations.rs file which likely handles parameter parsing:
- Assistant
Now I can see the issue. In the
import_parametersmethod, around lines 112-115, there's this code:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This means if the
requiredfield is omitted (which is allowed by OpenAPI for path parameters since they are always required), it defaults tofalse(optional). According to OpenAPI specification, path parameters MUST always be required.Let me also look at the existing tests to understand the test structure and find relevant test files.
- Assistant
Let me examine the test files to understand how tests are structured:
- Assistant
Now let me look at the projection_tests.rs to understand how projections handle parameters:
- Assistant
Let me check the IR structure to understand what
requiredfield is used for: - Assistant
Let me find the IrOperationInput struct definition.
- Assistant
Let me examine the IrOperationInput struct.
- Assistant
Now let me check the projection code that uses the
requiredfield to determine if a parameter becomes an optional SQL filter. Let me search for that. - Assistant
Let me find the projection generation code.
- Assistant
Let me check how the
requiredfield is used in the projection code. - Assistant
Now I understand the issue better. Looking at the code:
-
In
operations.rs, when importing parameters, therequiredfield is read from the OpenAPI parameter object. If it's not present, it defaults tofalse(optional). -
According to OpenAPI specification, path parameters are always required. The spec says: "If the parameter location is 'path', this property is REQUIRED and its value MUST be true."
-
The issue is that when OpenAPI documents omit the
requiredfield for path parameters (which is technically valid since it should be true anyway), they're being imported as optional. -
This affects how they're used in projections - optional parameters become SQL filters, while required parameters might become function arguments.
Let me create a test to reproduce the issue. First, let me check if there are existing tests that show this behavior:
-
- Assistant
Let me look at the test_support.rs to understand the helper functions.
- Assistant
Let me first create a test to reproduce the issue - I'll write a test where a path parameter doesn't have the
requiredfield, and verify that it's currently imported as optional. Then I'll fix the code and verify the test passes.Let me first check if there's a way to run existing tests to make sure I don't break anything:
- Assistant
The compilation is taking a while. Let me try to run the specific tests to see if they pass first.
- Assistant
Let me check the current directory
- Assistant
Good, I'm already in
crates/coral-spec. Let me run tests from here. - Assistant
Good! All existing tests pass. Now let me create a test to reproduce the issue. I'll write a simple script that creates an OpenAPI document with a path parameter that doesn't have the
requiredfield and verify that it's currently imported as optional. - Assistant
Actually, I should write this as a proper Rust test in the openapi_tests.rs file. Let me do that instead. First, let me understand the existing test structure better by looking at the imports and structure in openapi_tests.rs:
- Assistant
We're in /coral/crates/coral-spec, so the file is at src/v4/openapi_tests.rs
- Assistant
Let me check what's in the super module to understand what's available in tests:
- Assistant
Let me check the exports from surfaces module:
- Assistant
Let me check what's exported from the openapi module:
- Assistant
Good. So
import_openapi_surfaceandgenerate_projection_catalogare both available viasuper::*in the test file. Let me now write a proper test in the openapi_tests.rs file. - Assistant
Let me check the exact line in operations.rs where required is computed:
- Assistant
Let me look at the exact context around line 158 in operations.rs:
- Assistant
Now I understand the exact location of the bug. Lines 158-161 in
operations.rs. The fix should be:- If the location is
Path, always set required totrue(per OpenAPI spec) - Otherwise, use the existing behavior (default to
falseif omitted)
Now let me also check how this is used in projections to understand the full impact. Let me look at the projection code that uses
input.required: - If the location is
- Assistant
Let me also check the projection tests to see if there are existing tests for path parameters without required field:
- Assistant
All existing tests have
required: truefor path parameters. Now let me implement the fix. The fix is simple: in theimport_parametersmethod inoperations.rs, when computing therequiredfield, we need to check if the location isPath. If it is, we should setrequiredtotrueregardless of what the OpenAPI document says. - Assistant
Let me use the correct syntax for the edit command.
- Assistant
Let me use the edit command properly:
- Assistant
Great! The fix is applied. Now I need to add tests for this behavior. Let me run the existing tests first to make sure they still pass:
- Assistant
Perfect! All existing tests pass. Now I need to add tests for the new behavior. Let me add tests to the openapi_tests.rs file. I need to add:
- A test for path parameters without required field (should be imported as required)
- A test for path parameters with explicit required: false (should respect explicit false)
- A test for query parameters without required field (should remain optional)
- A test for projection behavior with path parameters without required field
Let me first check the end of the openapi_tests.rs file to add the tests:
- Assistant
Now let me add tests to the end of the file. First, let me check what imports are needed. Let me also check if there's a projection test file I should add tests to:
- Assistant
Let me check the imports in projection_tests.rs:
- Assistant
Now let me add tests to the openapi_tests.rs file. I'll add them at the end:
- Assistant
Let me check the end of the file to make sure it's complete:
- Assistant
Good! Now let me also add a projection test. Let me check if there's a projection test file I should add tests to:
- Assistant
I should also add a projection test that verifies that path parameters without required field are treated as required in projections. Let me add that to the projection_tests.rs file:
- Assistant
Let me check what helper function is used for filter specs:
- Assistant
Let me check the imports and see if projection_filter_specs is imported:
- Assistant
Let me check if it's available in the projections module:
- Assistant
Good. Now let me add a projection test at the end of projection_tests.rs. First, let me check what FilterSpec looks like:
- Assistant
Let me check what's imported from the module to see what FilterSpec is:
- Assistant
Good. Now let me add a projection test to the end of projection_tests.rs:
- Assistant
Now let me add a projection test at the end of projection_tests.rs:
- Assistant
I notice there's a missing closing brace. Let me fix that:
- Assistant
I see there's a duplicate line in the projection test. Let me fix that:
- Assistant
I see there's an extra closing brace. Let me fix that:
- Assistant
I need to fix the duplicate
}. Let me look at the file more carefully. - Assistant
I need to fix the duplicate function definition. Let me fix that:
- Assistant
Good! Now let me run the tests to make sure everything passes:
- Assistant
There's an unclosed delimiter in openapi_tests.rs. Let me fix it:
- Assistant
I see the issue - line 665 has
assert_eq!(operation.output.cardinality, OutputCardinality::Unknown);but there's no closing brace}after it. The original test was missing the closing brace. Let me fix it: - Assistant
Good! Now let me run the tests again:
- Assistant
All 223 tests pass. Now let me also check that the new tests I added are being run:
- Assistant
Perfect! All three new tests pass:
importer_treats_path_parameters_without_required_as_required- tests that path parameters without required field are imported as requiredimporter_respects_explicit_required_false_on_path_parameter- tests that explicit required: false is respectedprojection_treats_path_parameter_without_required_as_required- tests that path parameters without required field are treated as required in projections
Let me also run a test for query parameters to make sure they still work correctly:
- Assistant
Excellent! All tests pass. Now let me also run the openapi tests to make sure everything is working correctly:
- Assistant
Perfect! All tests pass. Now let me clean up the temporary test file I created earlier:
- Assistant
Now let me verify my changes by looking at the diff:
- Assistant
Perfect! The changes look good. Let me also check if there are any other places in the codebase that might need similar changes. Let me search for other places where
requiredis computed from OpenAPI parameters: - Assistant
Let me try a different approach:
- Assistant
Good! I can see that the only place where
requiredis computed for parameters is in line 158, which I've already fixed. The other place is for request bodies (line 237), which is correct - request bodies can be optional or required.Now let me run the full test suite to make sure everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →