ISSUE DESCRIPTION Resolve OpenAPI $ref response objects during DSL v4 import Problem DSL…
- User
ISSUE DESCRIPTION
Resolve OpenAPI $ref response objects during DSL v4 import
Problem
DSL v4 OpenAPI import currently misses valid response objects that are expressed as
$refs.import_responsecallsselect_json_response, andselect_json_responselooks forcontentdirectly on each response object without first resolving$ref.Code references:
crates/coral-spec/src/v4/mod.rs:972crates/coral-spec/src/v4/mod.rs:1290
A valid OpenAPI shape like this is treated as if the operation has no JSON response:
responses: '200': $ref: '#/components/responses/Foo' components: responses: Foo: content: application/json: schema: type: array items: type: objectImpact
The importer falls through to
OutputCardinality::None, which causes otherwise valid read operations to be hidden/dropped from the generated projection catalog. This can make major portions of a real OpenAPI descriptor disappear from DSL v4 sources.Acceptance criteria
- Response
$refs under operation responses are resolved before selecting JSON responses. - Missing or external response refs produce diagnostics consistent with existing schema/parameter ref diagnostics.
- A regression test covers a
200response that references#/components/responses/...and verifies the projection is published.
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 and understanding the codebase.
Assistant
Let me run commands one at a time.
Assistant
The mod.rs was split. The line numbers in the issue don't match anymore. Let me search for
select_json_responseandimport_response.Assistant
Now let me look at how
resolve_refworks and how schema/parameter ref diagnostics are produced.Assistant
Now let me look at the operations.rs file to understand the diagnostic patterns used.
Assistant
Let me look at the diagnostics module and existing tests.
Assistant
Let me look at the test_support and projection_tests to understand helpers for a regression test.
Assistant
Now let me write a quick reproduction to confirm the issue. Let me create a temp test file and run it.
Actually, the instructions say not to modify existing tests or add tests to the repository. I can create a temporary script. But the tests are Rust tests in the crate. Let me create a temp test file in the crate's tests, or better, let me just write a quick test and run with cargo test. Actually I should add a temp test, run it, then remove.
Let me first reproduce by writing a temporary test file. Let me check how tests are organized - the tests are in
mod.rsof the v4 module (inline tests). Let me check.Assistant
Let me create a temporary test to reproduce the issue. First, let me check the lib exports and run an existing test to make sure the build works.
Assistant
Let me check how to compile and run a standalone rust file. I'll need the crate as a dependency. Let me use
cargowith an example or a temporary test. Actually, the simplest approach: write the test as a #[test] function temporarily in the openapi_tests.rs, run, then revert. But I'm told not to modify existing tests... but a temporary modification that I revert is fine.Actually a cleaner approach: create a temp integration test in
crates/coral-spec/tests/tmp_repro.rs. This is a new file in the repo. I'll run it, then delete it before submitting. Let me do that.Assistant
No tests directory. Let me create it. Actually, let me just temporarily add a test function in openapi_tests.rs, run it, then revert with git checkout. That's the cleanest since I can revert easily.
Actually, let me create the tests dir.
Assistant
Reproduction confirmed:
cardinality = Nonefor a$refresponse. Now let me check ifselect_json_responseis used elsewhere.Assistant
Only used in one place. Let me refactor
select_json_responseinto a method that resolves$refs and returns owned values.Assistant
Let me refactor the call site and convert
select_json_responseinto a method that resolves$refs.Assistant
Now let me make the changes. I'll:
- Change the call to
self.select_json_response(operation.get("responses").and_then(Value::as_object), operation_id, diagnostics)returning owned(u16, String, Value). - Change
self.resolve_ref(schema, ...)toself.resolve_ref(&schema, ...). - Convert the free
select_json_responsefunction to a methodfn select_json_response(&mut self, ...) -> Option<(u16, String, Value)>inside the impl, that resolves $ref for each response before checking content.
Let me edit lines 23-24 first.
- Change the call to
Assistant
I introduced a duplicate
else {. Let me fix that.Assistant
Now
schemais owned (Value) soself.resolve_refneeds&schema. Let me update line 44.Assistant
Now I need to convert the free function
select_json_responseinto a method inside the impl block that resolves$refs. Let me replace the closing of the impl block and the free function.Assistant
Now I'll replace lines 99-126 to convert the free function into a method that resolves
$refs.Assistant
Now
value(the response) is a&Value.self.resolve_ref(response, ...)takes&Value. Good.Now there's a borrow issue:
self.resolve_reftakes&mut self(it's&selfactually, let me check).resolve_refisfn resolve_ref(&self, ...). So no borrow conflict. Butselect_json_responseis&mut self- that's fine since it callsresolve_ref(&self)anddiagnosticsis a separate&mut. Actually wait,self.resolve_refborrows&selfimmutably while we have&mut self- that's fine (reborrow). Anddiagnosticsis&mut Vec<Diagnostic>passed as separate arg, not through self. Good.But there's a subtle issue:
candidatesholds owned(u16, String, Value). The final selection:candidates.iter().position(...).and_then(|index| candidates.get(index).cloned())returnsOption<(u16,String,Value)>via cloned. ButValueis Clone - yes. Then.or_else(|| candidates.into_iter()...)- butcandidateswas borrowed by.iter()in the first branch. Since the first branch uses.cloned()and short-circuits viaand_then, if it returns Some, the or_else won't run. But the borrow checker:candidates.iter()borrows candidates immutably, and within the same expressioncandidates.get(index).cloned()- fine. Then.or_else(|| candidates.into_iter()...)moves candidates. Since the iter borrow ended (cloned produced owned), this is okay? Actuallycandidates.iter()returns an iterator borrowingcandidates. The.positionconsumes that iterator (returns Option), ending the borrow. Then.and_then(|index| candidates.get(index).cloned())-candidates.getborrows again,.cloned()ends it. So after theand_thenclosure completes, no borrow remains. Then.or_elseclosure can movecandidates. This compiles. The original code had the same pattern with&Valuereferences and.cloned()(which cloned the reference to&Value... wait original was(u16, String, &Value)and.cloned()onOption<&(u16,String,&Value)>clones the tuple containing a&Value- that's a Copy of the reference). Now with owned Value,.cloned()clones the Value. Fine.Now let me build.
Assistant
Build succeeds. Now let me run the reproduction test.
Assistant
Now let me test edge cases: missing response ref and external response ref diagnostics.
Assistant
Let me check the
as_v4return type and whether types are Clone.Assistant
as_v4returnsOption<&V4SourceManifest>. Let me check if V4SourceManifest and V4Surface derive Clone.Assistant
Both are Clone. Let me run the temp tests.
Assistant
ValidatedSourceManifestis not re-exported fromv4. It's in lib root. Let me import fromcoral_spec::ValidatedSourceManifest. Let me check.Assistant
All 3 edge cases pass. Now let me run the existing test suite to make sure nothing breaks.
Assistant
All 204 existing tests pass plus my 3 temp tests. The system instructions forbid adding tests to the repository (the evaluation system has its own), so let me remove the temp test file. But first, let me check for lint compliance on the modified file.
Assistant
Let me remove the unnecessary semicolon at line 117.
Assistant
No more warnings. Now let me remove the temp test file and run the full test suite once more.
Assistant
All tests pass. Let me verify the broader workspace builds correctly.
Assistant
Let me review the final diff to ensure everything is clean.
Assistant
The diff is clean and minimal. Let me do a final full test run to confirm everything passes.
Assistant
Let me run the full workspace tests to ensure nothing else is affected.
Assistant
Two failures in
source_lifecycle_tests. Let me check whether these are related to my change or pre-existing/environmental.Assistant
These failures are about config-write/cleanup-failure rollback scenarios (environment-dependent: e.g., "config write should fail" but it succeeded). They're unrelated to my OpenAPI parsing change. Let me confirm they're pre-existing by stashing my change and re-running them.
Assistant
Let me re-run more carefully to confirm these failures are pre-existing.
Assistant
Confirmed: the two
source_lifecycle_testsfailures are pre-existing (they fail identically without my change). They are environment-dependent filesystem-permission tests unrelated to OpenAPI response parsing.My change is restored. Let me do a final confirmation of the diff state.
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 →