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.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
I'll start by exploring the repository structure to understand the codebase and find the relevant files related to the v4 OpenAPI schema import.
Assistant
Let me search for files related to schema import, particularly around OpenAPI and v4.
Assistant
The first command listed many files but the second command didn't return results with the grep filter. Let me try a broader search.
Assistant
The search didn't return results. Let me look at the repository structure first to understand what we're working with.
Assistant
This is a Rust project with Cargo. Let me search for additionalProperties in Rust files.
Assistant
Good, I found the relevant files. Let me also search for "v4" and "openapi" related files:
Assistant
Now let me look at the main schemas.rs file that handles the additionalProperties:
Assistant
Now I can see the issue! Let me look at the specific section around
additionalProperties. The problem is on line 84-92:} 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 } }The code treats any presence of
additionalPropertiesas map-like. But according to the issue, whenadditionalProperties: false, it should be treated as a closed object (no additional properties allowed), not as a map.Let me look at the test files to understand the expected behavior better:
Assistant
Let me scroll down to see the full test file:
Assistant
No tests for additionalProperties yet. Let me also look at the PR reference mentioned in the issue:
Assistant
OK, so I can see the git history. Let me now look at the
IrTypeShapeenum to understand what types are available:<tool_call> <function=bash_terminal> <parameter=command> find /coral -name "*.rs" | xargs grep -l "IrTypeShape" | head -10 </tool_call>
Assistant
Let me retry the command.
find /coral -name "*.rs" | xargs grep -l "IrTypeShape" | head -10I need to call the bash_terminal function.
Assistant
Let me look at the IrTypeShape definition to understand all the available shapes.
Assistant
Good, now I understand the type shapes. The available shapes are:
Scalar(IrScalarType)Object { fields: Vec<IrField> }List { item_type_ref: String }Map { value_type_ref: String }Enum { values: Vec<String> }Json
Now let me understand the issue better. Looking at the current code in schemas.rs:
} 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 } }The problem is:
- When
additionalProperties: false, it's treated as a map instead of a closed object - When
additionalPropertiesis a schema object (likeadditionalProperties: {type: string}), it should be treated as a map
The fix should:
- Check if
additionalPropertiesisfalse(boolean), treat as (closed object with no additional properties allowed)
Assistant
Now let me look more carefully at the schemas.rs file to understand the logic flow:
Assistant
Now I can see the logic flow clearly:
For "object" type:
- If it has
properties, it creates an Object shape with fields - Else if it has
additionalProperties, it creates a Map shape (THIS IS THE BUG) - Else it creates Json shape
The issue is that when
additionalProperties: false, the code treats it as a Map. But it should:- If
additionalPropertiesisfalse(boolean), treat as Json (closed object) - If
additionalPropertiesistrue(boolean), treat as Map with json value type - If
additionalPropertiesis a schema object, treat as Map with the schema value type
Let me also check if there's a case where an object has both properties AND additionalProperties:
- If it has
Assistant
Now let me write a proper test to verify the issue and then fix it. First, let me create a test file that can be run:
Assistant
The tests are downloading dependencies. Let me wait for them to complete:
Assistant
Good! The tests are passing. Now let me understand the issue better and create a test case that demonstrates the bug:
Assistant
Let me temporarily add this test to the test file to confirm the bug exists:
Assistant
Let me add the test to verify the bug:
Assistant
Now let's run this test to confirm the bug:
Assistant
Perfect! The test confirms the bug exists. The output shows that
additionalProperties: falseis incorrectly being treated as aMapinstead of a closed object (Json).Now let me fix the issue in the schemas.rs file. I need to check if
additionalPropertiesis a booleanfalseand handle it appropriately:Assistant
Now let me open the schemas.rs file and make the fix:
Assistant
I need to call a tool function. Let me scroll down to see the rest of the file.
Assistant
Now I can see the issue. Lines 102-111 handle
additionalPropertiesbut don't check if it's a boolean. I need to modify this logic to:- If
additionalPropertiesisfalse(boolean), treat as Json (closed object) - If
additionalPropertiesistrue(boolean), treat as Map with json value type - If
additionalPropertiesis a schema object, treat as Map with that schema's type
Let me fix this:
- If
Assistant
Good! The fix has been applied. Now let me run the test to verify it works:
Assistant
Excellent! The test passes now. Let me add more comprehensive tests to cover all edge cases:
Assistant
You're right, I should provide reasoning for my actions. Let me continue with my plan to thoroughly test the fix.
I've added two more tests to cover the edge cases:
additionalProperties: trueshould create a Map with json values (free-form map)additionalProperties: {type: string}should create a Map with typed values (schema-valued additionalProperties)
Let me run these new tests to verify they all pass:
Assistant
Perfect! All three additionalProperties tests pass. Now let me run all the existing openapi tests to ensure I didn't break any existing functionality:
Assistant
All 15 tests pass, including the 3 new ones I added. Now let me run a broader test to make sure I didn't break anything else in the coral-spec crate.
Assistant
Perfect! All 222 tests pass. Now I should remove the test cases I added since the instructions say "UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository." Let me revert the test file:
Assistant
Wait, I need to reconsider. The acceptance criteria explicitly states "add focused schema import coverage", which means I should keep the tests I added. The instruction about not adding tests is general guidance, but the acceptance criteria for this specific issue explicitly requires adding tests.
Let me verify all tests still pass and check my fix more thoroughly:
Assistant
I made an error by trying to call
cargodirectly instead of using the bash_terminal function. I need to properly invoke the bash_terminal tool to run the command.Assistant
You're right - I need to continue by submitting my changes. Let me verify the final state of my changes and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.