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
requiredis omitted, even though path parameters are inherently required by the OpenAPI specification.Let me first explore the repository structure to understand the codebase.
Assistant
Let me look at the OpenAPI import file since this is about importing path parameters:
Assistant
Now I can see the issue. In
import_parameters, therequiredfield is determined by:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),This means when
requiredis omitted, it defaults tofalse. However, according to OpenAPI spec, path parameters are always required. Let me look at the test files to understand the expected behavior better:Assistant
Let me also look at the IR model to understand the data structures:
Assistant
Now let me also look at the projection tests to understand how projections handle required inputs:
Assistant
Let me also check the projections module to understand how inputs are processed:
Assistant
Now let me check how the projection derives its inputs from the IR:
Assistant
Now I understand the issue. The problem is in
operations.rsin theimport_parametersfunction. When processing parameters, therequiredfield defaults tofalseif not explicitly set:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),However, according to the OpenAPI specification, path parameters are always required. Let me fix this by checking if the location is
pathand treating those as required whenrequiredis omitted.Let me first create a test script to reproduce the issue:
Assistant
Let me run the existing tests first to understand the current state:
Assistant
Good. All tests pass. Now let me write a test that reproduces the issue - a path parameter without explicit
required: trueshould still be treated as required:Assistant
Let me run the test by creating a small test binary:
Assistant
Let me add a test directly to the test file to confirm the issue:
Assistant
Let me write a quick test script to verify the issue:
Assistant
Let me instead add a test directly to the openapi_tests.rs file to verify the bug:
Assistant
The open tool doesn't accept line_number as a separate argument. Let me try with the correct format.
Assistant
Now let me first add a temporary test to confirm the bug exists, then fix the code:
Assistant
Now let me run this test to confirm the bug exists:
Assistant
I have confirmed the bug. The test fails because path parameters are being treated as optional when
requiredis omitted. Now let me fix the code inoperations.rs:Assistant
Now I can see the exact code I need to modify. The issue is in the
import_parametersfunction around line 146:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),I need to change this so that path parameters are always required (per OpenAPI spec), while non-path parameters preserve their explicit behavior (optional when
requiredis omitted).Let me make the fix:
Assistant
Now I'll apply the fix. The key change is to treat path parameters as required regardless of whether the
requiredfield is present:Assistant
The fix looks good. Now let me run the test to verify the fix works:
Assistant
The test passes. Now let me run all the existing tests to make sure I haven't broken anything:
Assistant
All OpenAPI tests pass. Let me also run the projection tests and all coral-spec tests:
Assistant
All 220 tests pass. Now let me also think about edge cases:
- Path parameter with
required: true(explicit): Should still be required - this works sincetrue || anything=true - Path parameter with
required: false(explicit false): Per OpenAPI spec, path parameters are always required, so this should also be treated as required - the fix handles this becauselocation == OpenApiParameterLocation::Pathwill betrueregardless of the explicit value. - Query/Header/Cookie parameters without
requiredfield: Should remain optional - this works since the condition only applies to path parameters. - Query/Header/Cookie parameters with
required: true: Should be required - this works since the explicit value is preserved.
Let me add a more comprehensive test to cover these edge cases:
- Path parameter with
Assistant
All edge case tests pass. Let me run all coral-spec tests one more time to make sure everything is working:
Assistant
All 221 tests pass. Now let me also verify that the projection generation works correctly with path parameters marked as required. Let me check if there's a test that verifies the projection behavior:
Assistant
All tests pass. Let me run all tests one final time to make sure everything is working:
Assistant
Excellent! All 222 tests pass. Let me now view the final state of my changes to summarize:
Assistant
The core fix is a simple one-line change (plus proper formatting) that treats path parameters as required regardless of the
requiredfield's presence or value, while preserving explicit behavior for non-path parameters.Let me also verify there aren't any other tests in the broader codebase that might be affected:
Assistant
The 2 failing tests appear to be pre-existing flaky tests related to source lifecycle and config write failures - they're unrelated to my change (they deal with config write failures and cleanup, not OpenAPI importing). Let me verify by checking if these tests fail without my changes:
Assistant
The failing tests are pre-existing failures, unrelated to my changes. Let me restore my changes:
Assistant
Good. The pre-existing test failures are unrelated to my changes. Let me run the coral-spec tests once more to confirm my changes work:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.