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.Interface
No new interfaces are introduced.
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 issue. The problem is about handling
additionalProperties: falseduring v4 OpenAPI schema import. The schema importer currently treats the presence ofadditionalPropertiesas map-like, soadditionalProperties: falsecan be imported as a free-form map instead of a closed object.Let me first explore the repository structure to understand the codebase.
Assistant
Let me look at the structure better.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /coral </tool_call>
Assistant
The user wants me to explore the repository structure. Let me use the bash_terminal command properly with a structured call.
Assistant
This is a Rust project. Let me explore the crates directory to find the OpenAPI schema import code.
Assistant
This is a Rust project. Let me search for OpenAPI schema import related code.
Assistant
I apologize for the confusion. Let me explore the coral-spec crate more carefully since the issue is about OpenAPI schema import.
Assistant
I apologize for the confusion. Let me explore the coral-spec crate to find the OpenAPI schema import code.
Assistant
The user wants me to resolve an issue about handling
additionalProperties: falseduring v4 OpenAPI schema import. Let me explore the relevant files in the coral-spec crate.I need to:
- Find the code that handles
additionalPropertiesin the OpenAPI schema import - Understand the current behavior
- Fix it to handle boolean
additionalProperties: falseas a closed object - Preserve schema-valued
additionalPropertiesbehavior - Add focused schema import coverage
Let me start by looking at the relevant files.
- Find the code that handles
Assistant
Let me search for where
additionalPropertiesis handled in the codebase.Assistant
Let me examine the schemas.rs file where
additionalPropertiesis handled:Assistant
Now I understand the issue. Let me look at the existing tests for the OpenAPI schema import to understand the current test coverage:
Assistant
Now I understand the issue. Let me look at the
additionalPropertieshandling inschemas.rsmore carefully:} 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 } } else { IrTypeShape::Json }The problem is that when
additionalPropertiesis present with valuefalse(boolean), it's being treated as a map-like shape because the code just checks for the presence ofadditionalPropertieswithout checking its value. WhenadditionalProperties: false, it should be a closed object (not a map).Let me look at the linked PR discussion to understand better:
additionalProperties: falseshould be a closed objectadditionalProperties: <schema>should remain as a map
Let me check the existing tests and then write a fix.
First, let me understand the flow better by looking at the schema.rs file and how is defined:
Assistant
Let me start by exploring the repository structure to understand how it's organized.
Assistant
Good. I can see the issue now. Looking at
/coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs, the problem is on lines 100-108:} 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 } } else { IrTypeShape::Json }The issue is that when
additionalProperties: false(boolean), the code treats it as a map-like type instead of a closed object. Let me first verify this by understanding the test structure better.Assistant
Let me wait for the test listing to complete and also look at the specific file that needs to be modified:
Assistant
Let me look at the specific code in schemas.rs that handles
additionalProperties:Assistant
Now I understand the issue. Let me look at the full schemas.rs file to understand the complete context:
Assistant
Assistant
Let me continue my investigation of the IrTypeShape definition:
Assistant
Assistant
I need to continue investigating the code structure to understand how to implement the fix. Let me look at the v4 module structure.
Assistant
Now I understand the structure. Let me implement the fix. First, let me modify
schemas.rsto handleadditionalProperties: falseas a closed object:Assistant
I need to use a different approach. Let me use sed to make the edit.
Assistant
Let me use the
editcommand properly to fix the issue:Assistant
Let me verify the changes were applied correctly:
Assistant
The indentation is slightly off for the
let value_type_refline. Let me fix that:Assistant
Let me verify the indentation is now correct:
Assistant
The indentation on line 109 still needs adjustment. Let me fix the indentation of the chained method calls:
Assistant
The indentation for lines 109-115 needs to be fixed. Let me correct it:
Assistant
Let me try to build the project to see if the code compiles correctly:
Assistant
The build succeeded. Now let me verify the complete fix and run the existing tests:
Assistant
The build succeeded. Now let me run the existing tests to make sure they pass:
Assistant
All existing tests pass. Now I need to add focused schema import coverage for
additionalProperties: falseas required by the acceptance criteria. Let me add tests to the openapi_tests.rs file.Assistant
Now let me add focused schema import coverage tests for
additionalProperties: false. I'll add tests at the end of the openapi_tests.rs file:Assistant
Now I need to add focused schema import coverage tests for
additionalProperties: false. Let me append tests to the openapi_tests.rs file:Assistant
Now let me run all the tests to verify the new tests pass and existing tests still pass:
Assistant
The test for schema-valued
additionalPropertiesfailed because the value type ref naming is different than expected. Let me fix the test to match the actual naming convention:Assistant
I need to fix the test. The value type ref naming follows a different convention. Let me look at how the value type ref is generated:
Assistant
Let me check how type IDs are derived:
Assistant
The test failed because the value type ref name is
"attributes_get_row_value"instead of"attributes_value". This is because the suggested_id includes the operation context. Let me fix the test to verify the correct behavior regardless of the specific naming:Assistant
Let me fix the failing test by updating the assertion to match the actual naming convention:
Assistant
Let me verify the change was made and run the tests again:
Assistant
The user wants me to continue with the task. Let me run the tests to verify the fix is working correctly.
Assistant
All 16 tests pass, including the 3 new tests for
additionalProperties: false. Let me also run the full test suite for the coral-spec package to ensure nothing is broken:Assistant
All 222 tests pass. Let me verify the final state of my changes:
Assistant
All changes are complete and verified. Let me provide a summary of what was done:
Summary of Changes
1. Fixed
additionalProperties: falsehandling inschemas.rsFile:
crates/coral-spec/src/v4/surfaces/openapi/schemas.rsProblem: The code treated the presence of
additionalPropertiesas map-like, soadditionalProperties: falsewas incorrectly imported asIrTypeShape::Mapinstead of a closed object.Fix: Added a check for
additional.as_bool() == Some(false)before creating a Map type. WhenadditionalPropertiesis explicitlyfalse(boolean), it now createsIrTypeShape::Object { fields: vec![] }(a closed empty object).2. Added focused schema import tests
File:
crates/coral-spec/src/v4/openapi_tests.rsAdded 3 new tests:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.