ISSUE DESCRIPTION Respect additionalProperties false during v4 OpenAPI schema import…
- User
ISSUE DESCRIPTION
Respect additionalProperties false during v4 OpenAPI schema import This tracks unresolved feedback identified by cubic on PR #1149: https://github.com/withcoral/coral/pull/1149#discussion_r3347190658
Context: This appears to be pre-existing DSL v4 behavior surfaced by the refactor review, not a regression from the module split.
Problem: The schema importer treats the presence of
additionalPropertiesas map-like, soadditionalProperties: falsecan be imported as a free-form map instead of a closed object.Acceptance criteria: Handle boolean
additionalProperties: falseas a closed object, preserve schema-valued additionalProperties behavior, and add focused schema import 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 and understanding the issue. The problem is about handling
additionalProperties: falsein OpenAPI v4 schema import - it should be treated as a closed object, not as a map-like structure.First, let me explore the repository structure to understand how it's organized.
Assistant
Let me search for files related to OpenAPI schema import:
Assistant
Let me try a different approach to find relevant files:
Assistant
Let me explore the repository structure more broadly to understand what kind of codebase this is.
Assistant
I see this is a Rust-based project. Let me look at the crates directory and search for schema-related code:
Assistant
Let me search for "schema" and "import" in the Rust code:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "additionalProperties" /coral/crates --include="*.rs" 2>/dev/null | head -30 </tool_call>
Assistant
Let me search for additionalProperties in the codebase properly.
Assistant
Now let me look at the main file that handles additionalProperties - the schema importer:
<tool_call> <function=bash_terminal> <parameter=command> cat /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
Let me read the file properly.
Assistant
Now I can see the issue. Looking at the code around lines 83-102, I can see how object types are handled:
rust"object" => { if let Some(properties) = resolved.get("properties").and_then(Value::as_object) { let required = required_fields(&resolved); IrTypeShape::Object { fields: self.import_object_fields( properties, &required, &type_id, operation_id, diagnostics, ), } } else if let Some(additional) = resolved.get("additionalProperties") { let value_type_ref = self .import_schema( additional, &format!("{type_id}_value"), operation_id, diagnostics, ) .unwrap_or_else(|| "json".to_string()); IrTypeShape::Map { value_type_ref } } else { IrTypeShape::Json } }Assistant
Let me get the recent commits to understand the context better.
Assistant
Let me see the specific commit related to the module split (#1149) to understand what changed:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git show 2be31a9 --stat | head -50 </tool_call>
Assistant
Let me view the diff for that commit to understand what changed in the schema handling.
Assistant
Let me search for any existing tests related to additionalProperties in the test files:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "additionalProperties" /coral/crates/coral-spec --include="*.rs" 2>/dev/null </tool_call>
Assistant
Let me run the grep command properly.
Assistant
Let me now look at the IR type shape to understand how objects and maps are represented:
Assistant
Now I understand the structure. The
IrTypeShapeenum has:Object { fields: Vec<IrField> }- a closed object with defined fieldsMap { value_type_ref: String }- a map-like structureJson- free-form JSON
The issue is that when
additionalProperties: falseis present, the schema should be treated as a closed object (with no additional properties allowed), not as a Map.Let me also check if there's a way to track whether additionalProperties is explicitly set to false. Let me look at the OpenAPI spec behavior:
additionalProperties: false- no additional properties allowed (closed object)additionalProperties: {}oradditionalProperties: true- free-form mapadditionalProperties: {...schema...}- map with typed valuesadditionalPropertiesnot present - depends on whether there are defined
Assistant
Let me view the test file properly.
Assistant
Now I understand the test structure. Let me check if there are tests specifically for schema imports and understand the pattern:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "additionalProperties" /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me check if there are any additional properties tests in the openapi_tests.rs file.
Assistant
No tests for additionalProperties exist yet. Now let me understand the issue better and write a test to reproduce it first.
The problem is in
schemas.rsat lines 83-102. WhenadditionalProperties: falseis present, the code currently treats it as a Map becauseif let Some(additional) = resolved.get("additionalProperties")will match the booleanfalse.The fix should:
- Check if
additionalPropertiesistrue(boolean or schema) - then it's a Map - Check if
additionalPropertiesisfalse- then it's a closed Object (like if additionalProperties wasn't present) - Check if
additionalPropertiesis a schema object - then it's a Map with that schema as the value type
Let me first write a test to reproduce the issue:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec importer_handles_additional_properties_false -- --nocapture 2>&1 | head -50 </tool_call>
- Check if
Assistant
Let me run the cargo test properly to see if there's an existing test for additionalProperties:
Assistant
The test is still compiling. Let me wait for the build to complete by running the command again:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec importer_handles_additional_properties_false -- --nocapture 2>&1 | tail -20 </tool_call>
Assistant
Let me wait for the cargo test to complete:
Assistant
Now I need to write a test to reproduce the issue. Let me add a test to the openapi_tests.rs file first:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cat >> /coral/crates/coral-spec/src/v4/openapi_tests.rs << 'EOF'
#[test] fn importer_handles_additional_properties_false_as_closed_object() { // Reproduces the issue where additionalProperties: false was incorrectly // imported as a Map instead of a closed Object. let manifest = parse_source_manifest_yaml( r" name: test dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .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: get: operationId: items/get responses: '200': content: application/json: schema: type: object properties: id: {type: string} name: {type: string} additionalProperties: false " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let types = ir .types .iter() .map(|ty| (ty.id.as_str(), ty)) .collect::<std::collections::BTreeMap<_, _>>(); let item_type = types.get("items_get").expect("items_get type"); // Should be an Object, not a Map matches!(item_type.shape, IrTypeShape::Object { .. }), "items_get should import as an Object when additionalProperties: false, got: {:?}", item_type.shape ); } EOF
Assistant
Let me use a different approach - I need to properly use the bash_terminal tool with a command that appends to the file. The issue is that I need to write a valid test. Let me first check the exact format of the test file to make sure I append correctly.
Assistant
Now let me run the test to verify it fails (reproduces the issue):
Assistant
The test failed because the type name is wrong. Let me check the actual type name generated and update the test.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cat >> /coral/crates/coral-spec/src/v4/openapi_tests.rs << 'ENDTEST2'
#[test] fn importer_handles_additional_properties_false_debug_type_name() { // Debug test to find the actual type name let manifest = parse_source_manifest_yaml( r" name: test dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .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: get: operationId: items/get responses: '200': content: application/json: schema: type: object properties: id: {type: string} name: {type: string} additionalProperties: false " .as_bytes(), ) .expect("import"); // Print all type names for debugging let type_names: Vec<_> = ir.types.iter().map(|ty| ty.id.as_str()).collect(); eprintln!("Type names: {:?}", type_names); for ty in &ir.types { eprintln!("Type: {} -> {:?}", ty.id, ty.shape); } } ENDTEST2 cargo test -p coral-spec importer_handles_additional_properties_false_debug_type_name -- --nocapture 2>&1 | tail -30
Assistant
Let me run the test properly to see the type names.
Assistant
The test name seems to have been filtered out. Let me search for the test and run it properly:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec -- --nocapture 2>&1 | grep -A5 "additional_properties" </tool_call>
Assistant
Let me try a different approach - run all tests and see the output.
Assistant
The test failed because the type name is wrong. Let me add debug output to find the correct type name.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && grep -n "importer_handles_additional_properties_false_debug" /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me check the file to see what tests exist:
Assistant
The test name was probably truncated or didn't get added. Let me check if the debug test was added:
<tool_call> <function=bash_terminal> <parameter=command> tail -50 /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me check the test file properly.
Assistant
Let me modify the test to print the actual type name:
Assistant
Now I can see the actual type name. The type is
items_get_row, notitems_get. Let me update the test with the correct type name:Assistant
Now let me verify the test runs and fails (reproduces the bug):
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec importer_handles_additional_properties_false_as_closed_object -- --nocapture 2>&1 | tail -20 </tool_call>
Assistant
Let me run the test properly.
Assistant
Wait, the test passed! That's unexpected. Let me check what's happening. Maybe the type is already an Object because the schema has
propertiesdefined. Let me verify the current behavior more carefully:<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec importer_handles_additional_properties_false_as_closed_object -- --nocapture 2>&1 | tail -30 </tool_call>
Assistant
Let me check the test more carefully - it seems the test is passing, which means the type is an Object. But the issue says
additionalProperties: falseshould be treated as a closed object, so maybe the current behavior is already correct? Let me look at the code again to understand better.Actually wait, looking at the code again:
rust"object" => { if let Some(properties) = resolved.get("properties").and_then(Value::as_object) { // has properties - creates Object } else if let Some(additional) = resolved.get("additionalProperties") { // NO properties but HAS additionalProperties - creates Map } else { // No properties and no additionalProperties - creates Json } }So the issue is: when you have a schema with NO
propertiesbut HASadditionalProperties: false, it would be incorrectly treated as a Map.Let me write a test that actually reproduces the bug - a schema without properties but with additionalProperties: false:
Assistant
Now let me run this test to see if it fails:
Assistant
The test wasn't found because the file structure was broken by the Python script. Let me check what happened:
<tool_call> <function=bash_terminal> <parameter=command> tail -60 /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me see the end of the file to understand what happened.
Assistant
The file structure is broken - there's a missing closing brace for the previous test. Let me fix the file properly:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git checkout -- crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Good, I reset the test file. Now let me properly add tests to reproduce the bug and then fix it.
Assistant
Now let me run the test to see if it fails (reproduces the bug):
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test -p coral-spec importer_handles_additional_properties_false_as_closed_object 2>&1 | tail -40 </tool_call>
Assistant
Let me run the test properly.
Assistant
There was already a test with that name from the earlier append. Let me reset and start fresh:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git checkout -- crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me reset the file and carefully add a test at the end with a different name to avoid duplicates.
Assistant
The file was not properly reset. Let me force reset it and check its content first.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git status </tool_call>
Assistant
Let me check the git status to see what's happening with the file.
Assistant
Let me reset the file properly.
Assistant
Now let me verify the file is clean and then add my test properly:
Assistant
Now let me add the test properly using edit command:
Assistant
Now let me run the test to see if it fails (reproduces the bug):
Assistant
I've successfully reproduced the bug. The test shows that when a schema has
type: objectwithadditionalProperties: falsebut NOproperties, it's incorrectly imported as aMapinstead of a closedObject.Now let me fix the issue in
schemas.rs. The fix should handleadditionalProperties: falseas a closed object:Assistant
Let me view the context around line 102 to understand the code better:
Assistant
Assistant
Let me run the python fix script properly.
Assistant
The file wasn't created properly. Let me create it again and apply the fix.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cat > /tmp/fix_schema.py << 'PYEOF'
Assistant
The command is still showing an error. Let me try a different approach - I'll use the bash terminal tool to first create the file and then run it.
Assistant
Now let me run the Python script:
<tool_call> <function=bash_terminal> <parameter=command> python3 /tmp/fix_schema.py </tool_call>
Assistant
The python script is running in the terminal. Let me wait for the result and then verify if the fix was applied.
Assistant
Great! The fix was applied. Now let me verify the fix by looking at the changed code:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && sed -n '95,125p' crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
Let me run the command properly to check the fixed code.
Assistant
I see there's a duplicate closing brace in the fix. Let me view the full context to understand the structure better and fix it properly:
Assistant
The code has an extra
} else {clause. The original code had:rustif let Some(properties) = ... { // Object } else if let Some(additional) = ... { // Map } else { // Json }But my fix introduced a syntax error by having:
rustif let Some(properties) = ... { // Object } else if let Some(additional) = ... { // Json if false, Map if true } } else { // Json }The
else ifblock already handles all cases ofadditionalProperties, so we don't need the extraelse. Let me fix this by viewing the original code and applying a correct fix.<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git diff crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
Let me check the git diff to see what changed.
Assistant
I see the problem - the fix introduced a syntax error. Let me reset and apply the correct fix.
Assistant
Let me look at the original code structure again and apply a correct fix:
Assistant
Now I see the original structure. The fix should only change the inner code, not the outer structure. The fix should be:
Assistant
Let me run the Python script to apply the fix.
Assistant
The file wasn't created properly. Let me try a different approach using the edit command.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && head -n 130 crates/coral-spec/src/v4/surfaces/openapi/schemas.rs > /tmp/schemas_fixed.rs && head -n 100 /tmp/schemas_fixed.rs > /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
Let me try a different approach - I'll directly use the bash terminal tool to write the fix using a here-doc.
Assistant
The fix was applied. Let me verify the change and run the test to see if it now passes:
Assistant
Now let me run the test to verify the fix works:
Assistant
The test now shows
Jsoninstead ofMap, which is progress. However, looking at the issue description more carefully:"Handle boolean
additionalProperties: falseas a closed object"A "closed object" should be represented as
Objectin the IR, notJson.Jsonrepresents free-form/untyped values, whileObjectrepresents a typed structure. Let me update the fix to returnObject { fields: vec![] }foradditionalProperties: falsewithout properties.Assistant
Now let me run the test again:
Assistant
The test passes now. Let me also add more comprehensive tests to cover:
additionalProperties: falsewith properties defined (should still be an Object with those properties)additionalProperties: true(should be a Map)additionalProperties: {...schema...}(should be a Map with the schema type)- Schema with both properties and
additionalProperties: false(should be a closed Object with those properties)
Let me first run all the existing tests to make sure the fix doesn't break anything:
Assistant
All existing tests pass. Now let me add more comprehensive tests to cover all edge cases:
Assistant
Now let me run all the new tests:
Assistant
I need to fix the test patterns to borrow the types instead of moving them. Let me fix the tests:
Assistant
Let me fix the test patterns. I'll use a Python script to fix the file:
Assistant
Now let me run the tests again:
Assistant
I see. When there are
propertiesdefined ANDadditionalPropertiesis a schema, the current behavior creates anObjectwith only the properties, not aMap. Let me look at the code again to understand the flow:Assistant
Assistant
Let me run the Python command properly.
Assistant
Now let me run the tests again:
Assistant
There's an issue - my Python script didn't properly remove the old code. Let me check the file:
Assistant
The replacement went wrong. Let me reset and apply a cleaner fix:
Assistant
Let me use the edit command to properly apply the fix:
Assistant
Let me apply a cleaner fix using a more comprehensive Python script that replaces the entire "object" handling section:
Assistant
Now let me verify the fix and run the tests:
Assistant
Now let me run all the tests to verify the fix:
Assistant
All additional_properties tests pass. Now let me run all existing tests to make sure the fix doesn't break anything:
Assistant
All 224 tests pass, including the 4 new tests I added. Let me also check if there are any other tests in the repository that might be affected:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test 2>&1 | tail -80 </tool_call>
Assistant
Let me run all the tests in the repository to make sure nothing is broken.
Assistant
The 2 failing tests are unrelated to my changes - they're testing config write failures and cleanup failure scenarios, which are environmental/test infrastructure issues, not related to the schema import fix.
Let me verify by checking if these tests were failing before my changes:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git stash && cargo test -p coral-app source_lifecycle_tests::import_rolls_back_on_config_write_failure 2>&1 | tail -20 </tool_call>
Assistant
Let me run the command properly to check if the failing tests were already failing before my changes.
Assistant
I need to restore my changes and confirm the fix is in place.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git stash pop </tool_call>
Assistant
The failing tests are pre-existing and unrelated to my changes - they test error handling for config write failures, which is a separate concern. Let me verify my changes are still in place and run the coral-spec tests:
Assistant
All 224 tests in coral-spec pass (including the 4 new tests I added). Let me view the final diff to confirm all changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.