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.
Assistant
Let me start by exploring the repository structure to understand the codebase and find relevant files related to the issue.
The issue is about OpenAPI path parameters being imported as optional when
requiredis omitted, even though path parameters are required by OpenAPI. The fix should:- Import path parameters as required regardless of an omitted
requiredfield - Preserve explicit behavior for non-path parameters
- Add focused importer/projection coverage
Let me first explore the repository structure.
- Import path parameters as required regardless of an omitted
Assistant
Let me explore the structure further. This is a Rust project (Cargo.toml). Let me search for files related to OpenAPI and import.
<tool_call> <function=bash_terminal> <parameter=command> find . -type f -name "*.rs" | head -50 </tool_call>
Assistant
Let me run the find command properly to locate Rust files.
Assistant
Based on the issue, I need to find files related to OpenAPI path parameters import. The most relevant file seems to be
./crates/coral-spec/src/v4/surfaces/openapi/import.rs. Let me look at that file and also at the PR link mentioned in the issue.Assistant
I need to use the correct tool syntax. The open command needs
--fileoption.Assistant
This file contains the import logic. Now I need to find the
import_operationmethod and see where path parameters are being handled. The issue mentions that path parameters are imported as optional whenrequiredis omitted, but path parameters are required by OpenAPI specification.Let me look at the operations.rs file to find how parameters are imported.
<tool_call> <function=bash_terminal> <parameter=command> cat /coral/crates/coral-spec/src/v4/surfaces/openapi/operations.rs </tool_call>
Assistant
I need to use the bash_terminal tool to run the command.
Assistant
Now I can see the issue. In the
import_parametersmethod, the code is handling parameters. The problem is in this section:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),For path parameters, the
requiredfield should betrueby default according to OpenAPI specification, even if it's not explicitly set. Currently, it defaults tofalsewhenrequiredis omitted.Let me also look at the IR model to understand the data structures better.
<tool_call> <function=bash_terminal> <parameter=command> cat /coral/crates/coral-spec/src/v4/ir/model.rs </tool_call>
Assistant
Let me run the command properly to see the IR model file.
Assistant
Now I understand the structure. The
IrOperationInputstruct has arequiredfield. The issue is in theimport_parametersfunction inoperations.rswhere path parameters default torequired: falsewhen therequiredfield is not explicitly set.According to OpenAPI specification, path parameters are always required. Let me now check the PR link mentioned in the issue to understand the context better, and also look at any tests related to this functionality.
Let me first look at the tests for the OpenAPI import:
<tool_call> <function=bash_terminal> <parameter=command> find . -type f -name "*.rs" -exec grep -l "path.*parameter|required.*path|OpenApiParameterLocation" {} ; 2>/dev/null | head -20 </tool_call>
Assistant
I need to run the grep command to find files related to path parameters and OpenAPI.
Assistant
Now let me check for tests related to OpenAPI import:
<tool_call> <function=bash_terminal> <parameter=command> find . -type f -name "test.rs" -path "openapi" 2>/dev/null </tool_call>
Assistant
Let me try running a find command to locate test files related to OpenAPI.
Assistant
Let me look at this test file to understand the test cases for OpenAPI import.
Assistant
Now I have a clear understanding of the issue. Looking at the
import_parametersfunction inoperations.rs, the key issue is:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This code sets
requiredtofalsewhen therequiredfield is omitted from a parameter. However, according to OpenAPI specification, path parameters are always required, even if therequiredfield is not explicitly set.The fix should check if the parameter location is
pathand default totruefor path parameters whenrequiredis not explicitly set.Let me also check what the PR #1149 mentioned in the issue might have changed. Let me look at the git history.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git log --oneline -20 </tool_call>
Assistant
Let me run the git log command properly to see the recent commits.
Assistant
Let me look at the specific commit that split the v4 module and see if the issue was introduced there:
<tool_call> <function=bash_terminal> <parameter=command> git show 2be31a9 --stat | head -50 </tool_call>
Assistant
Let me check the git diff for the commit that split v4 module to see what changes were made:
Assistant
Now I understand the issue. Looking at the code in
operations.rs, theimport_parametersfunction has this logic:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This defaults to
falsewhenrequiredis not set, but path parameters are always required according to the OpenAPI specification. Let me first write a test to reproduce the issue, then fix it.Assistant
Now I need to add a test case to verify that path parameters are imported as required even when the
requiredfield is omitted. Let me first write a script to test this issue, then make the fix.Let me first look at the end of the openapi_tests.rs file to see where I should add a new test:
Assistant
Now let me create a test script to reproduce the issue. I'll add a test case that verifies path parameters without explicit
required: trueare still imported as required.First, let me add the test to the test file:
<tool_call> <function=bash_terminal> <parameter=command> cat >> /coral/crates/coral-spec/src/v4/openapi_tests.rs << 'EOF'
#[test] fn importer_imports_path_parameters_as_required_by_default() { // Path parameters are always required by OpenAPI spec, even if 'required' field is omitted let manifest = parse_source_manifest_yaml( r" name: api dsl_version: 4 surfaces:
Assistant
Let me try to append a test case to reproduce the issue. This test will verify the current buggy behavior where path parameters without explicit
required: trueare incorrectly imported as optional.Assistant
The test I tried to append didn't work because the command syntax was incorrect. Let me try a different approach to add the test case. First, let me check if the test was added:
Assistant
The test wasn't added. Let me try using the
edittool to add a test case to verify the issue.<tool_call> <function=bash_terminal> <parameter=command> echo ' #[test] fn importer_imports_path_parameters_as_required_by_default() { // Path parameters are always required by OpenAPI spec, even if '''required''' field is omitted let manifest = parse_source_manifest_yaml( r" name: api dsl_version: 4 surfaces:
-
id: rest type: openapi file: /tmp/openapi.yaml base_url: ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface"); let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /items/{item_id}: get: operationId: items/get parameters: - name: item_id in: path schema: {type: string} - name: include_details in: query responses: '''200''': content: application/json: schema: type: object properties: id: {type: string} " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation");
-
Assistant
Let me run the echo command properly:
Assistant
Let me verify the test was added to the file:
Assistant
I need to add the opening lines for the test. Let me check the file again and fix it:
<tool_call> <function=bash_terminal> <parameter=command> tail -65 /coral/crates/coral-spec/src/v4/openapi_tests.rs | head -10 </tool_call>
Assistant
Let me try a different approach to add the test case.
Assistant
Good, the test was added. Now let me run the test to verify it fails with the current buggy code:
Assistant
The test confirms the issue: path parameters are being imported as
required: falseeven though they should be required according to the OpenAPI spec. The assertion failed becauseleft: false(current behavior) butright: true(expected behavior).Now let me fix the issue in
operations.rs. The fix should check if the parameter location ispathand default torequired: truewhen therequiredfield is omitted.Assistant
Let me see the context around that line and understand the code better:
Assistant
Now I understand the issue. The fix is to change the default value from
falseto check if the parameter is a path parameter - in which case it should default totrue. Let me fix this:Assistant
Let me verify the change was made correctly:
Assistant
The change was made correctly. Now let me run the test to verify the fix works:
Assistant
I see the issue - the sed command replaced all occurrences. Let me check the file and fix it:
Assistant
Let me see lines 60-75 to understand what was affected:
Assistant
I accidentally replaced too many lines. Let me check line 240 too:
Assistant
I need to revert those wrong replacements. Let me use git to restore the file and be more careful:
Assistant
Now let me be more precise with the edit and only change the specific line for the parameter's
requiredfield:Assistant
Let me be more precise and use the sed command with a specific line number:
Assistant
Let me verify the change:
Assistant
Let me verify no other unwanted replacements were made:
Assistant
Let me verify lines 68 and 240 are still correct:
Assistant
Let me run the test now to verify the fix works:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec importer_imports_path_parameters_as_required_by_default -- --nocapture 2>&1 | tail -20 </tool_call>
Assistant
Let me run the cargo test to verify the fix.
Assistant
The test passes now! The fix is working correctly. Path parameters without explicit
required: trueare now imported as required.Let me now run the existing tests to make sure my fix doesn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec --lib 2>&1 | tail -30 </tool_call>
Assistant
Let me run the existing tests to make sure the fix doesn't break anything.
Assistant
Assistant
Let me try using echo to append the test cases:
Assistant
The command succeeded, but I need to continue appending the second test. Let me do that now.
Assistant
Let me run the tests to verify all the edge cases work correctly.
Assistant
Good, the path parameter tests pass. Let me also run the test for non-path parameters:
Assistant
All three new tests pass. Now let me run all tests to ensure the fix doesn't break any existing functionality:
Assistant
All 222 tests pass. Let me verify all the new tests are in place and run the full test suite:
Assistant
The tests for path parameters were added. Now let me run the full test suite to make sure everything works correctly.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test 2>&1 | tail -50 </tool_call>
Assistant
Let me run the full test suite properly.
Assistant
These two test failures seem to be pre-existing issues unrelated to my change. They're integration tests for the coral-app that are failing due to some test environment or timing issues. Let me verify by checking if these tests were passing before my change by reverting and running them.
Actually, let me first verify that the coral-spec tests (which are the ones most relevant to my change) are all passing:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec --lib 2>&1 | grep -E "test result|FAILED|passed" </tool_call>
Assistant
Let me verify the coral-spec tests are all passing.
Assistant
All 222 tests in coral-spec pass. The failing tests in coral-app are unrelated to my change - they are integration tests that seem to have pre-existing issues. Let me verify this by checking the git status to see what files have been changed:
<tool_call> <function=bash_terminal> <parameter=command> git diff </tool_call>
Assistant
Let me check the git diff to see what files I have changed.
Assistant
The changes look correct. Let me now also check if the failing tests in coral-app were pre-existing by reverting the changes and running them:
Actually, let me first check if those tests pass without my change. I'll use git stash to save my changes and run the tests.
<tool_call> <function=bash_terminal> <parameter=command> git stash </tool_call>
Assistant
Let me run git stash to save my changes and see if the failing tests are pre-existing.
Assistant
Let me now run the failing tests in coral-app to check if they are pre-existing failures.
Assistant
Let me fix the cargo test command:
Assistant
The test fails even without my change. This confirms the test failure is a pre-existing issue unrelated to my fix. Let me restore my changes:
<tool_call> <function=bash_terminal> <parameter=command> git stash pop </tool_call>
Assistant
Good, the test failure is a pre-existing issue unrelated to my fix. Let me verify my changes are restored:
Assistant
The git stash pop didn't seem to work properly. Let me check the current status:
<tool_call> <function=bash_terminal> <parameter=command> git status </tool_call>
Assistant
Let me check the git status to see what happened with the stash.
Assistant
Let me check what's in the stash and restore the changes:
Assistant
The stash is still there. Let me pop it:
Assistant
Good, my changes are restored. Let me verify the changes are correct by running the coral-spec tests again:
Assistant
All 222 tests in coral-spec pass. Now let me also verify that my fix handles the edge case where a path parameter is explicitly set to
required: false. According to my understanding of the issue, the problem is specifically when is omitted. Let me verify this behavior is correct.Assistant
Let me check the git diff to verify my changes are ready for submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.