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 handling
additionalProperties: falsein v4 OpenAPI schema import. The schema importer treats the presence ofadditionalPropertiesas map-like, soadditionalProperties: falsecan be imported as a free-form map instead of a closed object.Let me explore the repository structure first to understand how it's organized and find the relevant code.
Assistant
The output shows very few Python files. Let me explore the repository structure more broadly.
Assistant
This is a Rust project. Let me explore the crates directory to find the relevant schema import code.
Assistant
Let me look at the PR #1149 mentioned in the issue and search for schema import code related to OpenAPI v4.
Assistant
Found it. Let me look at the coral-spec crate which seems to contain the schema import code.
Assistant
Let me look at the file that contains
additionalPropertieshandling:Assistant
Now I understand the issue. Let me look at the
IrTypeShapedefinition to understand all possible shapes:Assistant
Found the IrTypeShape definition. Let me look at it.
Assistant
Now I understand the issue. Let me look at the problematic code more carefully. In the
import_schemafunction, for the "object" type:- If
propertiesexists, it creates an Object with fields - Else if
additionalPropertiesexists, it creates a Map (WRONG - this includesadditionalProperties: false) - Else it creates Json
The problem is that when
additionalPropertiesisfalse, it should be treated as a closed object, not a Map. Let me look at the test files to understand the testing setup:- If
Assistant
Let me look at the existing tests for the OpenAPI import to understand how they work:
Assistant
Let me look at the existing tests to understand the testing setup.
Assistant
Good, I can see how tests are structured. Now let me check the v4/mod.rs to understand how tests are set up, and look at the v4/schema.rs file to see if there's any schema-level handling for additionalProperties:
Let me also look at the full openapi_tests.rs to see if there are more tests:
Assistant
Now let me look at the surfaces module to understand the structure:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /coral/crates/coral-spec/src/v4/surfaces/ </tool_call>
Assistant
Let me use bash_terminal correctly.
Assistant
Let me continue exploring the codebase to understand the issue and then implement a fix.
Assistant
Let me analyze the issue more carefully. Looking at the
schemas.rscode, I can see the problem:"object" => { if let Some(properties) = resolved.get("properties").and_then(Value::as_object) { // Creates Object with fields } else if let Some(additional) = resolved.get("additionalProperties") { // BUG: This treats additionalProperties: false as a Map IrTypeShape::Map { value_type_ref } } else { IrTypeShape::Json } }When an object has
additionalProperties: falsebut noproperties, it gets treated as a Map. It should be treated as a closed object.Let me first run the existing tests to confirm they pass:
Assistant
Good, all tests pass. Now let me create a test to reproduce the issue before fixing it.
Assistant
Let me create a proper test in the existing test file instead:
Assistant
Let me first write a test to reproduce the issue, then fix the code:
Assistant
Wait, I need to check the end of the file to make sure I didn't duplicate the closing brace.
Assistant
Let me check if there's already a closing brace at the end of the file before my additions.
Assistant
Let me check the file structure to make sure the tests I added are properly placed.
Assistant
Now let me run the tests to see if they compile and verify the issue:
Assistant
I need to fix the test - the BTreeMap uses String keys but I'm passing a reference to a String field. Let me fix it:
Assistant
The issue is that the test is using
types.get(&operation.output.type_ref)but the BTreeMap is keyed byStringand theoperation.output.type_refis already aString. I need to pass it directly without the&reference, or use.as_str()to get a&str.Let me look at how other tests handle this.
Assistant
The sed command had an issue with the address syntax. Let me use a different approach.
Assistant
I see - the test at line 228 uses
types.get("tree")with a string literal. The problem is that in my tests I'm using&operation.output.type_refwhich gives&String, but the map keys are&str. I need to use.as_str()instead.Assistant
Let me check the current state of the test file and fix the tests:
Assistant
The file has 804 lines. I need to fix the two tests I added to use
.as_str()instead of&. Let me view the tests and fix them.Assistant
The issue is clear: at lines 720 and 790, I'm using
&operation.output.type_refwhich returns&String, but the BTreeMap is keyed by&str. I need to useoperation.output.type_ref.as_str()instead to get&str.Let me fix these two lines in the test file.
Assistant
Now let me run the tests to confirm the issue exists:
Assistant
The tests confirm the issue:
additionalProperties: falseproducesMapinstead ofObjectwith empty fields- There's also an issue with schema-valued additionalProperties when both properties and additionalProperties exist
Let me understand the code better and fix the issue in
schemas.rs:Assistant
Let me view the schemas.rs file more carefully to understand the exact structure:
Assistant
Now I understand the issue clearly. The problem is in lines 102-111 of
schemas.rs:- When there are no
propertiesbutadditionalPropertiesis present, it creates a Map - But
additionalProperties: falseshould create a closed Object (not a Map)
Let me fix this:
- When there are no
Assistant
Now I understand the issue clearly. The fix needs to be in the "object" match arm (lines 89-114). Currently, it checks for
propertiesfirst, thenadditionalProperties, then falls back toJson. But it doesn't handle the case whereadditionalPropertiesis the booleanfalse.The fix should:
- If there are no
propertiesandadditionalPropertiesis the booleanfalse, create anObjectwith empty fields - If
additionalPropertiesis a schema (notfalse), create aMap - If neither, fall back to
Json
Let me implement the fix:
- If there are no
Assistant
Now I need to apply this fix to the actual file. Let me use the edit command to replace lines 88-114 in schemas.rs with the fixed version.
Looking at the file again:
- Line 88: starts the
matchstatement for the type - Line 89:
"object" => { - Lines 90-101: first branch handling
properties - Lines 102-111: second branch handling
additionalProperties(currently creates Map for any additionalProperties value) - Lines 112-114: else branch returning Json
- Line 115: closes the match arm for "object"
I need to replace lines 89-114 (the "object" match arm) with the new version.
Actually, let me look at the exact line numbers more carefully.
- Line 88: starts the
Assistant
I need to replace lines 89-114 with the fixed version. Let me do this carefully.
Assistant
Now let me construct the fixed file by combining the parts with the fix in between.
Assistant
Let me verify the fix was applied correctly.
Assistant
I see there's a duplicate closing brace on line 123. Let me fix that.
Assistant
The command was successful. Let me verify the fix is correct now by checking the file structure.
Assistant
The fix looks correct. Let me run the tests to verify:
Assistant
Let me run the tests with more verbose output to understand what's happening:
Assistant
The issue is that the test is looking for "StrictObject" type but it doesn't exist. Let me debug by checking what types are being created:
Assistant
Let me view the test file to understand the issue better.
Assistant
I see the issue. The test's schema includes
StrictObjectin components, but the operation's response has an inline schema. The components are never referenced, so they won't be in the types. Let me fix the test:Assistant
The test is looking for "StrictObject" type but it's never referenced from any operation, so it's never imported. I need to fix the tests to either reference the schemas or remove those checks. Let me update the tests:
Assistant
Let me fix the tests. The issue is that
StrictObjectis incomponentsbut never referenced, so it's never imported. I need to update the tests:Assistant
The original file has 804 lines, but I need to check what's happening. Let me check the end of the file.
Assistant
Let me rewrite both tests to be simpler and correct:
Assistant
Let me take a different approach. I'll rewrite the tests to be correct:
Assistant
Let me rewrite both tests to be correct. The key issue is that component schemas are only imported when they are referenced:
Assistant
Now let me assemble the new test file:
Assistant
Now let me run the tests:
Assistant
All three new tests pass. Now let me run all the tests in the coral-spec package to make sure I haven't broken anything:
Assistant
All 222 tests pass, including the 3 new tests. Let me also run the full test suite to make sure nothing else is broken:
Assistant
The test failure is unrelated to my changes - it's a flaky network test (
oauth_callback_accepts_real_callback_after_idle_preconnection) with an "Address already in use" error. Let me verify this is pre-existing by checking if the test was already flaky:Assistant
The flaky test failure is unrelated to my changes - it's an OAuth test that fails due to "Address already in use", which is a network port binding issue. Let me confirm my changes are correct by looking at the diff.
Assistant
The diff looks correct. Let me verify that my fix handles all edge cases properly by running the tests one more time:
Assistant
Let me verify the edge case of
additionalProperties: true(which should be a Map):Assistant
All tests pass. Let me verify the fix is complete by viewing the final state of the schemas.rs file:
Assistant
All tests pass. Let me provide a summary of the changes:
Summary
Issue
The schema importer treated the presence of
additionalPropertiesas map-like, soadditionalProperties: falsewas being imported as a free-form map instead of a closed object.Root Cause
In
crates/coral-spec/src/v4/surfaces/openapi/schemas.rs, when an object type had nopropertiesbut hadadditionalProperties, it would unconditionally create aMapshape. This was incorrect because:additionalProperties: falsemeans no additional properties are allowed → should be a closed Object
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.