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 understanding the issue. The problem is about how the schema importer handles
additionalProperties: falsein OpenAPI v4 schemas. Currently, it treats the presence ofadditionalPropertiesas map-like, soadditionalProperties: falsecan be imported as a free-form map instead of a closed object.I need to:
- Explore the repository structure
- Find the relevant code for OpenAPI v4 schema import
- Understand the current behavior
- Fix the issue to handle boolean
additionalProperties: falseas a closed object - Preserve schema-valued additionalProperties behavior
- Add focused schema import coverage
Let me start by exploring the repository structure.
Assistant
This is a Rust project (Cargo.toml). Let me explore the crates directory to find the schema-related code.
Assistant
Let me search for files related to OpenAPI schema import.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "additionalProperties" /coral --include="*.rs" | head -30 </tool_call>
Assistant
Let me search for additionalProperties in the codebase.
Assistant
Good, I found the key file:
/coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs. Let me also search for "schema import" to understand the context better.<tool_call> <function=bash_terminal> <parameter=command> grep -r "schema import" /coral --include="*.rs" -l </tool_call>
Assistant
Let me search for schema import in a different way.
Assistant
Let me open the main import file and the schemas file to understand the issue better.
<tool_call> <function=bash_terminal> <parameter=command> cat /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
I need to use the bash_terminal tool correctly with proper JSON formatting.
Assistant
Now I can see the issue! Let me look at the code more carefully:
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 read the openapi_tests.rs file to understand what tests exist.
Assistant
Now I have a good understanding of the code. Let me look at the PR reference mentioned in the issue description to understand the exact feedback.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "additionalProperties" /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me search for additionalProperties tests more thoroughly.
Assistant
No additionalProperties tests exist. Now let me understand the structure better and create a fix. Let me look at the IrTypeShape enum to understand what shapes are available.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "IrTypeShape" /coral/crates/coral-spec/src/v4/ir/model.rs | head -30 </tool_call>
Assistant
Let me search for the IrTypeShape enum definition.
Assistant
Assistant
The patch approach is not available. Let me use the edit command to make the fix directly in the file. I need to identify the exact line numbers for the section I need to change.
Let me look at the code again to find the exact line numbers.
Assistant
Let me view the section around line 102 to understand the exact lines I need to modify.
Assistant
I need to modify the code from line 102 to line 112 (the
else if let Some(additional)block through theelse { IrTypeShape::Json }block).Let me use the edit command to make the fix. I need to replace lines 102-115 with the new logic.
Assistant
Now I need to use the edit command to replace lines 102-114 with the new code that handles
additionalProperties: falsecorrectly.Assistant
Now I need to replace lines 102-114 with the new code. Let me use the edit command to do this.
Assistant
The edit looks correct. Now let me verify the code compiles and run the existing tests to make sure I didn't break anything.
First, let me check if the code compiles:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo build --package coral-spec 2>&1 | head -50 </tool_call>
Assistant
I need to properly use the bash_terminal tool with JSON formatting.
Assistant
The code compiles successfully. Now let me run the existing tests for the coral-spec package to make sure I didn't break anything.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec 2>&1 | tail -100 </tool_call>
Assistant
Let me use the bash_terminal tool to run the tests.
Assistant
All 219 tests pass. Now I need to add test coverage for the specific case of
additionalProperties: false. Let me add a test to verify the fix.Assistant
Now let me run the tests to see if they pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec importer_handles_additional_properties 2>&1 </tool_call>
Assistant
I need to use the bash_terminal tool properly to run the tests.
Assistant
I see the issues:
- The
import_openapi_surfacefunction expects&[u8]but I'm passing&str - The
types.get()call has a type mismatch
Let me look at how the existing tests pass the OpenAPI document:
<tool_call> <function=bash_terminal> <parameter=command> grep -A 5 "import_openapi_surface" /coral/crates/coral-spec/src/v4/openapi_tests.rs | head -20 </tool_call>
- The
Assistant
I need to look at how the existing tests in the file pass the OpenAPI document to
import_openapi_surface. Let me check one of the existing test cases.Assistant
I need to see the actual content of the string being passed to
import_openapi_surface. Let me look at a specific test:<tool_call> <function=bash_terminal> <parameter=command> sed -n '45,70p' /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me view the actual content of a test case more carefully.
Assistant
Let me see how the string is passed to import_openapi_surface. The error message shows it expects
&[u8], so the existing tests must be using.as_bytes(). Let me verify this:<tool_call> <function=bash_terminal> <parameter=command> sed -n '67,72p' /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me search for the
.as_bytes()pattern in the tests.Assistant
I need to fix my test code. The existing tests use
.as_bytes()to convert the string to&[u8]. Let me remove the incorrect tests and add correct ones.Assistant
Let me remove the incorrect tests I added and add corrected versions. First, let me see what's at the end of the file:
Assistant
I need to remove the incorrect tests I added and add corrected versions that use
.as_bytes()and fix the type issues. Let me find the line where the original tests end and my tests begin:<tool_call> <function=bash_terminal> <parameter=command> grep -n "fn importer_warns_for_invalid_parameters" /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me search for where my test starts:
Assistant
Let me delete the tests I added and re-add them with proper fixes. I need to:
- Remove lines 669 onwards (the incorrect tests I added)
- Re-add them with correct
.as_bytes()calls and fix the type issues
Assistant
Now let me verify the file ends properly and add the corrected tests:
Assistant
Now let me add the correct tests with the proper
.as_bytes()and fix the type issues:Assistant
Now let me run the tests to see if they pass:
Assistant
I need to fix the pattern matching to borrow instead of move. Let me fix the test code:
Assistant
Now let me fix the other occurrence:
Assistant
Now let me run the tests again:
Assistant
Let me see what went wrong with the sed replacement:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '712,716p' /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
I need to properly use the bash_terminal tool with JSON formatting.
Assistant
The sed replacement went wrong and duplicated the pattern. Let me fix this by rewriting the tests properly. First, let me remove the broken tests and re-add them correctly.
Assistant
Let me run the tests again to check if they pass now:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec importer_handles_additional_properties 2>&1 </tool_call>
Assistant
Let me run the tests using the bash_terminal tool properly.
Assistant
The tests pass! But I notice there's a warning about a duplicated attribute. It seems there's a duplicate test. Let me check and clean up the file:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "fn importer_handles_additional_properties" /coral/crates/coral-spec/src/v4/openapi_tests.rs </tool_call>
Assistant
Let me search for duplicate tests using bash_terminal.
Assistant
The warning is about
#[test]being duplicated. Let me check what's around line 669-671:Assistant
I see the issue - there's a stray
#[test]attribute on line 668 from my previous edits. Let me remove it:Assistant
Now let me run all the tests again to make sure everything passes:
Assistant
All 222 tests pass now. Let me also run the specific new tests to ensure they work:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec importer_handles_additional 2>&1 </tool_call>
Assistant
Let me run the tests with the correct command using the bash_terminal tool.
Assistant
Let me also run the other tests:
Assistant
All three new tests pass. Let me verify the complete solution by looking at the changes I made:
Assistant
Now let me verify the fix is complete by looking at the schemas.rs file to ensure the changes are correct:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '89,130p' /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
I need to use the bash_terminal tool to view the file.
Assistant
The fix looks correct. Let me also run the full test suite to make sure I didn't break anything in other packages that depend on coral-spec.
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test 2>&1 | tail -100 </tool_call>
Assistant
I need to use the bash_terminal tool to run the tests.
Assistant
The 2 failing tests (
import_rolls_back_on_config_write_failureanddelete_restores_artifacts_on_cleanup_failure) are related to file system permission tests in the integration tests. They're not related to my changes in the OpenAPI schema import code. These tests are flaky and depend on the ability to create read-only files, which may not be working in the current environment.Let me run the coral-spec tests specifically to confirm my changes are correct:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec 2>&1 | grep -E "^(running|test result|ok|FAILED)" </tool_call>
Assistant
The output is too verbose. Let me use the bash_terminal tool properly to run the tests.
Assistant
All tests pass for the coral-spec package (222 tests). The two failing tests in coral-app are unrelated to my changes - they're file system permission tests for rollback behavior that don't work in the current environment.
Let me also verify there are no clippy warnings for the code I modified:
Assistant
The output seems incomplete. Let me check for clippy warnings more specifically on my changed file:
Assistant
No clippy warnings for the coral-spec package! Now let me also check that the code is properly formatted:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo fmt --package coral-spec -- --check 2>&1 </tool_call>
Assistant
Let me check if the code is formatted correctly.
Assistant
Let me format the code properly:
Assistant
No errors during formatting. Let me verify the tests still pass and then check the final diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && cargo test --package coral-spec 2>&1 | grep -E "(running|test result|FAILED)" </tool_call>
Assistant
I need to run the tests using the bash_terminal tool.
Assistant
All tests pass! Now let me see the final diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /coral && git diff --no-color </tool_call>
Assistant
I need to use the bash_terminal tool to see the final diff.
Assistant
The fix is complete. Let me provide a summary of what I did:
Summary of Changes
Problem
The schema importer in
coral-specwas treatingadditionalPropertiespresence as always map-like, soadditionalProperties: falsewas being incorrectly imported as a free-form map instead of a closed object.Solution
Modified
/coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rsto:- Check if
additionalPropertiesis explicitlyfalse(boolean) - If
additionalProperties: false, treat it as a closed object (IrTypeShape::Objectwith no fields) - If
additionalPropertiesis a schema object (ortrue), treat it as a map (IrTypeShape::Map) - If neither
propertiesnoradditionalPropertiesexist, use the open object (IrTypeShape::Json)
Test Coverage
- Check if
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.