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.
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 to understand the codebase and locate the relevant files for the issue. Let's first get an overview.
- Assistant
Let me understand the repo structure better. This seems to be a monorepo. Let me look at the issue more closely. The issue is about OpenAPI schema import - specifically handling
additionalProperties: falsein v4 OpenAPI schema import. Let me search for relevant files. - Assistant
Great, I found the relevant Rust files. Let me examine the schemas.rs file first as it likely contains the logic for handling additionalProperties. Let me also look at the import.rs file to understand the import process.
- Assistant
Let me look at the schemas.rs file more closely to understand the issue.
- Assistant
Now I can see the issue! In the
import_schemamethod, around line 90-97, there's a check foradditionalProperties. The code currently does:} 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 that
additionalPropertiescan be:- A boolean (
trueorfalse) - in OpenAPI 3.0,additionalProperties: falsemeans the object cannot have any properties beyond those defined inproperties - A schema object - in this case, it defines the type for additional properties (map-like behavior)
When
additionalProperties: false, the current code will try to importfalseas a schema, which will likely fail and return "json". This makes it look like a free-form map instead of a closed object.The fix should:
- If
additionalPropertiesis a booleanfalse, treat the object as a closed object (no additional properties allowed) - this means we should NOT create a Map, but instead create an Object with only the explicitly defined properties - If
additionalPropertiesis a booleantrue, treat it as a free-form map (or Object with no defined properties) - If
additionalPropertiesis a schema object, treat it as a Map with the specified value type
Let me also check if there are any tests for this functionality.
- A boolean (
- Assistant
Let me check the openapi_tests.rs to see if there are existing tests for additionalProperties.
- Assistant
No matches. Let me check the test files.
- Assistant
Now I understand the issue. Let me also look at the IrTypeShape to understand the type definitions:
- Assistant
Let me look at the IrTypeShape enum to understand the available types.
- Assistant
Now I understand the issue. Let me look at the exact code that needs to be fixed:
- Assistant
Let me see more context:
- Assistant
Now I need to understand the issue. The current code at line 102-112 handles
additionalProperties:} 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: when
additionalProperties: false, it's a boolean value. The code treats it as a schema to import. Sincefalseis not a valid schema object with a type,import_schemawill likely returnNone(or create some weird Json type), and the object will be imported as aMapinstead of a closed object.According to OpenAPI spec:
additionalProperties: falsemeans no additional properties are allowed (closed object)additionalProperties: truemeans any additional properties are allowed (open/free-form object, which could be represented as a Map<string, any>)additionalProperties: {schema}means additional properties must conform to the schema (Map<string, schema>)
The fix should:
- Check if
additionalPropertiesis a boolean - If
false, treat as a closed object with no additional properties (same as having no additionalProperties) - If
true, treat as a free-form object/map (could useIrTypeShape::Mapwith json value type) - If it's a schema (object), keep the current behavior
Let me also check the test file for any existing tests related to additionalProperties.
Let me check the structure of the test file:
- Assistant
Now I understand the issue clearly. Let me look at the existing tests and understand the code flow better:
- Assistant
Good, all tests pass. Now let me write a reproducer script to understand the current behavior:
- Assistant
Now let me understand the current behavior with the problematic case. Let me write a quick test:
- Assistant
Now I understand the issue clearly. The problem is in the
import_schemafunction inschemas.rs:- When
additionalProperties: false(boolean), the code still enters theelse if let Some(additional)branch - It tries to pass
false(a boolean) toimport_schemaas if it were a schema object - This causes it to be imported as a Map instead of a closed object
The fix:
- Check if
additionalPropertiesis a boolean value - If
false: treat as a closed object (empty if no properties, same as ifadditionalPropertieswas absent) - If
true: treat as a free-form map (useIrTypeShape::Mapwith json value type) - If it's a schema object: keep current behavior (Map with that value type)
Also need to handle the case where
propertiesexists alongsideadditionalProperties: false(already handled since properties takes precedence).Let me now implement the fix:
- When
- Assistant
Now I need to fix the
else if let Some(additional)branch to check if the value is a boolean. WhenadditionalProperties: false, we should treat it as a closed object (IrTypeShape::Json with no map behavior). When it'strue, we could treat it as a free-form map. Let me make the fix: - Assistant
Now I understand the issue. The code at lines 102-114 treats
additionalPropertiesas a schema to import, but when it'sfalse(a boolean), it should be treated as a closed object (no additional properties allowed), not as a free-form map.Let me make the fix:
- Assistant
Let me open the file first.
- Assistant
Now let me scroll down to see the full section around additionalProperties:
- Assistant
Now I understand the issue clearly. Let me edit the file to fix the additionalProperties handling:
- Assistant
Good, the edit is applied. Now let me run the existing tests to make sure I didn't break anything:
- Assistant
All existing tests pass. Now I need to add focused tests for the
additionalProperties: falsebehavior. Let me look at the test file structure to understand how to add tests properly. - Assistant
Let me scroll to the end of the test file to add tests there.
- Assistant
Now I need to add tests at the end of the file. Let me add a test for the additionalProperties: false behavior. First, let me understand how to check what the imported type looks like. Let me check what types are used in existing tests to understand the pattern.
- Assistant
Now I'll add the tests. I need to add tests for:
additionalProperties: falsewithout properties → closed object (IrTypeShape::Object with empty fields)additionalProperties: falsewith properties → closed object with those propertiesadditionalProperties: true→ free-form map (IrTypeShape::Map)additionalProperties: {type: string}→ typed map (existing behavior, should still work)
Let me add the tests:
- Assistant
I see there's a duplicate line. Let me fix that:
- Assistant
I see there's still a duplicate line. Let me look at lines 664-668:
- Assistant
I see there are issues - a duplicate line and an extra closing brace. Let me fix:
- Assistant
Good, now let me run the tests to make sure they pass:
- Assistant
The tests are failing because the types are not being found by their expected IDs. Let me check how types are imported. The issue is likely with how type IDs are generated from
$refreferences. Let me check the type IDs that are actually generated. - Assistant
Let me check how type IDs are generated from
$refreferences: - Assistant
Let me check how the type ID is derived from the ref:
- Assistant
Let me check what
normalize_identifierdoes: - Assistant
Let me check the normalize_identifier function.
- Assistant
Now I understand!
normalize_identifierconverts to lowercase: "ClosedObject" becomes "closedobject", "SemiClosed" becomes "semi_closed", etc. Let me fix the tests: - Assistant
Let me use the
--fileoption correctly. - Assistant
I see the edit created a duplicate. Let me fix the file properly:
- Assistant
Good. Now let me fix the other tests that have similar issues with type IDs:
- Assistant
I see there's a duplicate
.expect("import");on line 762. Let me fix that and also fix the remaining type IDs: - Assistant
Good, the duplicate is fixed. Now I need to fix the third test to use the correct type ID. Let me check what
TypedMapwould normalize to: - Assistant
Now let me run the tests again:
- Assistant
The types aren't being found because the schema reference isn't being triggered. Let me add some debug output to understand what's happening:
- Assistant
Let me check how the existing tests reference schemas and look at the import flow:
- Assistant
Let me check how the import process works - specifically how
$refto component schemas are resolved: - Assistant
Let me look at how
resolve_refworks to understand how schemas are resolved: - Assistant
Let me understand the issue with the tests. The problem is that when using
$ref, the type_id is derived differently. Let me fix the tests to inline the schemas instead of using$ref: - Assistant
I see the test file is broken now - let me check lines 714-715:
- Assistant
I see the first test is missing a closing brace. Let me fix:
- Assistant
I see the assertion is malformed. Let me fix the first test properly:
- Assistant
Now I need to add the missing
#[test]attribute before the second test: - Assistant
Now I need to fix the second test similarly. Let me update it to use inline schemas too:
- Assistant
Good. Now let me fix the third test too. Let me see the remaining part:
- Assistant
The third test has the same issue with
$ref. Let me fix it to use inline schema: - Assistant
Good, now let me run the tests again:
- Assistant
All 15 tests pass! Now let me run the full test suite for the coral-spec crate to make sure nothing else is broken:
- Assistant
All 222 tests pass! Let me verify my changes one more time by looking at the final state of the schemas.rs file:
- Assistant
Perfect! Let me verify the final state of my changes:
- Assistant
Now let me check the diff to make sure everything looks good:
- Assistant
Perfect! All changes look good. Let me run the full test suite one more time to make sure everything is still passing:
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →