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.
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
Let me start by understanding the issue. The problem is that OpenAPI path parameters are being imported as optional when the
requiredfield is omitted, even though OpenAPI spec says path parameters are always required. I need to:- First explore the repository structure to understand the codebase
- Find the relevant code for importing OpenAPI specs
- Understand how path parameters are currently handled
- Fix the code to treat path parameters as required
- Add tests for the fix
Let me start by exploring the repository.
Assistant
Good, I can see this is a Rust project. The relevant files seem to be in
/coral/crates/coral-spec/src/v4/surfaces/openapi/. Let me look at the import.rs file first since that's likely where the OpenAPI parameters are imported.Assistant
Let me also look at the operations.rs file where parameters are likely being processed:
Assistant
Now I can see the issue. In the
import_parametersfunction, around line 146-148, therequiredfield is determined by:required: 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 spec, path parameters are always required. So whenlocationisOpenApiParameterLocation::Path, therequiredshould betrueregardless of whether therequiredfield is present.Let me also look at the existing tests to understand the test patterns:
Assistant
Now let me see the projection_tests.rs file to understand the projection testing patterns:
Assistant
Now let me also check the test_support.rs file to see the github_openapi fixture:
Assistant
Now I understand the issue and the codebase structure. Let me also look at the
IrOperationInputstruct definition and related types:Assistant
Now I have a clear understanding of the issue. The fix is in the
import_parametersfunction inoperations.rs. When the parameter location ispath, therequiredfield should default totrueinstead offalse.Let me first create a test script to reproduce the issue:
Assistant
Good, all tests pass. Now let me create a test script to confirm the issue - path parameters without
required: trueare being treated as optional:Assistant
Let me run the tests in a simpler way using cargo test:
Assistant
Let me look at lines 155-165 more carefully to understand the exact code I need to modify:
Assistant
Now I understand the issue. The code on lines 158-161 sets
requiredtofalseby default when therequiredfield is omitted:required: parameter_obj .get("required") .and_then(Value::as_bool) .unwrap_or(false),But according to the OpenAPI spec, path parameters are always required (see OpenAPI 3.0 spec: "When
inispath, therequiredproperty MUST be true"). So the fix should be:- If
locationisOpenApiParameterLocation::Path, defaultrequiredtotrue - For other locations, preserve the current behavior (default to
false)
Let me make the fix:
- If
Assistant
Now I'll make the fix. The key change is in lines 158-161 where the
requiredfield is determined. I need to change the default fromfalsetotruewhen the location isPath:Assistant
The sed command duplicated the lines. Let me restore the file and make the edit properly:
Assistant
Now let me make the edit properly using the edit command:
Assistant
The fix is now in place. Let me verify the code compiles:
Assistant
The code compiles. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
All 219 tests pass. Now let me add focused tests for the fix. According to the acceptance criteria, I need to:
- Add importer tests to verify path parameters are treated as required when
requiredfield is omitted - Preserve explicit behavior for non-path parameters
- Add projection coverage
Let me look at how to add tests in the openapi_tests.rs file:
- Add importer tests to verify path parameters are treated as required when
Assistant
Now let me add the new tests. I'll add tests for:
- Path parameters without explicit
requiredshould be treated as required - Path parameters with explicit
required: trueshould still work - Non-path parameters should preserve their existing behavior (optional when
requiredis omitted) - A projection test to verify path parameters produce the right SQL exposure
- Path parameters without explicit
Assistant
Now I need to add the import for
OpenApiParameterLocationat the top of the test file:Assistant
The test file uses
use super::*;which should bring in everything from the parent module. Let me check what's exported from the v4 module:Assistant
Good,
OpenApiParameterLocationis re-exported in the v4 module. Now let me run the new tests:Assistant
All new importer tests pass. Now let me add a projection test to verify that path parameters are correctly handled in projections. Let me first understand how path parameters relate to projections by looking at how
SqlInputExposureis determined:Assistant
I see that path parameters are mapped to the
default_exposure(which isSqlInputExposure::Filterfor tables). The projection test should verify that path parameters are correctly classified as filters. Let me add a projection test:Assistant
Now let me run all tests to make sure everything passes:
Assistant
All 224 tests pass. Let me also run the full test suite for the entire workspace to make sure my changes don't break anything else:
Assistant
The two failing tests are in a different crate (
coral-app) and seem unrelated to my changes. They appear to be pre-existing test failures related to file system operations (config write failure, manifest cleanup). Let me verify by checking if these tests fail even without my changes:Assistant
The test also fails without my changes, confirming these are pre-existing failures unrelated to my fix. Let me restore my changes:
Assistant
Let me verify all my changes look correct:
Assistant
All the changes look correct. Let me run the coral-spec tests one more time to confirm everything passes:
Assistant
All 224 tests pass. Let me summarize what I did and verify against the checklist:
Summary of Changes
Problem
OpenAPI path parameters were being imported as optional when the
requiredfield was omitted in the OpenAPI spec, even though path parameters are always required by the OpenAPI specification.Fix
Modified
/coral/crates/coral-spec/src/v4/surfaces/openapi/operations.rsto treat path parameters as required when therequiredfield is omitted. The change was on line 161:Before:
.unwrap_or(false),After:
.unwrap_or(location == OpenApiParameterLocation::Path),This ensures:
- Path parameters without explicit
requiredare treated as required (per OpenAPI spec) - Path parameters with explicit
required: truecontinue to work correctly - Non-path parameters (query, header, cookie) preserve their existing behavior (optional when
requiredis omitted, required when explicitly set totrue)
Tests Added
-
Importer tests in
openapi_tests.rs:importer_treats_path_parameters_as_required_when_required_field_omitted- verifies path params are requiredimporter_preserves_explicit_required_for_path_parameters- verifies explicitrequired: truestill worksimporter_preserves_optional_query_parameters_when_required_omitted- verifies query/header params remain optionalimporter_treats_mixed_path_and_query_parameters_correctly- verifies mixed parameter handling
-
Projection test in
projection_tests.rs:projection_treats_path_parameters_as_required_filters- verifies path parameters produce correct SQL exposure (Filter)
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue described that path parameters were imported as optional when
requiredis omitted. I confirmed this by analyzing the code - theimport_parametersfunction was using.unwrap_or(false)which defaults all parameters to optional whenrequiredis not specified.
- The issue described that path parameters were imported as optional when
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I changed the default behavior to
.unwrap_or(location == OpenApiParameterLocation::Path), which makes path parameters required by default. All new tests pass confirming the fix works correctly.
- I changed the default behavior to
-
I have thought about edge cases and made sure my fix handles them as well.
- Edge cases covered:
- Path parameters with explicit
required: true(still works) - Path parameters without
requiredfield (now required) - Query parameters without
required(still optional) - Query parameters with explicit
required: true(still required) - Header parameters without
required(still optional) - Mixed path and query parameters in the same operation
- Path parameters with explicit
- Edge cases covered:
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- All 224 tests in
coral-specpass. The two failing tests incoral-appare pre-existing failures unrelated to my changes (confirmed by testing without my changes).
- All 224 tests in
- Path parameters without explicit
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
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →