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 locate the relevant files for the OpenAPI schema import issue.
Assistant
Let me search for files related to OpenAPI schema import, DSL v4, and additionalProperties.
Assistant
The command ran but didn't show output. Let me try a different approach.
Assistant
This is a Rust project (has Cargo.toml and crates directory). Let me search in Rust files instead.
Assistant
Great! Found the relevant files. Let me examine them to understand the issue.
Assistant
The user is telling me that I need to use terminal commands, not special commands like
open. Let me usecatto view the file instead.Assistant
Now I can see the issue! Let me also check the other file and understand the IrTypeShape enum better:
Assistant
Now let me look at the test file to understand the expected behavior better:
Assistant
Let me see the rest of this file and also look at the PR discussion to understand the issue better. Let me also look for any existing tests related to
additionalProperties:Assistant
No tests for additionalProperties. Now let me understand the issue better by looking at the problematic code section in
schemas.rs:Assistant
Now I can clearly see the problem! Looking at lines 94-104:
} 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 checks if
additionalPropertiesexists withget("additionalProperties"), but it doesn't distinguish between:additionalProperties: false(should be treated as a closed object with no extra fields)additionalProperties: true(free-form object)additionalProperties: { type: string }(map-like behavior, should use Map)
The issue is that
additionalProperties: falseis being treated the same as a schema-valued additionalProperties, resulting in aMaptype instead of a closedObjectorJsontype.Let me create a test script to reproduce the issue first:
Assistant
Now let me check what tests exist and run them:
Assistant
Let me wait for the build to complete:
Assistant
Good, all tests pass. Now let me run the v4 specific tests to see the openapi tests:
Assistant
Now let me create a test to reproduce the issue with
additionalProperties: false:Assistant
Let me look at the full openapi_tests.rs file to understand how to write a proper test:
Assistant
Now I understand the test pattern. Let me write a temporary test file to confirm the bug exists:
Assistant
Now let me add these tests to the actual test file temporarily to confirm the bug:
Assistant
Now let me run the new tests to confirm the bug:
Assistant
Interesting! The tests are failing because the types are not being found in the types map. Let me add some debugging to understand what's happening:
Assistant
Let me update the test to print more information:
Assistant
Let me check the test more carefully. The issue is that the type might not exist because when there's a
$ref, it might use a different naming. Let me first revert the test changes and add a simpler debug test:Assistant
Let me look at how other tests access types:
Assistant
Let me look at a simpler test case that checks types and how they are named:
Assistant
Interesting! So the type is named
items_get_row, notclosedobject. The import process uses the operation ID and context to generate type names. I can see from the output that it IS treating it as an Object already (not a Map), which is good. But wait, the issue is that when there are NO properties and onlyadditionalProperties: false, it would still be treated incorrectly. Let me test that case:Assistant
Let me look at the code more carefully to understand when the bug occurs:
Assistant
Now I understand! The bug occurs when an object type has ONLY
additionalProperties: falsewithout anyproperties. Let me create a test for that case:Assistant
Let me fix the test by using
.as_str()properly:Assistant
I've confirmed the bug. The test output clearly shows:
additionalProperties: falseis being treated as aMapwith value_typeJson, which is WRONGadditionalProperties: { type: string }is being treated as aMap, which is CORRECT
Now I need to fix the code in
schemas.rs. The fix should:- When
additionalProperties: false, treat it as a closed object (or Json if no properties) - When
additionalPropertiesis a schema object, treat it as a Map - When
additionalProperties: true, treat it as Json (free-form)
Let me look at the code section that needs to be fixed:
Assistant
Now I'll fix the code. The issue is in the
else if let Some(additional) = resolved.get("additionalProperties")branch. I need to check ifadditionalPropertiesisfalse(boolean) or an object/schema before treating it as a Map:Assistant
Let me verify the changes:
Assistant
The fix looks good. Now let me run the tests to see if it works:
Assistant
Excellent! Both tests pass now. Let me also add a test case for when there are properties AND
additionalProperties: false:Assistant
All three tests pass. Now let me run all the v4 tests to make sure I haven't broken anything:
Assistant
All 26 tests pass. Now let me run all coral-spec tests to make sure nothing is broken:
Assistant
All 222 tests pass. Now let me think about edge cases:
additionalProperties: falsewithout properties - ✅ Handled (treats as Json)additionalProperties: falsewith properties - ✅ Handled (treats as Object, because properties check comes first)additionalProperties: true- Need to check this caseadditionalProperties: { schema }- ✅ Handled (treats as Map)additionalPropertiesnot present - ✅ Handled (existing behavior, falls through to Json)
Let me add a test for
additionalProperties: true:Assistant
Good,
additionalProperties: trueis also handled correctly (treated as Map with Json value type). Now let me run all tests again to make sure everything works:Assistant
All 223 tests pass. Now let me also check if there are any other tests in the repository that might be affected:
Assistant
The 2 failing tests are unrelated to my change - they're about config write failures and manifest cleanup in the coral-app package, not related to schema import. Let me verify these tests were already failing before my change:
Assistant
Let me continue by restoring my changes and verifying the fix is complete.
Assistant
Good, my changes are restored. The failing tests were already failing before my change, so they're pre-existing issues unrelated to the fix. Let me verify my changes are correct by reviewing them:
Assistant
The fix looks good. Now let me also check the test changes:
Assistant
Let me run the final tests to confirm everything works correctly:
Assistant
All 27 v4 tests pass, including the 4 new tests I added. Let me now clean up the debug output from the tests and make them cleaner:
Assistant
Now let me add the tests without the debug output:
Assistant
Now let me run all the coral-spec tests one final time to confirm everything passes:
Assistant
All 223 tests pass. Let me verify the final state of my changes:
Assistant
Let me now provide a summary of the changes and verify that the checklist items are addressed.
Assistant
Let me submit my changes since I've completed the fix and verified all tests pass.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.