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 related to OpenAPI schema import and
additionalProperties. Let's first get an overview. - Assistant
Let me get a better understanding of the repository structure and find OpenAPI schema import related code.
- Assistant
No TypeScript files with "additionalProperties". Let me search more broadly.
- Assistant
Great! Found two relevant Rust files. Let me examine them. First, let's look at the OpenAPI schema import file.
- Assistant
Let me examine the schemas.rs file first since it's the most relevant one.
- Assistant
Let me check the IR types to understand the available type shapes:
- Assistant
Let me look at the IR model to see what IrTypeShape looks like.
- Assistant
Let me check the existing tests to understand the expected behavior:
- Assistant
Let me run the existing tests to see if they pass:
- Assistant
Let me run the tests again and capture the output:
- Assistant
Let me examine the PR discussion mentioned in the issue to understand the context better:
- Assistant
Now I understand the issue! Let me look at the specific problematic code section more carefully:
- Assistant
Let me continue reading the file.
- Assistant
Now I understand the issue. Let me first create a reproduction script to confirm the bug:
- Assistant
Let me also check what the
mcp/src/surface/tools.rsfile looks like, and then theimport.rsfile: - Assistant
Now I understand the issue. Looking at the
import_schemamethod inschemas.rs, around lines 102-114:} 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 clear: when
additionalProperties: false(a boolean), the code tries to treat it as a schema to import. In OpenAPI:additionalProperties: false→ closed object (no additional properties allowed)additionalProperties: true→ free-form map (any additional properties allowed)additionalProperties: {schema}→ map with value type matching the schema
Let me first write a reproduction test to confirm the bug:
- Assistant
Let me look at how the existing tests are structured:
- Assistant
Now I understand the issue completely. Let me trace through the logic:
- When
additionalProperties: false(boolean), the code at line 102 enters theelse if let Some(additional)branch - It tries to import
false(a boolean Value) as a schema - The
import_schemacall treatsfalseas a bare schema with no type, so it defaults to "object" and producesIrTypeShape::Json - The parent object then gets
IrTypeShape::Map { value_type_ref: "json" }— a free-form map — when it should be a closed object
The fix: check if
additionalPropertiesis a boolean first, and handle accordingly:false→ closed object (justIrTypeShape::Objectwith the existing properties, orIrTypeShape::Jsonif none)true→ free-form map- schema object → keep current behavior
Let me also check if there's an object with both
propertiesANDadditionalProperties: - When
- Assistant
Now let me write a reproduction script to confirm the bug:
- Assistant
Let me create a proper reproduction test to confirm the issue:
- Assistant
Let me look at the import module:
- Assistant
Now I understand the issue clearly. Let me trace the logic:
When
additionalProperties: false(boolean):- Line 102:
else if let Some(additional) = resolved.get("additionalProperties")→ enters this branch sincefalseis a value - Lines 103-111: calls
self.import_schema(additional, ...)whereadditional = false(a boolean Value) - The
import_schemaprocessesfalseas a schema:resolved = false(no $ref)- Type check:
false.get("type")returns None → falls tounwrap_or("object")→ treats as "object" - No properties → no additionalProperties → falls through to
IrTypeShape::Json
- Back in the caller:
value_type_ref= some JSON type id, and the whole object becomesIrTypeShape::Map
This is wrong:
additionalProperties: falseshould be a closed object (no additional properties allowed), not a free-form map.Similarly,
additionalProperties: trueshould be treated as a free-form map.Let me now fix the schema import logic:
- Line 102:
- Assistant
Now I understand the issue. Let me implement the fix. The problem is in the
else if let Some(additional)branch around line 102. WhenadditionalPropertiesis a booleanfalse, it should be treated as a closed object, not as a map. When it'strue, it should be a free-form map. When it's a schema object, the current behavior is correct.I also need to handle the case where an object has BOTH
propertiesANDadditionalProperties: false— the current code already handles this because it checks forpropertiesfirst (line 90). - Assistant
Now I'll implement the fix. The issue is at lines 102-114 in
schemas.rs. WhenadditionalPropertiesis a booleanfalse, it should be treated as a closed object (same as noadditionalProperties). When it'strue, it should be a free-form map. When it's a schema object, keep current behavior. - Assistant
Good! Now let me run the existing tests to make sure nothing is broken:
- Assistant
All existing tests pass. Now let me add a focused test for the
additionalProperties: falsebehavior. Let me find the end of the test file: - Assistant
Now let me add a test for
additionalProperties: false: - Assistant
Let me run the tests to see if my changes work:
- Assistant
The test has a lookup issue. Let me debug to see what operation IDs are produced:
- Assistant
The issue is that the operationId
closed/getbecomes normalized. Let me check the actual operation IDs by looking at what the import does with them: - Assistant
Let me add debug output to find the actual operation IDs:
- Assistant
Let me modify the test to add debug output temporarily:
- Assistant
I need to look at how operation IDs are actually handled. Looking at the test output, the operationId is "closed/get" with a slash. Let me check what normalize_identifier does to operationIds. Let me look at the operations.rs file.
- Assistant
I can see the issue. The operation IDs are normalized (e.g., "closed/get" becomes "closed_get"), and the type IDs include "_row" suffix. Let me fix my test:
- Assistant
Now let me remove the debug output and fix the test:
- Assistant
I see there's a duplicate. Let me fix the file:
- Assistant
Good. Now let me run the tests:
- Assistant
Let me run the second test too:
- Assistant
Let me run all openapi tests:
- Assistant
All 14 tests pass (12 existing + 2 new). Let me also run the full coral-spec test suite to ensure nothing else is broken:
- Assistant
All 221 tests pass. Let me verify the final state of my changes:
- Assistant
Let me also run the broader test suite to ensure nothing else is broken:
- Assistant
The 2 failing tests are in a different package (
coral-app) and are unrelated to our changes. Let me verify they were already failing before our changes: - Assistant
Good - these tests were already failing before my changes (pre-existing failures). Let me restore my changes:
- Assistant
Good - the failing tests are pre-existing and unrelated to our changes. Let me verify the final changes:
- Assistant
The changes look good. Let me also consider one edge case: what if there's an object with both
propertiesANDadditionalProperties: false? Looking at the code flow:- Line 90 checks for
propertiesfirst — this branch is taken - If properties exist, it creates an Object with those fields
- The
additionalProperties: falseis effectively ignored for this case
But wait - in OpenAPI, objects with only
propertiesare open by default (can have additional properties). OnlyadditionalProperties: falsemakes them closed. Let me check if we need to handle that case too. Let me look at the existing behavior for objects with properties: - Line 90 checks for
- Assistant
Good - the code already handles the
properties+additionalProperties: falsecase correctly by prioritizing properties. My test covers all the key cases:additionalProperties: falsewith no properties → Json (closed object)additionalProperties: falsewith properties → Object (already handled by existing code)additionalProperties: true→ Map with json value (free-form map)additionalProperties: {schema}→ Map with typed value (existing behavior preserved)
Let me run the final comprehensive test:
- Assistant
All 221 tests pass. Let me now complete the checklist:
CHECKLIST
-
✅ If an error was reported in the issue description, I have successfully reproduced it.
- I traced through the code in
schemas.rslines 102-111 and confirmed thatadditionalProperties: false(a boolean) was incorrectly being passed toimport_schema(), which treated it as a schema object and producedIrTypeShape::Map(a free-form map) instead of a closed object.
- I traced through the code in
-
✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- My fix adds three-way handling for
additionalProperties:false(boolean) →IrTypeShape::Json(closed object, same as no additionalProperties)true(boolean) →IrTypeShape::Map { value_type_ref: "json" }(free-form map)- schema object →
IrTypeShape::Map { value_type_ref: ... }(typed map, preserved existing behavior)
- Both new tests confirm the correct behavior.
- My fix adds three-way handling for
-
✅ I have thought about edge cases and made sure my fix handles them as well.
additionalProperties: falsewith no properties → Json (closed object)additionalProperties: falsewith properties → Object (already handled by existing code that checks properties first)additionalProperties: true→ Map with Json value type (free-form map)additionalProperties: {schema}→ Map with schema value type (existing behavior preserved)- allOf objects (don't need additionalProperties handling in current code)
-
✅ I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- All 221 tests in coral-spec package pass, including the 12 existing openapi_tests and the 2 new tests I added.
- The 2 failing tests in coral-app are pre-existing failures unrelated to my changes (verified by running them on the original code).
Now I'll submit the changes:
-
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 →
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 →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →