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 additionalProperties as map-like, so additionalProperties: false can be imported as a free-form map instead of a closed object.
Acceptance criteria:
Handle boolean additionalProperties: false as 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 using git reset --hard command.
Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later.
Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands.
However you don't need to use git add or git commit before submitting your changes. In fact,
submit only submits currently unstaged changes because it uses git diff to 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: false correctly during v4 OpenAPI schema import. When additionalProperties is set to false, it should be treated as a closed object, not a free-form map.
Let me first explore the repository structure.
Assistant
The repository seems to not have many Python files. Let me check what kind of project this is.
<tool_call>
<function=bash_terminal>
<parameter=command>
ls -la /coral
</tool_call>
Assistant
The user wants me to list every bullet from the checklist and write my reasoning for why I think I did it or didn't need to. But first, I need to actually do the work - explore the repository, understand the issue, and implement the fix.
Let me start by exploring the repository structure to understand what we're working with.
Assistant
This is a Rust project. Let me explore the crates directory to understand the project structure.
Assistant
Let me explore the crates to find where schema importing is handled.
Assistant
Let me explore the schema import code to understand how additionalProperties is currently handled.
Assistant
Now I understand the issue. Let me explore the IrTypeShape enum to understand all possible shapes.
Assistant
Let me look at the IrTypeShape definition to understand all possible shapes.
Assistant
Now I understand the structure. Let me also look at any existing tests for schema importing to understand the expected behavior.
Assistant
Let me explore the coral-spec crate to understand its structure better and find any existing tests.
Assistant
Let me look at the existing tests and the schema module.
Assistant
Assistant
The user wants me to run the existing tests to make sure they pass before making changes. Let me execute the cargo test command.
Assistant
Now I understand the issue. The problem is in the import_schema function in /coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rs. When a schema has additionalProperties: false but no properties, it's being treated as a Map instead of a closed Object.
The problematic code section is:
rust
} else if let Some(additional) = resolved.get("additionalProperties") {
let value_type_ref = self.import_schema(additional, ...)
.unwrap_or_else(|| "json".to_string());
IrTypeShape::Map { value_type_ref }
}
This catches additionalProperties: false (and additionalProperties: true) and treats both as Maps.
Let me first write a quick reproduction test to confirm the bug, then implement the fix.
Assistant
Let me verify the bug exists by looking more closely at the code and adding a test inline:
Assistant
Now let me look at the IrTypeShape enum to understand all the possible shapes, then implement the fix.
Assistant
Let me look at the context around line 102 to understand the code better.
Assistant
Now I understand the issue. The problem is that when additionalProperties is present with any value (including false), the code treats it as a Map. But additionalProperties: false should be treated as a closed Object, and additionalProperties: true should be treated as Json (untyped, since any properties are allowed).
Let me implement the fix:
Assistant
The user wants me to fix the issue where additionalProperties: false is being treated as a Map instead of a closed Object. Let me first open the file and see the current state, then make the proper edit.
Assistant
Let me look at the file content first to understand the exact lines:
Assistant
Let me use bash with sed to make the edit properly:
Assistant
Let me use bash with sed to make the edit properly:
Assistant
Let me verify the fix was applied correctly:
Assistant
The fix was applied correctly. Now let me run the existing tests to make sure they still pass:
Assistant
All existing tests pass. Now I need to add focused schema import coverage tests for additionalProperties. Let me look at the end of the test file to understand where to add new tests:
Assistant
Now I need to add focused schema import coverage tests for additionalProperties. Let me append tests to the existing test file:
Assistant
Let me run the new tests to verify they pass:
Assistant
One of the new tests is failing. Let me debug the issue - I need to check what the actual value_type_ref looks like:
Assistant
The user wants me to fix the failing test. The issue is that my test assertion value_type_ref.contains("string") is incorrect because the value_type_ref is a normalized type name like "metadatavalue" not the actual type name "string".
Let me fix the test to check the actual type shape of the referenced type instead.
Assistant
Let me check if the test file has the necessary imports:
Assistant
Now let me run the tests again:
Assistant
All 3 new tests pass. Now let me run the full test suite to make sure everything still works:
Assistant
All 222 tests pass (219 original + 3 new tests). Let me verify the changes I made by looking at the diff:
Assistant
The changes look correct. Let me also verify the test file changes:
Assistant
The user wants me to run the full test suite to make sure all tests pass before submitting. Let me run all the tests in the coral-spec crate.
Assistant
All 222 tests pass (219 original + 3 new tests). Let me provide the checklist summary and then submit.
Checklist
[Done]If an error was reported in the issue description, I have successfully reproduced it. - I analyzed the code and traced through the logic: when additionalProperties: false is present without any properties, the code falls through to the additionalProperties branch and calls import_schema() with false, which returns "json", resulting in IrTypeShape::Map { value_type_ref: "json" }. This confirms the bug.
[Done]If an error was reported in the issue description, I have confirmed that my fix resolves the error. - I implemented the fix by adding a check for before the general branch. The fix creates an empty shape when . I added tests to verify all three cases work correctly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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-$
Now I understand the issue better. Let me look at the core problem in the import_schema function. The key section is in the import_schema function where it handles additionalProperties. Let me look at the issue more carefully:
The issue is that when additionalProperties: false is present in an OpenAPI schema, it should be treated as a closed object (i.e., an object with only the defined properties, not allowing extra properties). But currently, the code treats the presence of additionalProperties as indicating a map-like structure.
Let me look at the relevant section of the code again:
rust
"object" => {
if let Some(properties) = resolved.get("properties").and_then(Value::as_object)
{
let required = required_fields(&resolved);
IrTypeShape::Object {
fields: self.import_object_fields(
properties,
&required,
&type_id,
operation_id,
diagnostics,
),
}
} 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:
If an object has properties, it's treated as an Object (correct)
If an object doesn't have properties but has additionalProperties, it's treated as a Map (this is wrong when additionalProperties: false)
If an object has neither, it's treated as Json
The fix should be:
When additionalProperties is false, the object should be treated as a closed object (either as Object { fields: [] } if no properties are defined, or as the properties are defined)
When additionalProperties is a schema object (not boolean false), then it should be treated as a Map
Wait, actually let me re-read the code more carefully. The issue is that if a schema has:
properties (with some fields) and additionalProperties: false, it would correctly import as an Object.
Only additionalProperties: false (no properties), it would fall through to the additionalProperties check and be treated as a Map.
But actually, even with properties and additionalProperties: false, the code doesn't respect additionalProperties: false. Let me look at the IrTypeShape::Object variant - it only has fields, no way to indicate whether additional properties are allowed.
Hmm, let me check what the IrTypeShape variants are again. Looking at the model.rs file:
So Object with fields: [] would be a closed object with no properties. And Map would be an open map.
The fix should be:
If additionalProperties is false, the object should be closed. If there are properties, import them as an Object. If there are no properties, import as an empty Object (not a Map).
If additionalProperties is a schema object, import as a Map with that schema as the value type.
Let me also check if there's a case where the object has properties but additionalProperties is explicitly set. In the current code, if an object has properties, it's always treated as IrTypeShape::Object, regardless of whether additionalProperties is true, false, or a schema. This seems like the current code doesn't distinguish between:
But looking at the IrTypeShape, there's no way to represent "map-like object" - there's only Object and Map. And Map seems to be for schemas that have no properties but do have additionalProperties.
So the fix should be:
When additionalProperties is false, ensure we don't treat the schema as a Map, even if there are no properties.
When additionalProperties is a schema object, treat it as a Map.
Let me think about the edge cases:
{ type: "object", additionalProperties: false } - This should be an empty Object (closed, no properties)
{ type: "object", properties: {...}, additionalProperties: false } - This should be an Object with the defined fields
{ type: "object", additionalProperties: {...} } - This should be a Map
{ type: "object", additionalProperties: true } - This is equivalent to the default, should probably be Json or Map depending on context
Actually, wait. Looking at the current code more carefully:
rust
"object" => {
if let Some(properties) = resolved.get("properties").and_then(Value::as_object)
{
// Has properties -> Object with fields
} else if let Some(additional) = resolved.get("additionalProperties") {
// No properties but has additionalProperties -> Map
} else {
// No properties and no additionalProperties -> Json
}
}
The fix should be:
If additionalProperties is boolean false, treat it as a closed object. If there are no properties, this means an empty Object.
If additionalProperties is a schema object, treat it as a Map.
But what if the object has properties AND additionalProperties: false? Currently it would be imported as an Object with fields, which is correct. The issue is only when there are NO properties.
Actually wait, let me re-read the issue description again:
"The schema importer treats the presence of additionalProperties as map-like, so additionalProperties: false can be imported as a free-form map instead of a closed object."
This suggests that additionalProperties: false is being imported as a Map. Let me check if there's a case where this happens...
If a schema is:
yaml
type: object
additionalProperties: false
It has no properties, so the first branch won't match. Then it checks for additionalProperties, and since it exists (even though it's false), it will import it as a Map with the value being additional (which is false in this case).
The fix should be to check if additionalProperties is the boolean false, and if so, treat it as a closed object (empty Object if no properties, or Object with the defined properties).
Let me also think about what additionalProperties: true means. In OpenAPI 3.0, additionalProperties: true is the default and means any additional properties are allowed. In OpenAPI 3.1, this is effectively the same as not having additionalProperties at all.
For the fix:
If additionalProperties is boolean false, the object is closed. If there are properties, import as Object with fields. If there are no properties, import as empty Object.
If additionalProperties is boolean true, the object allows any additional properties. If there are properties, this should probably be Json (since it's effectively untyped). If there are no properties, this should also be Json.
If additionalProperties is a schema object, the object is a Map with that schema as the value type.
Hmm, but actually, looking at the current code, when there are properties, it always imports as Object, regardless of additionalProperties. This might be intentional because the current model doesn't distinguish between "closed" and "open" objects.
But the issue is specifically about additionalProperties: false being imported as a Map when there are no properties. So let me focus on that case.
Actually, I want to double-check. Let me see if there are any tests that cover this behavior.
Let me search for any tests involving additionalProperties in the test files.
Actually, looking at the code again:
rust
"object" => {
if let Some(properties) = resolved.get("properties").and_then(Value::as_object)
{
let required = required_fields(&resolved);
IrTypeShape::Object {
fields: self.import_object_fields(
properties,
&required,
&type_id,
operation_id,
diagnostics,
),
}
} 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 in the else if let Some(additional) = resolved.get("additionalProperties") branch. When additionalProperties: false, resolved.get("additionalProperties") will return Some(Value::Bool(false)), and then self.import_schema(...) will be called with false as the schema.
Let me think about what import_schema does when given a Value::Bool:
rust
let shape = if let Some(all_of) = resolved.get("allOf").and_then(Value::as_array) {
// ...
} else if let Some(values) = resolved.get("enum").and_then(Value::as_array) {
// ...
} else {
match resolved
.get("type")
.and_then(Value::as_str)
.unwrap_or("object")
{
// ...
}
}
When given Value::Bool(false), it won't have allOf or enum, so it will fall through to the match. resolved.get("type") will return None (since Value::Bool doesn't have a type field), so it will use "object" as the default. Then it will check for properties, additionalProperties, etc., but Value::Bool doesn't have any of those, so it will return IrTypeShape::Json.
Wait, let me trace through more carefully. resolved.get("additionalProperties") on Value::Bool(false) will return None because you can't call .get() on a Value::Bool. So the import_schema(false, ...) call will have resolved as Value::Bool(false).
Then:
resolved.get("allOf") -> None (Value::Bool doesn't have this)
resolved.get("enum") -> None
resolved.get("type") -> None, so default to "object"
In the "object" branch:
resolved.get("properties") -> None
resolved.get("additionalProperties") -> None
Falls to IrTypeShape::Json
So the value_type_ref will be "json", and the result will be IrTypeShape::Map { value_type_ref: "json" }.
That's the bug! When additionalProperties: false, it's being imported as Map { value_type_ref: "json" }, which represents a free-form map.
The fix should be to check if additionalProperties is the boolean false, and if so, not treat the schema as a Map.
Let me implement the fix. The simplest approach is:
rust
"object" => {
if let Some(properties) = resolved.get("properties").and_then(Value::as_object)
{
let required = required_fields(&resolved);
IrTypeShape::Object {
fields: self.import_object_fields(
properties,
&required,
&type_id,
operation_id,
diagnostics,
),
}
} else if resolved.get("additionalProperties").and_then(Value::as_bool) == Some(false) {
// additionalProperties: false means a closed object with no additional properties
IrTypeShape::Object { fields: vec![] }
} 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
}
}
Wait, but I need to think about what happens with additionalProperties: true. In OpenAPI, additionalProperties: true means that additional properties of any type are allowed. This is different from additionalProperties: false (closed object) and additionalProperties: {...} (map with specific value type).
With additionalProperties: true and no properties, should this be Json or Map? I think Json makes more sense because it's not a map with typed values - it's just an untyped free-form object.
But wait, with additionalProperties: true and properties, should this be Object or Json? Currently it's Object, but since additional properties are allowed and typed as anything, Json might be more accurate. However, changing this would be a bigger change and might not be what the issue is asking for.
Let me focus on the specific issue: additionalProperties: false should not be treated as a Map.
For the fix, I need to:
Check if additionalProperties is boolean false BEFORE checking for additionalProperties in general
If it's false, treat the object as a closed object (empty Object if no properties)
If it's a schema object, treat it as a Map
For additionalProperties: true, I'll keep the current behavior (Json) since it's effectively untyped.
Actually, let me reconsider. The current code flow for additionalProperties: false:
Check for properties -> None (no properties defined)
Check for additionalProperties -> Some(Value::Bool(false))
Call import_schema(Value::Bool(false), ...) -> returns "json" (as I traced above)
Result: Map { value_type_ref: "json" }
The fix should intercept the additionalProperties: false case before step 2.
Let me also check if there's a case where additionalProperties: false is combined with properties. In the current code:
Check for properties -> Some(...)
Import fields
Result: Object { fields: [...] }
This is correct - the additionalProperties: false is not checked, but the result is still an Object. So the only issue is when there are no properties but additionalProperties: false.
Now let me also think about the test coverage. The issue says to "add focused schema import coverage". I should add a test that verifies:
additionalProperties: false with no properties is imported as an empty Object (not a Map)
additionalProperties: true with no properties is imported as Json (or Map, depending on what makes sense)
additionalProperties: {...} with no properties is imported as a Map
Actually, let me also check what additionalProperties: true does with the current code:
Check for properties -> None
Check for additionalProperties -> Some(Value::Bool(true))
Call import_schema(Value::Bool(true), ...) -> returns "json" (same as false)
Result: Map { value_type_ref: "json" }
So additionalProperties: true is also being treated as a Map. Should this be changed? The issue description says:
"Handle boolean additionalProperties: false as a closed object"
It doesn't mention additionalProperties: true. But logically, additionalProperties: true means any additional properties are allowed, which is different from a Map. A Map has a specific value type, while additionalProperties: true means any value is allowed.
Hmm, but changing additionalProperties: true might be a bigger change. Let me focus on additionalProperties: false first.
Actually, re-reading the issue description: "preserve schema-valued additionalProperties behavior". This suggests that when additionalProperties is a schema object (not a boolean), it should continue to be treated as a Map. So the fix is specifically for the boolean cases.
For additionalProperties: true, I think the current behavior (treating it as Map with json value type) might actually be incorrect, but the issue doesn't ask me to fix this. Let me leave it as is for now.
Wait, actually, let me reconsider. The issue says:
"Handle boolean additionalProperties: false as a closed object"
This specifically says false, not true. So I'll only fix the false case.
But actually, thinking about it more, additionalProperties: true is essentially the default (any properties allowed), which is semantically similar to not having additionalProperties at all. So additionalProperties: true with no properties should probably be Json, not Map. But since the issue doesn't mention this, I'll focus on additionalProperties: false.
Actually, let me reconsider once more. The issue description says:
"Handle boolean additionalProperties: false as a closed object, preserve schema-valued additionalProperties behavior"
This suggests:
additionalProperties: false -> closed object (Object with fields, or empty Object)
additionalProperties: {...} (schema-valued) -> Map (preserve current behavior)
additionalProperties: true -> leave as is (current behavior: Map with json value)
Actually, wait. Let me re-read the current code one more time:
rust
} 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 }
}
This branch is hit when additionalProperties is any value (including false and true). The current behavior is to treat it as a Map with the value being whatever import_schema returns for that value.
For additionalProperties: false, import_schema(false) returns "json" (because Value::Bool doesn't have any OpenAPI-specific fields, so it falls through to IrTypeShape::Json).
additionalProperties: true -> leave as is (Map { value_type_ref: "json" }), since the issue doesn't mention it
additionalProperties: {...} -> leave as is (Map with schema value)
Hmm, but actually I'm second-guessing the additionalProperties: true case. Let me think about what the expected behavior should be.
In OpenAPI:
additionalProperties: false -> object with no additional properties (closed)
additionalProperties: true -> object with any additional properties (open, untyped)
additionalProperties: {...} -> object with additional properties matching the schema (typed map)
The current model has Object, Map, and Json shapes:
Object -> typed object with known fields
Map -> typed map with known value type
Json -> free-form JSON
So:
additionalProperties: false -> Object (closed, with fields if defined)
additionalProperties: true -> Json (open, untyped) or Map (current behavior)
additionalProperties: {...} -> Map
I think additionalProperties: true should be Json rather than Map, but the issue doesn't ask me to change this. Let me focus on additionalProperties: false.
OK wait, I just realized something. Let me re-read the issue description again:
"The schema importer treats the presence of additionalProperties as map-like, so additionalProperties: false can be imported as a free-form map instead of a closed object."
This says additionalProperties: false is being imported as a "free-form map". A free-form map would be Map { value_type_ref: "json" }. And that's exactly what's happening.
So the fix is clear:
When additionalProperties is boolean false, treat it as a closed object (Object, not Map)
When additionalProperties is a schema object, continue to treat it as a Map (preserve current behavior)
For additionalProperties: true, I'll also fix it to be Json instead of Map, since true means any additional properties are allowed (untyped), which is closer to Json than Map. But this is a bit of a judgment call.
Actually, you know what, let me just focus on the specific issue: additionalProperties: false should be treated as a closed object. I won't change additionalProperties: true unless the tests tell me to.
Let me implement the fix now.
The fix:
rust
"object" => {
if let Some(properties) = resolved.get("properties").and_then(Value::as_object)
{
let required = required_fields(&resolved);
IrTypeShape::Object {
fields: self.import_object_fields(
properties,
&required,
&type_id,
operation_id,
diagnostics,
),
}
} else if resolved.get("additionalProperties").and_then(Value::as_bool) == Some(false) {
// additionalProperties: false means a closed object with no additional properties
IrTypeShape::Object { fields: vec![] }
} 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
}
}
Wait, I need to double-check my understanding of the code flow. The issue is specifically about additionalProperties: false being imported as a Map when there are no properties. But what if there are properties and additionalProperties: false? In that case, the current code would import it as an Object (with fields), which is correct. The additionalProperties: false is just ignored in this case.
So the issue is only when there are no properties but additionalProperties: false. In this case, the code falls through to the additionalProperties branch and imports it as a Map.
My fix adds a check for additionalProperties: false before the additionalProperties branch, and if it's false, imports as an empty Object.
Let me also think about what happens if an object has properties and additionalProperties: false. In the current code:
resolved.get("properties") -> Some(...)
Import as Object with fields
additionalProperties: false is ignored
This is actually correct for the current model, since Object doesn't have a flag for whether additional properties are allowed. The issue is specifically about the case where there are no properties.
OK, I'm confident in my fix. Let me also write a test to verify it.
Actually, let me also check the v4 mod.rs file to understand how to run tests and what modules are available.
Let me first look at the file structure and understand how tests are organized, then make the fix and add tests.
Now let me look at the existing tests and the module structure to understand how to add tests.
Now let me look at the file more carefully to understand the structure and then write the fix.
OK let me now implement the fix and add tests. Let me first run the existing tests to make sure they pass.
OK, let me now:
Run existing tests to confirm they pass
Implement the fix
Add tests for the fix
Run tests again to confirm everything passes
Let me start by running the existing tests.
<tool_call>
<function=bash_terminal>
<parameter=command>
cd /coral && cargo test -p coral-spec --no-run 2>&1 | tail -30
</tool_call>
additionalProperties: false
additionalProperties
Object
additionalProperties: false
[Done]I have thought about edge cases and made sure my fix handles them as well. - I considered:
additionalProperties: false without properties → imports as empty Object (fixed)
additionalProperties: false with properties → imports as Object with those fields (already worked, documented in test)
additionalProperties as a schema object → imports as Map with typed values (preserved existing behavior)
additionalProperties: true → left unchanged (not part of issue scope)
[Done]I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. - All 222 tests in cargo test -p coral-spec pass.