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 to understand its structure and locate the relevant code for OpenAPI schema import, particularly handling
additionalProperties. Let's first get an overview. - Assistant
Let me explore the repository structure more broadly to understand what kind of project this is.
- Assistant
This appears to be a Rust project. Let me explore the crate structure more.
- Assistant
Let me explore the crates directory more, focusing on the spec or API related crates.
- Assistant
Let me look at the schema import code, particularly the file that likely handles
additionalProperties: - Assistant
Now let me look at the IR types to understand the
IrTypeShapestructure: - Assistant
Let me look at the IR model to understand the shapes:
- Assistant
Let me look at the existing tests to understand the expected behavior:
- Assistant
Now let me look at the
import_schemamethod more closely, focusing on the object handling withadditionalProperties: - Assistant
Let me see the full context around the additionalProperties handling:
- Assistant
Now I understand the issue. The problem is in the
import_schemamethod. WhenadditionalPropertiesis present in the schema, it's currently being treated as a Map type regardless of its value. However:additionalProperties: falseshould mean it's a closed object (no additional properties allowed)additionalProperties: trueoradditionalProperties: <schema>should mean it's a Map type
Let me create a test script to reproduce the issue:
- Assistant
Let me search for existing tests related to additionalProperties:
- Assistant
Let me check the PR discussion link to understand the specific issue:
- Assistant
Let me scroll down to see the problematic code section:
- Assistant
Now I understand the problem clearly. The issue is on lines 102-111. When
additionalPropertiesis present in the schema, it's being treated as a Map type regardless of its value. However:additionalProperties: falseshould mean it's a closed object (no additional properties allowed)additionalProperties: trueshould mean it's an open object/mapadditionalProperties: <schema>should mean it's a map with the specified value type
Let me check if there are existing tests for this scenario:
- Assistant
Let me check the full test file for any map/object tests:
- Assistant
Let me check if there's a case where an object has both
propertiesandadditionalProperties: false: - Assistant
Now let me run the existing tests to understand the current behavior:
- Assistant
Let me wait for the tests to finish:
- Assistant
All tests pass. Now I understand the issue. The problem is in the
import_schemamethod around lines 102-111. WhenadditionalPropertiesis present (regardless of its value), it's being treated as a Map type. However, according to OpenAPI specification:additionalProperties: falsemeans it's a closed object (no additional properties allowed)additionalProperties: truemeans it's an open object (any additional properties allowed)additionalProperties: <schema>means it's a map with additional properties of the specified type
The current code doesn't distinguish between these cases. Let me look at the exact location in the code:
- Assistant
Now I understand the issue clearly. Let me trace through the logic:
-
Current behavior (lines 89-114):
- First checks if schema has
properties→ createsIrTypeShape::Objectwith those fields - Then checks if schema has
additionalProperties→ createsIrTypeShape::Mapwith the additionalProperties as the value type - Otherwise →
IrTypeShape::Json
- First checks if schema has
-
Problem: When
additionalProperties: falseis present:- In OpenAPI spec,
additionalProperties: falsemeans no additional properties are allowed - The current code treats ANY
additionalPropertiesas a map type - So
additionalProperties: falsegets imported as aMaptype withfalseas the schema (which would probably becomejsontype after import)
- In OpenAPI spec,
-
- Assistant
Now let me understand the exact fix needed. Looking at the code, the issue is in lines 102-111 where it checks for
additionalProperties. The fix should:- Check if
additionalPropertiesis a booleanfalse- if so, treat as closed object (empty object if no properties) - Check if
additionalPropertiesis a booleantrue- if so, treat as open object/map - Check if
additionalPropertiesis a schema object - if so, treat as map with specified value type
Let me implement the fix:
- Check if
- Assistant
Let me check the exact line numbers and use the correct edit command syntax:
- Assistant
Let me open the file and make the edit:
- Assistant
Now I can see the exact code I need to modify. The issue is on lines 102-111. I need to replace this section to handle the three cases:
additionalProperties: false→ closed object (empty object if no properties)additionalProperties: true→ open object/mapadditionalProperties: <schema>→ map with specified value type
Let me use the edit command to replace the problematic section:
- Assistant
Good, the edit was successful. Now let me run the tests to make sure my changes work correctly:
- Assistant
Good! All tests pass. Now I need to also handle the case where we have both
propertiesANDadditionalProperties: false. Let me check if the current code handles that correctly: - Assistant
Good! The code looks correct. Now I need to add tests to verify the behavior. Let me add tests to the test file:
- Assistant
Let me verify the fix is correct by looking at the full logic:
- Assistant
Let me run the tests to verify my fix works:
- Assistant
Let me run the tests again and see the full output:
- Assistant
I need to add the new tests to the existing test file. Let me add them:
- Assistant
Let me scroll down to the end of the file to see where to add the new tests:
- Assistant
Let me add the tests to the end of the test file:
- Assistant
Now let me run the tests to see if they pass:
- Assistant
Excellent! All my new tests pass. Let me run all the tests to make sure I didn't break anything:
- Assistant
All 223 tests pass, including my 4 new tests (we went from 219 to 223). Let me also check if there are any other places in the codebase that might need to handle the
additionalPropertiescase. Let me search for other files that might be affected: - Assistant
Good, the only place where
additionalPropertiesis handled in the schema import logic is in the file I already modified. Let me also check if there are any other test files or examples that might be affected by my changes: - Assistant
Let me check if there are any fixtures in the docs or sources directories:
- Assistant
Let me also check if there are any other tests in the crate that might be affected by my changes:
- Assistant
Let me also run tests for other crates that might be affected by the schema import changes:
- Assistant
Let me verify the changes are correct by looking at the modified code:
- Assistant
Perfect! The changes look correct. Let me verify the final checklist:
-
✅ If an error was reported in the issue description, I have successfully reproduced it.
- The issue reports that
additionalProperties: falseis imported as a free-form map instead of a closed object. I can see in the original code that anyadditionalPropertiesvalue is treated as a Map type.
- The issue reports that
-
✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I modified the code to check for
additionalProperties: falseand create an Object type instead of a Map type.
- I modified the code to check for
-
✅ I have thought about edge cases and made sure my fix handles them as well.
- I handle 4 cases:
additionalProperties: falsewith no properties → empty ObjectadditionalProperties: falsewith properties → Object with those properties (handled by existing code)additionalProperties: true→ Map with "json" value type
- I handle 4 cases:
-
- Assistant
Let me review the actual diff to make sure everything is correct:
- Assistant
Let me also check the test changes:
- Assistant
Let me run all tests one more time to ensure everything is working correctly:
- Assistant
All tests pass. Let me now review the checklist and make sure I've addressed all the requirements:
- ✅ Handle boolean
additionalProperties: falseas a closed object - Done - ✅ Preserve schema-valued additionalProperties behavior - Done (kept existing behavior for schema values)
- ✅ Add focused schema import coverage - Done (added4 new tests)
The changes are minimal and focused on the issue. I've also ensured that:
additionalProperties: falseis treated as a closed object (either empty or with properties)additionalProperties: trueis treated as an open object/mapadditionalProperties: <schema>is treated as a map with the specified value type
Let me run the tests one more time to make sure everything is working correctly:
- ✅ Handle boolean
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.