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.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /coral, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files for the OpenAPI schema import functionality.
Assistant
Now I can see the issue! Let me look at the relevant section more closely. The problem is in the
import_schemamethod around line 85-95. When the type is "object", the code checks forpropertiesfirst, then falls through to checkadditionalProperties. However, whenadditionalProperties: falseis present, it's still treated as a truthy value and imported as a Map type.Let me search for any related tests:
Assistant
Now let me check the
IrTypeShapeenum to understand the different type shapes:Assistant
Now let me create a test script to reproduce the issue. First, let me look at the current logic more carefully:
Assistant
Now I understand the issue clearly. The problem is on lines 102-111. The code checks:
} else if let Some(additional) = resolved.get("additionalProperties") {This treats the presence of
additionalPropertiesas map-like, regardless of its value. So whenadditionalProperties: falseis set (which means "closed object"), it's still being treated as a Map type.According to OpenAPI spec:
additionalProperties: falsemeans no additional properties are allowed (closed object)additionalProperties: trueoradditionalProperties: {schema}means it's a map/dictionary
Let me create a test script to reproduce the issue first:
Assistant
Let me run the existing tests first to see if they pass:
Assistant
Continuing to wait for the tests to run.
Assistant
Good, existing tests pass. Now let me add a test that demonstrates the bug with
additionalProperties: false:Assistant
Let me add a proper test to the existing test file to reproduce the issue:
Assistant
Now let's run the tests to confirm they fail (since the bug exists):
Assistant
Interesting - the first test passes. Let me check if the test is actually testing what we think it's testing. Let me trace through the code more carefully:
Assistant
Let me run the tests in a different way to see the actual behavior:
Assistant
Interesting! The second test fails because "stringmap type" is not found. Let me check what type ID is actually being generated. Let me modify the test to print all types:
Assistant
Let me add some debug output to the test to see what's happening:
Assistant
Let me add a debug test that prints all types:
Assistant
Interesting! So:
- When
additionalProperties: falseis present WITH properties, it correctly creates an Object (the current code path handles this because properties exist first) - When
additionalProperties: {type: string}is present WITHOUT properties, it correctly creates a Map
But wait, the issue is when
additionalProperties: falseis present WITHOUT properties! Let me test that case:- When
Assistant
I found the bug! When
additionalProperties: falseis present without anyproperties, the schema is incorrectly imported as aMapinstead of an emptyObjectorJson.The issue is in the code that checks for
additionalProperties- it only checks for the presence of the key, not its value. WhenadditionalProperties: false, it should be treated as a closed object (empty object shape), not a map.Let me fix the code:
Assistant
Now I understand the code. The fix needs to be in the section handling "object" type (lines 89-114). The issue is at line 102 where it checks
if let Some(additional) = resolved.get("additionalProperties")- this treats any presence ofadditionalPropertiesas map-like, regardless of its value.The fix should:
- Check if
additionalPropertiesisfalse→ treat as closed object (empty Object with no fields, or Json) - Check if
additionalPropertiesis a schema object → treat as Map - If
additionalPropertiesistrueor not present → fall through to default behavior
Let me look at what the appropriate behavior should be for
additionalProperties: false:- According to OpenAPI/JSON Schema spec,
additionalProperties: falsemeans no additional properties are allowed beyond what's defined inproperties - If there are no
propertiesdefined, it's an empty object
Looking at the code, when there are no properties and no additionalProperties, it falls through to
IrTypeShape::Json. ForadditionalProperties: false, I think it should also be an empty Object or Json. Let me check what makes more sense by looking at how other similar cases are handled.Actually, re-reading the acceptance criteria:
Handle boolean
additionalProperties: falseas a closed objectSo
additionalProperties: falseshould result in an Object (closed, with empty fields if no properties are defined).Let me make the fix:
- Check if
Assistant
Good, the fix looks correct. Now let me run the debug test again to confirm the fix works:
Assistant
The fix works. Now
additionalProperties: falseresults inObject { fields: [] }instead ofMap { value_type_ref: "..." }.Let me also verify the other debug test still works:
Assistant
Both cases work:
additionalProperties: {type: string}→ Map (still works)additionalProperties: falsewith properties → Object with fields (still works)
Now let me fix my actual test cases in the openapi_tests.rs file to have the correct type IDs and test the bug scenario properly:
Assistant
I see the issue - my second test case was looking for "stringmap" but the type ID would be "config_get_row" since it's coming from the operation response, not directly from the component schema. Let me update the tests to be more focused and correct. Let me first remove the debug test modules and update the actual test file:
Assistant
Now let me update the test file to have correct tests. First, let me remove the old tests and add proper ones:
Assistant
Let me view the whole test file to find where these tests end:
Assistant
Now let me add the proper test cases:
Assistant
Now let's run all the new tests to make sure they pass:
Assistant
Let me fix the type error - the issue is that
value_type_refis aString, not&str, so I need to dereference it:Assistant
Also there's a duplicated
#[test]attribute warning. Let me check the file:Assistant
I see - there's a duplicate
#[test]attribute. Let me fix it:Assistant
Good, now let me run the tests again:
Assistant
All 3 new tests pass. Now let me run all the openapi tests to make sure I didn't break anything:
Assistant
Excellent! All 15 tests pass (12 original + 3 new). Let me also run the broader test suite for coral-spec to make sure nothing else is broken:
Assistant
Let me also test what happens with
additionalProperties: trueto make sure that case is still handled correctly:Assistant
All tests pass. Let me also add a quick edge case test for
additionalProperties: trueto verify that falls through to Json behavior:Assistant
test result: ok. 222 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s
Assistant
I need to run the test command properly using the bash_terminal tool.
Assistant
Let me verify my changes one more time before submitting:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →