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
Let me start by understanding the repository structure and the issue at hand. The issue is about handling
additionalProperties: falseduring v4 OpenAPI schema import. Currently, the schema importer treats the presence ofadditionalPropertiesas map-like, soadditionalProperties: falsegets imported as a free-form map instead of a closed object.Let me explore the repository to understand its structure and find the relevant code.
Assistant
This is a Rust project. Let me look for schema import related code.
Assistant
Now I can see the issue. Looking at lines 82-90:
} 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 } }When
additionalPropertiesis present, it always treats it as aMaptype, even whenadditionalProperties: false. WhenadditionalPropertiesisfalse, it should be treated as a closed object (orJson), not as a map.Let me look at the related tests and understand the codebase better.
Assistant
Now let me look at the existing tests to understand the test patterns:
Assistant
Let me scroll down to see the rest of the test file:
Assistant
Now I understand the issue. Let me look more closely at the problematic code in
schemas.rsand create a test to reproduce the issue first:Assistant
Good, the existing tests pass. Now let me write a reproduction script to confirm the bug:
Assistant
Let me add a test directly to the test file to confirm the bug:
Assistant
Interesting, the test passes. Let me understand better. When there are
propertiespresent ANDadditionalProperties: false, the code currently handles it by matchingpropertiesfirst. Let me look at the code more carefully:"object" => { if let Some(properties) = resolved.get("properties").and_then(Value::as_object) { // This branch handles objects with properties ... } else if let Some(additional) = resolved.get("additionalProperties") { // This branch is only reached when there are NO properties // but additionalProperties IS present ... IrTypeShape::Map { value_type_ref } } else { IrTypeShape::Json } }The issue is when an object type has
additionalProperties: falsebut noproperties. In that case, it would incorrectly go into theMapbranch instead of treating it as a closed object.Let me test that scenario:
Assistant
I've confirmed the bug. When
additionalProperties: falseis present (as a booleanfalse) without any properties, the importer incorrectly treats it as aMaptype withvalue_type_ref: emptyobject_value.Now let me also test what happens when
additionalPropertiesis a schema object (which should be treated as a Map):Assistant
Good. Now I understand the full picture:
- When
additionalPropertiesis a schema object (e.g.,additionalProperties: {type: string}): Should be treated asMaptype (currently works correctly) - When
additionalProperties: false: Should be treated as a closedObjectorJsontype (currently broken - incorrectly treated as Map) - When
additionalProperties: true(or omitted): Default behavior, can be treated asJsonorObjectdepending on context
Now let me revert the test additions I made and fix the actual code:
- When
Assistant
Now let me fix the code in
schemas.rs. The issue is in the handling ofadditionalPropertiesfor objects without explicit properties:Assistant
Edit the schemas.rs file to fix the additionalProperties handling. The fix should check if additionalProperties is
false(boolean false) and treat it as a closed object (empty Object or Json), rather than treating it as a Map.Assistant
Now I can see the exact code that needs to be fixed. The issue is at lines 82-90 (approximately). When
additionalPropertiesis present but the value isfalse, it should not create aMaptype. Let me fix it:Assistant
Now I need to edit lines 102-112 to check if
additionalPropertiesisfalse(boolean) and handle it appropriately. The fix should:- If
additionalPropertiesisfalse, treat as a closed object (empty Object or Json) - If
additionalPropertiesis a schema object, treat as Map (current behavior) - If
additionalPropertiesistrueor omitted, treat as Json (current behavior)
- If
Assistant
I see my sed command replaced each line with PLACEHOLDER_TO_REPLACE. Let me restore and do a proper edit:
Assistant
Let me now use the edit command properly. First let me see the exact lines:
Assistant
Now I'll replace the code block that handles
additionalProperties. The fix is to check ifadditionalPropertiesis booleanfalseand treat it as a closed object (Json), otherwise treat it as a Map:Assistant
The fix looks correct. Now let me run the tests to make sure the fix works:
Assistant
All existing tests pass. Now let me add the focused tests for the
additionalPropertiesbehavior as mentioned in the acceptance criteria. Let me add these tests to verify all edge cases:Assistant
Wait, I need to re-read the instructions. I was told NOT to add new tests. Let me revert the test file changes:
Assistant
Actually, wait - let me re-read the instructions. The acceptance criteria says "add focused schema import coverage." And the instructions say I shouldn't modify existing tests or add new tests to avoid errors in the evaluation system. But the acceptance criteria explicitly asks for "focused schema import coverage." Let me re-read the instructions:
If missing packages or some environment misconfiguration is preventing you from running the tests, you can install missing packages or fix the environment. However UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository.
Since the instructions are clear that I should NOT add new tests, I'll just verify my fix with a temporary test script and then remove it. Let me create a temporary test script:
Assistant
Let me create a temporary test to verify the fix works, then remove it:
Assistant
The
emptyclosedtype is not being found. Let me check what types are being imported:Assistant
The issue is that the schemas (EmptyClosed, ClosedWithProps, StringMap, OpenObject) are defined but only
Testis referenced in the operation. The importer only imports types that are reachable from operations. Let me fix the test to reference these schemas:Assistant
I see! The type IDs are based on the operation response, not the schema name. The types are:
empty_get_row-> Json (correct!)closed_get_row-> Object (correct!)map_get_row-> Map (correct!)open_get_row-> Map (correct!)
The fix is working. Let me update the test to use the correct type IDs:
Assistant
All tests pass. Now let me revert the test file and run all existing tests to make sure I haven't broken anything:
Assistant
All existing tests pass. Let me also run a broader test to make sure nothing else is broken:
Assistant
All 219 tests pass. Let me verify my changes one more time:
Assistant
Let me check the final state of the file to make sure everything looks correct:
<tool_call> <function=bash_terminal> <parameter=command> cat /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs </tool_call>
Assistant
I need to use the bash_terminal function to view the file contents.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.