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.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 understanding the repository structure and the issue at hand. The issue is about OpenAPI path parameters being imported as optional when the
requiredfield is omitted, even though OpenAPI spec says path parameters are always required.Let me first explore the repository structure to understand the codebase.
Assistant
The find command didn't return output. Let me try a different approach to explore the repository.
Assistant
This is a Rust project (Cargo.toml, Cargo.lock). Let me explore the crates directory to understand the structure better.
Assistant
I need to find files related to OpenAPI import and DSL v4. Let me search for OpenAPI-related files.
Assistant
The key file is likely
/coral/crates/coral-spec/src/v4/surfaces/openapi/import.rs. Let me look at the import file first.Assistant
Now let me look at the operations file, which likely handles importing parameters:
Assistant
I found the issue! In the
import_parametersfunction, around line 134-136, therequiredfield is determined as:rustrequired: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This means if
requiredis omitted, it defaults tofalse. However, according to the OpenAPI specification, path parameters are always required. So whenlocationisOpenApiParameterLocation::Path, it should berequired: trueregardless of whether therequiredfield is present.Let me also look at the tests to understand the expected behavior:
Assistant
Good. I can see the existing tests. Now let me understand the issue better and look at the PR reference mentioned in the issue. Let me also check what the
IrOperationInputstruct looks like:Assistant
Now let me see the
OpenApiParameterLocationenum:Assistant
Now I have a clear understanding of the issue. In the
import_parametersfunction inoperations.rs, when a parameter'srequiredfield is omitted, it defaults tofalse. However, according to the OpenAPI specification, path parameters (wherein: path) are always required.Let me first create a test script to reproduce the issue:
Assistant
Let me wait for the tests to complete:
Assistant
All tests pass. Now let me create a test script to reproduce the issue - path parameters without explicit
required: trueshould still be treated as required:Assistant
Let me write a proper test case as a Rust test in the test file to demonstrate the issue. First, let me look at the structure more closely:
Assistant
Let me add a temporary test to the existing test file to confirm the bug:
Assistant
Let me add a test to confirm the bug exists. I'll add it to the test file temporarily:
Assistant
The test confirms the bug. The path parameter is being imported with
required=falseeven though OpenAPI spec says path parameters are always required.Now let me fix the issue in the
operations.rsfile. I need to modify theimport_parametersfunction to treat path parameters as required regardless of whether therequiredfield is present:Assistant
I found the exact location of the bug. Lines 158-161:
rustrequired: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This should be changed to treat path parameters as required. The fix should check if
location == OpenApiParameterLocation::Pathand if so, setrequiredtotrueregardless of therequiredfield value.Let me apply the fix:
Assistant
I see the edit removed the
requiredfield entirely. I need to add it back with the correct logic. Let me fix this:Assistant
I made a mistake with the edits and the file is now broken. Let me restore it and start fresh:
Assistant
Now let me view the exact lines I need to modify and use the proper
editformat:Assistant
Now I can see the exact lines. Lines 158-161 contain the
requiredfield logic. I need to change it so that for path parameters, it defaults totrue. Let me use the replace command:Assistant
The change looks correct. Now let me run the test I added to verify the fix:
Assistant
The test passes. Now let me run all the OpenAPI tests to make sure I didn't break anything:
Assistant
All 14 OpenAPI tests pass. Now let me also run all tests in the coral-spec package to ensure nothing else is broken:
Assistant
All 220 tests pass. Now let me think about edge cases and verify they are handled correctly:
- Path parameter with explicit
required: true- Should still be required (existing tests cover this) - Path parameter with explicit
required: false- My fix still treats it as required sincelocation == Pathtakes precedence. This is correct per OpenAPI spec. - Query/Header/Cookie parameters without
requiredfield - Should remain optional (default false) - Query parameter with
required: true- Should be required
Let me add a quick verification test to check non-path parameters are not affected:
- Path parameter with explicit
Assistant
I have a type error in my test. Let me fix the test:
Assistant
Let me revert the test file and rewrite the test with correct types:
Assistant
Now let me add both tests with the correct format:
Assistant
The filter didn't match. Let me try a different approach:
Assistant
Both new tests pass. Now let me run all OpenAPI tests again to make sure everything still works:
Assistant
All 15 OpenAPI tests pass. Now let me run the full test suite for the coral-spec package to make sure nothing is broken:
Assistant
all 221 tests pass. Now let me also verify the projection tests since the issue mentions "add focused importer/projection coverage." Let me check if there are any projection-related tests that might be affected:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec projection 2>&1 </tool_call>
Assistant
The previous command didn't run. Let me try again.
Assistant
The instructions say I should not add new tests to the repository. Let me remove the tests I added and only keep the fix:
Assistant
Let me also clean up any temporary test files I created:
Assistant
Let me re-read the issue. The acceptance criteria mentions "add focused importer/projection coverage" but the system instructions say I must NOT modify existing tests or add new tests. So I'll just keep the code fix.
Let me run all the existing tests to make sure my fix doesn't break anything:
Assistant
All 219 tests pass. Let me view the final state of my change to confirm it's correct:
Assistant
Let me also run a broader test to make sure I haven't broken anything else in the workspace:
Assistant
The 2 failing tests (
delete_restores_artifacts_on_cleanup_failureandimport_rolls_back_on_config_write_failure) are in thecoral-apppackage and appear to be unrelated to my OpenAPI importer fix. Let me verify these tests were already failing before my change by reverting and running them:Assistant
Good, the test was already failing before my change. This is a pre-existing issue unrelated to my fix. Let me restore my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.