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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
This is the Coral repository. Let me explore the crates directory to find the relevant code
Assistant
me check the test file structure and look for existing tests:
Assistant
me check the git log for recent changes to the openapi schema file:
Assistant
Let me look at the IrTypeShape definitions to understand the available shapes:
Assistant
me look at the existing test patterns and understand the import structure:
Assistant
look at the full openapi_tests.rs file to understand the test patterns:
Assistant
Now I understand the test patterns. Let me also look at the
mod.rsto see the imports:Assistant
Let me first understand the current behavior by writing a reproduction test:
Assistant
me run the existing tests to confirm the environment works:
Assistant
Let me create a temporary test to verify the bug exists:
Assistant
Now let me check what
Value::as_boolreturns for an Object:Assistant
Now let me look at the schemas.rs file once more and make the fix:
Assistant
Now let me make the fix to the schemas.rs:
Assistant
The edit replaced the wrong section. Let me check what happened and fix it:
Assistant
revert the change and try again properly:
Assistant
let me make the fix correctly using the
replacecommand:Assistant
run the temporary test to confirm the fix works:
Assistant
look at recent fixes to see the test pattern they use:
Assistant
Confirmed - the project does add focused tests as part of the fix. Let me look at the test pattern in the recent PR:
Assistant
Good. Now I understand the pattern - add focused tests to the
openapi_tests.rsfile. Let me remove the temporary test file and add proper tests:Now I understand the pattern. Let me remove the temporary test file and add proper tests toopenapi_tests.rs:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[rm crates/coral-spec/src/v4/_temp_additional_properties_tests.rs && git checkout crates/coral-spec/src/v4/mod.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
Let me run the command:
Assistant
Let me first run all existing tests to make sure my fix didn't break anything:
Assistant
219 tests pass. Let me also run tests in dependent crates to ensure nothing else broke:
Assistant
The integration test failures are unrelated (gRPC cleanup related). Let me verify these failures exist on the base branch:
Assistant
The failures are pre-existing and unrelated to my changes. Let me restore my changes:
Assistant
Now let me add focused tests to the
openapi_tests.rsfile. I'll add tests that cover:additionalProperties: falsealone (no properties) → closed ObjectadditionalProperties: falsewith properties → closed Object with fieldsadditionalProperties: <schema>(no properties) → typed MapadditionalProperties: true(no properties) → free-form Map- No
additionalPropertiesand no properties → Json (preserve existing behavior)
Let me look at the end of the file to find a good place to add the tests:Now let me add focused tests to the
openapi_tests.rsfile:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[tail -20 crates/coral-spec/src/v4/openapi_tests.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
I need to use the correct tool call format. Let me use
bash_terminal:Assistant
Now I'll add the focused tests at the end of the file. Let me append them:Now I'll add focused tests at the end of the file:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat >> crates/coral-spec/src/v4/openapi_tests.rs << 'EOF'
#[test] fn importer_imports_additional_properties_false_alone_as_closed_object() { let manifest = parse_source_manifest_yaml( r" name: additional_properties_closed dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface"); let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /closed: get: operationId: closed/get responses: '200': content: application/json: schema: type: object additionalProperties: false " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("row type"); let IrTypeShape::Object { fields } = &ty.shape else { panic!( "additionalProperties: false should import as a closed object, got {:?}", ty.shape ); }; assert!( fields.is_empty(), "closed object should have no fields when properties are absent, got {fields:?}" ); assert!( !ir.types .iter() .any(|ty| ty.id == format!("{}_value", ty.id.replace("row", ""))), "no synthetic map value type should be created for additionalProperties: false" ); }
#[test] fn importer_preserves_properties_when_additional_properties_false() { let manifest = parse_source_manifest_yaml( r" name: additional_properties_closed_with_props dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface"); let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /items: get: operationId: items/get responses: '200': content: application/json: schema: type: object additionalProperties: false properties: id: {type: string} name: {type: string} " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("row type"); let IrTypeShape::Object { fields } = &ty.shape else { panic!( "additionalProperties: false with properties should import as a closed object, got {:?}", ty.shape ); }; let names: BTreeMap<&str, &IrField> = fields .iter() .map(|field| (field.name.as_str(), field)) .collect(); assert_eq!(names.len(), 2); assert!(names.contains_key("id")); assert!(names.contains_key("name")); }
#[test] fn importer_preserves_schema_valued_additional_properties_as_typed_map() { let manifest = parse_source_manifest_yaml( r" name: additional_properties_typed_map dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface"); let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /labels: get: operationId: labels/get responses: '200': content: application/json: schema: type: object additionalProperties: type: string " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("row type"); let IrTypeShape::Map { value_type_ref } = &ty.shape else { panic!( "schema-valued additionalProperties should import as a typed map, got {:?}", ty.shape ); }; let value_type = ir .types .iter() .find(|ty| ty.id == *value_type_ref) .expect("value type"); assert!(matches!( value_type.shape, IrTypeShape::Scalar(IrScalarType::String) )); }
#[test] fn importer_treats_additional_properties_true_as_free_form_map() { let manifest = parse_source_manifest_yaml( r" name: additional_properties_true dsl_version: 4 surfaces:
- id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface"); let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /bag: get: operationId: bag/get responses: '200': content: application/json: schema: type: object additionalProperties: true " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("row type"); assert!( matches!(ty.shape, IrTypeShape::Map { .. }), "additionalProperties: true should remain a map, got {:?}", ty.shape ); } EOF echo "Tests appended"]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me try again with proper formatting
Assistant
Now let me run the new tests:
Assistant
All 4 new tests pass! Let me also run all tests to make sure I haven't broken anything else:All 4 new tests pass. Let me also run all the other tests to make sure nothing is broken:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cargo test -p coral-spec 2>&1 | tail -15]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Need to use proper tool call format.
Assistant
All 223 tests pass (219 original + 4 new). Let me also run clippy to make sure the code is clean:All 223 tests pass (219 original + 4 new). Let me also run clippy to ensure code is clean:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cargo clippy -p coral-spec --all-targets -- -D warnings 2>&1 | tail -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Clippy passes too. Let me also run rustfmt to ensure formatting is correct:
Assistant
me fix the formatting:
Assistant
let me verify the final state of the file:
Assistant
The fix is in place. Let me also run all tests once more to verify everything still works:Let me run all tests once more to verify everything still works:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cargo test -p coral-spec 2>&1 | grep -E "test result|^running|^test " | tail -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All 223 tests pass. Let me check the git status to confirm what changes will be submitted:Let me check the git status to confirm what changes will be submitted:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git status && echo "===" && git diff --stat]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me try again with the proper tool call:
Assistant
Now let me also check the new tests:Let me also look at the final test additions:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git diff crates/coral-spec/src/v4/openapi_tests.rs | head -50]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The diffs look correct. Let me also verify the schema fix once more, then think about edge cases and verify the temporary test file is removed:Let me verify the temporary test file is removed and the mod.rs is back to original:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[ls crates/coral-spec/src/v4/ | grep -i temp]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Need to retry with proper tool call:
Assistant
Temporary file is removed. Let me also verify the mod.rs is back to original:
Assistant
The mod.rs is back to original. Let me also think about edge cases:
additionalProperties: falsealone (without properties) - tested ✓additionalProperties: falsewith properties - tested ✓additionalProperties: true- tested ✓additionalProperties: <schema>- tested ✓- No
additionalPropertiesand no properties - existing behavior (Json) ✓
Let me also think about:
- What about
additionalProperties: null? In OpenAPI, this is undefined behavior. The currentas_bool() == Some(false)check would returnfalse(sinceas_bool()returnsNonefor null), and the schema would be treated as a Map. This is consistent with how the original code handled it - the value would be passed toimport_schemawhich would create a type for it. - What about a typed map with
additionalPropertiescontaining an enum or complex schema? This is already handled by the recursiveimport_schemacall.
Let me also check whether
as_bool()handlesnullcorrectly. Looking at serde_json's docs:Value::as_boolreturnsSome(b)ifValue::Bool(b), elseNone
So for
null, it returnsNone, which means ourSome(false)check fails, and we fall into theelsebranch. The null value gets passed toimport_schema, which will likely create a Json type or empty type. This is the same as the original behavior, so it's fine.What about an explicit
additionalProperties: falsewithnullable: true? Thenullablefield is processed earlier in the schema import, so it should still work correctly.Let me also run the full test suite once more to be sure everything is good:Let me also think about edge cases and test with
nulladditionalProperties:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat > /tmp/edge_case_test.rs << 'EOF' use std::collections::BTreeMap;use coral_spec::parse_source_manifest_yaml; use coral_spec::v4::{import_openapi_surface, IrTypeShape};
fn main() { let manifest = parse_source_manifest_yaml( r" name: edge dsl_version: 4 surfaces:
-
id: rest type: openapi file: /tmp/openapi.yaml base_url: https://api.example.com ", ) .expect("manifest"); let v4 = manifest.as_v4().expect("v4"); let surface = v4.surfaces.first().expect("one surface");
// Edge case 1: additionalProperties with ref: '#/components/schemas/Item' components: schemas: Item: type: object properties: id: {type: string} " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("type"); println!("[REF MAP] additionalProperties: {{$ref}} -> shape: {:?}", ty.shape);
// Edge case 2: properties + additionalProperties: false (already tested, but double-check) let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /object-with-properties: get: operationId: objwith/get responses: '200': content: application/json: schema: type: object additionalProperties: false properties: id: {type: string} " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("type"); println!("[OBJ] additionalProperties: false with props -> shape: {:?}", ty.shape);
// Edge case 3: no type, no properties, no additionalProperties (the Json fallback case) let ir = import_openapi_surface( v4, surface, r" openapi: 3.0.3 paths: /free: get: operationId: free/get responses: '200': content: application/json: schema: {} " .as_bytes(), ) .expect("import"); let operation = ir.operations.first().expect("operation"); let ty = ir .types .iter() .find(|ty| ty.id == operation.output.type_ref) .expect("type"); println!("[FREE] empty schema -> shape: {:?}", ty.shape); } EOF echo "edge case test created"]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me create the edge case test as an actual test in the project so I can run it with cargo test:
Assistant
All edge cases are handled correctly:
additionalProperties: {$ref}→ typed Map with the referenced type ✓- Empty schema → Json (preserved existing behavior) ✓
additionalProperties: <schema>with properties → Object with fields (preserved existing behavior - properties take precedence) ✓
Now let me clean up the temporary test files:All edge cases handled correctly:
additionalProperties: {$ref}→ typed Map with referenced type ✓- Empty schema → Json (preserved) ✓
additionalProperties: <schema>with properties → Object with fields (preserved) ✓
Now let me clean up the temporary test files:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[rm crates/coral-spec/src/v4/_temp_edge_tests.rs && git checkout crates/coral-spec/src/v4/mod.rs && grep -n "mod _temp|mod openapi_tests" crates/coral-spec/src/v4/mod.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The mod.rs is back to its original state. Let me also verify everything one more time and run the tests:Let me run all the tests one more time and verify the diff is correct:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cargo test -p coral-spec 2>&1 | tail -5]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All 223 tests pass. Let me also run clippy and fmt checks one more time:All 223 tests pass. Let me also run clippy and fmt checks:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cargo clippy -p coral-spec --all-targets -- -D warnings 2>&1 | tail -5 && cargo fmt -p coral-spec -- --check 2>&1 | tail -5]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Everything passes. Let me do a final review of my changes:All checks pass. Let me do a final review:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git status && echo "===" && git diff --stat]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
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 →