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
I'll start by exploring the repository structure to understand the codebase and locate the relevant files for OpenAPI schema import, particularly handling additionalProperties. Let me first get an overview.
- Assistant
Let me get a better understanding of the project structure and find the relevant files for OpenAPI schema import.
- Assistant
This appears to be a Rust project (Cargo.toml, crates directory). Let me explore further to find the OpenAPI schema import functionality.
- Assistant
I need to look at the issue. It says:
- "The schema importer treats the presence of
additionalPropertiesas map-like, soadditionalProperties: falsecan be imported as a free-form map instead of a closed object." - Need to handle boolean
additionalProperties: falseas a closed object, preserve schema-valued additionalProperties behavior, and add focused schema import coverage.
Let me look at the relevant file(s) first.
- "The schema importer treats the presence of
- Assistant
The key file is likely
/coral/crates/coral-spec/src/v4/surfaces/openapi/schemas.rsbased on the grep foradditionalProperties. Let me look at it. - Assistant
Let me see the rest of the file to understand how
additionalPropertiesis currently handled. - Assistant
Now I can see the issue. Let me examine lines 89-114:
rust - Assistant
Let me look at the IR model to understand the shapes available:
- Assistant
Now let me look at the existing tests to understand how the OpenAPI schema import works and what test patterns are used:
- Assistant
Let me look for existing tests related to
additionalPropertiesin the test file: - Assistant
Let me look at the rest of the tests to understand the pattern:
- Assistant
Now let me look at the full
schemas.rsfile to understand the exact logic: - Assistant
Now I understand the issue. Let me also look at the tests file to understand the test patterns:
- Assistant
Now let me look at the test helper function to understand how tests are set up:
- Assistant
Now I understand the problem. In line 102 of
schemas.rs: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 code doesn't check whether is a boolean (/) or an object (schema). When , the code tries to treat it as a schema and call on it, which would likely fail or produce unexpected results.
- Assistant
The tests don't have any existing tests for
additionalProperties. I need to add tests to verify the fix. Let me first understand the full flow by looking at the completeschemas.rsfile one more time, then implement the fix. - Assistant
Let me see the remainder of the file:
- Assistant
Now I have a clear picture of the issue. The problem is in lines 102-111 of
schemas.rs: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 } }When
additionalProperties: false(a boolean), the code tries to import it as a schema and create a Map. Instead:additionalProperties: false→ closed object with no additional properties (emptyObject)additionalProperties: true→ free-form map (Mapwith value type"json")additionalProperties: { schema }→ preserve current map behavior
Let me first reproduce the issue by running the existing tests to understand the baseline:
- Assistant
All existing tests pass. Now let me implement the fix. I need to modify the
schemas.rsfile to handleadditionalProperties: falseas a closed object, and add tests. - Assistant
Now I'll fix the code. I need to replace lines 102-111 with proper handling of
additionalPropertiesbeing a boolean or a schema: - Assistant
Good. Now let me verify the change compiles and existing tests still pass:
- Assistant
All existing tests pass. Now I need to add tests to cover the
additionalPropertiesbehavior. Let me look at the end of the openapi_tests file to add new tests: - Assistant
Now I'll add the test cases at the end of the file:
- Assistant
I see there's a duplicate line at 666-666. Let me check and fix that:
- Assistant
I see there's a duplicate assertion at line 666. Let me fix that:
- Assistant
I see there's still a problem with extra closing brace. Let me check:
- Assistant
There's a duplicate
}on lines 666-667. Let me fix that: - Assistant
Good, the duplicate
}is fixed. Now let me run the tests to make sure they all pass: - Assistant
The tests are failing because the type id is not "item". Let me check how normalize_identifier works to understand the expected type id:
- Assistant
Let me check the
normalize_identifierfunction: - Assistant
Let me check how the import works by adding some debug output to understand what's happening:
- Assistant
Let me look at the import function to understand how it works and where types get registered:
- Assistant
Let me see the rest of the file to understand how resolve_ref works:
- Assistant
Let me check what
type_id_from_refdoes: - Assistant
Let me write a quick debug test to understand the actual types being generated:
- Assistant
Let me look at how operations import the response schema to understand where type_id comes from:
- Assistant
Let me look at the import_response function:
- Assistant
Let me look at the import_response function:
- Assistant
Let me find the import_response function:
- Assistant
Let me search for where import_response is defined:
- Assistant
Let me check the responses.rs file to understand how the response schema is imported:
- Assistant
Let me look at the
classify_response_schemafunction: - Assistant
Let me look at the
classify_response_schemafunction: - Assistant
Now I understand the issue - when the schema is
{$ref: '#/components/schemas/Item'}, theresolve_refresolves it fully, so by the timeclassify_response_schemaandimport_schemasee it, the$refis already resolved. The type ID would be based on the suggested name, not "item". Let me debug to find the actual type IDs: - Assistant
I need to debug the actual type IDs being created. Let me add a temporary test to see what types are generated:
- Assistant
I need to understand how the response import flow works. Let me look at how
import_responseworks in more detail: - Assistant
Let me trace through more carefully. The key is
import_response:schemafromselect_json_responseis{$ref: '#/components/schemas/Item'}resolved = self.resolve_ref(&schema, ...)resolves it to{type: object, additionalProperties: false}classify_response_schema(path, &resolved)- receives the resolved schema- But then
import_schema(&row_schema, ...)is called withrow_schemawhich wasschema.clone()inclassify_response_schema
Wait, let me look at
classify_response_schemaagain - it receivesschemawhich is the resolved value. When it returns, it returnsschema.clone(). Sinceschemais already the resolved value,row_schemawould NOT have$ref... unless...Actually wait - the line 69 says
&row_schemabut looking at the flow:- Line 23:
let Some((status_code, media_type, schema)) = self.select_json_response(...)- this is the RAW schema from JSON, i.e.,
- Assistant
I need to understand how the type_id is determined. Let me look at how
import_responseworks - the schema value goes throughclassify_response_schemawhich passes the already resolved schema toimport_schema, so the type_id would be based on the suggested name, not the original$ref. Let me check how existing tests handle this: - Assistant
Let me understand the response classification flow better. Let me look at how the tests find types - they use
operation.output.type_ref: - Assistant
Now I understand the issue. The type_id is not "item" because the
$refis resolved beforeimport_schemais called in the response flow. The type_id would be based on the suggested name from the operation. I need to useoperation.output.type_refto find the type. Let me update the tests: - Assistant
I see there's a duplicate
#[test]attribute at line 668-669. Let me fix that: - Assistant
Now I need to update the other two tests similarly. Let me also fix them:
- Assistant
Let me update the "additionalProperties: true" test:
- Assistant
Now let me update the third test for schema-valued additionalProperties:
- Assistant
Let me update the third test:
- Assistant
Now let me run the tests to see if they pass:
- Assistant
All 15 tests pass (12 original + 3 new ones). Let me also run the full test suite for the coral-spec crate to make sure nothing else broke:
- Assistant
All 222 tests pass, including the new ones. Let me also check for any clippy warnings:
- Assistant
No clippy warnings. Let me also verify that I haven't introduced any other issues by looking at the modified files. Let me review the changes I made:
- Assistant
The diff looks clean and correct. Let me verify the final state of the modified files:
- Assistant
Let me also verify the test file to make sure it's correct:
- Assistant
The code looks good. Let me now run the full test suite one more time to confirm everything passes:
- Assistant
All 222 tests pass. Let me now do a final review of my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.