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:
yamlresponses: '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 use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
I'll start by exploring the repository structure to understand the codebase.
Assistant
The issue mentions
crates/coral-spec/src/v4/mod.rs:972andcrates/coral-spec/src/v4/mod.rs:1290. Let me find the actual location ofimport_responseandselect_json_response.Assistant
Now I understand the structure. Let me look at the OpenAPI importer and how it handles refs.
Assistant
Now let me look at the schemas.rs to see how schema refs are resolved (which the issue says already works).
Assistant
Now I have a clear understanding. Let me look at the test files for context.
Assistant
Now I understand the structure well. Let me also look at how operations.rs handles parameters and look at
operations.rsto understand parameter handling with refs.Assistant
Now I have a clear understanding. The issue is in
select_json_response- when the response object has a$ref, the function looks atcontentdirectly on the response without resolving the reference. Let me check how to fix this properly.Let me also look at related code to make sure I understand what the fix should look like. The function returns
(u16, String, &Value)where the value is the schema. The issue is that the response object itself might be a$ref.Let me also check the issue description again carefully:
- The fix needs to resolve
$refon the response object itself (not on the schema) - If a ref is missing or external, it should produce diagnostics consistent with schema/parameter refs
Let me run existing tests first to make sure things compile before changes.
- The fix needs to resolve
Assistant
Good, the project compiles. Let me look at the diagnostics module to see how diagnostics are structured.
Assistant
Now let me write a small script to reproduce the bug first.
Assistant
Let me instead create a temporary test inside the crate to reproduce.
Assistant
Wait, I added a duplicate entry. Let me clean that up.
Assistant
Good, it's a separate test module. Let me run the test now to confirm the bug.
Assistant
Let me fix my test.
Assistant
I've successfully reproduced the bug. The cardinality is
None, even though we get a projection forlistfoo(Wait, that's interesting - the projection still shows up. Let me check this more carefully.)Wait, looking at the output, it says
projection: listfoo (Table)but cardinality isNone. That's actually a separate issue: there is a projection, but the cardinality isNone. Let me look at the projection generation logic to understand why the projection shows up despite cardinality beingNone.Assistant
OK so the projection is created but hidden when cardinality is
None. Let me see how visibility works:Assistant
OK so projections are still created but hidden. The bug description says "fall through to OutputCardinality::None, which causes otherwise valid read operations to be hidden/dropped from the generated projection catalog". My test shows
listfoo (Table)but it must be Hidden. Let me check:Assistant
Now I've confirmed the bug. The cardinality is
Noneand the projection isHidden. Now let me fix the issue.The fix is in
responses.rs- specifically inselect_json_response, which needs to resolve$refs on the response object before checking forcontent. Let me design the fix:- Move the logic for resolving
$reffrom insideimport_response(where it's done on the schema) intoselect_json_response(or a helper), so it can resolve the response object itself.
Looking at the current flow:
select_json_responselooks at each response, findscontentand the schema inside it. Returns(status, media_type, schema).- Then
import_responsecallsself.resolve_ref(schema, ...)on the returned schema.
We need to also resolve the response object itself if it's a
$ref.The cleanest way is to make
select_json_responsetake the importer (or resolver function) as a parameter so it can resolve refs. Or move the ref-resolution insideselect_json_response.Let me look at how the function is structured once more.
- Move the logic for resolving
Assistant
Now let me design the fix. I'll modify
select_json_responseto accept an operation_id and diagnostics so it can resolve refs on the response object itself.Actually, looking at this more carefully, I think the cleanest fix is to keep
select_json_responseas a pure helper that operates on already-resolved values, and move the ref resolution into the caller. But that would require restructuring. Let me consider:Option A: Pass
&self(the importer) toselect_json_response. The function becomes a method onOpenApiImporter. This is the cleanest approach since the function already needs access tosurface.idfor diagnostics.Option B: Pre-resolve all response objects before calling
select_json_response. This is also clean.Let me look at the issue requirements again:
- "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"
The existing
resolve_refalready produces warnings for external refs and missing refs. So if we use it to resolve response refs, the diagnostics should be consistent.Assistant
Now let me implement the fix. I'll make
select_json_responsea method onOpenApiImporterso it can callresolve_refon the response object. Since we need to own the resolved value (the existing function returns&Valuefrom the original map), I'll need to clone the schema and pass an owned value.Let me look at how it's used and trace through carefully:
select_json_responseis called withoperation.get("responses").and_then(Value::as_object)— this is the operation'sresponsesfield.- It iterates through status codes, looks at each
responseobject (which can be a$ref), looks atcontentandschema. - Returns the chosen
(status, media_type, schema)whereschemais a reference into the original map.
Assistant
Now let me think about the structure. The fix should be:
-
select_json_responsebecomes a method onOpenApiImporterand takesresponses,operation_id,diagnostics. It returns(u16, String, Value)(owned schema). It:- Iterates over status codes (200-299).
- For each
responsevalue, callsself.resolve_ref(response, operation_id, diagnostics). If resolution fails, skip that status code (since resolve_ref already pushed diagnostics). - Looks for
content.application/json.schemaon the resolved response. - Returns the best candidate.
-
import_responsecalls the updatedselect_json_responseand then uses the returned ownedValuefor subsequentresolve_ref(which still handles schema$ref).
Let me implement this:
-
Assistant
Oops, my edit duplicated code. Let me revert and fix:
Assistant
Good. Now let me carefully rewrite the responses.rs file with the fix. I'll re-do the changes step by step.
Assistant
Now let me do the edit correctly. First, change the call to
select_json_responseto be a method call and pass operation_id + diagnostics:Assistant
Good. Now I need to:
- Convert
select_json_responsefrom a free function to a method onOpenApiImporter - Add ref resolution for the response object itself
- Change the schema return to owned
Valuesince after resolution the value is owned
Let me now look at what
schemabecomes after this —self.resolve_ref(schema, ...)takes&Valueand returnsOption<Value>, so it's fine to keep schema as&Value. But after my fix, the schema returned fromselect_json_responsewill be a reference into the resolved (owned) response, which means I need to either:- Return owned
Valueand clone once - Keep the resolved response alive somehow
Let me make
select_json_responsereturn(u16, String, Value)(owned schema). The existingimport_responsecan then callself.resolve_ref(schema, ...)on the owned schema.Wait, the
resolve_reffirst checks if the value has a . If we returned the schema directly from inside of the resolved response, and the schema is a itself, then we still want to resolve it. But that's already handled by the second call after.- Convert
Assistant
Now let me replace
select_json_responseto be a method and resolve refs:Assistant
There's leftover code from the old function (the
candidatesfilter logic). Let me clean that up:Assistant
Good, the file looks clean now. Let me check the closing brace on the impl block:
Assistant
Good, the structure looks right. The
fn select_json_responseis inside the impl block (after the closing brace ofimport_response). Let me verify the file compiles:Assistant
The
implblock is closing too early. The issue is that}on line 100 closes theimpl, but thenfn select_json_responseis outside. Let me fix the indentation and put it inside the impl block:Assistant
Looks like there are duplicated lines (97:
entity,and 98:},and 99:)) in the wrong place. Let me look more carefully and reset the file from git, then do this cleanly:Assistant
Let me rewrite the whole file cleanly using a single multi-line replacement:
Assistant
Let me do this differently. I'll do the edits as a series of smaller, more careful replacements:
Assistant
Now let me make my changes step by step carefully. First, the call site:
Assistant
Let me look at line 23 again and see exact whitespace:
Assistant
Hmm, the text is in the file but replace says "Text not found in displayed lines." Maybe because of how the current file display works. Let me use edit with line range:
Assistant
Now I need to convert the
select_json_responsefunction into a method onOpenApiImporter. Let me move it into the impl block and update it. The impl block currently ends at line 100 (}). I'll move the function into the impl block, before the closing brace, and update its body.Let me find the boundaries. The current impl block:
- Starts at line 11 with
impl OpenApiImporter<'_> { - Ends at line 100 with
}
The
select_json_responsefunction is at lines 102-120. I need to:- Remove the closing
}at line 100 - Add
select_json_responseinside the impl block - Add the closing
}back
Let me do this carefully:
- Starts at line 11 with
Assistant
The edit duplicated lines (97-101) and left over old content. Let me reset and try a different approach:
Assistant
Let me use a Python script to make the changes reliably:
Assistant
Let me verify the changes:
Assistant
The function is now outside the impl block again. Looking at the structure, I see line 100 has the
}that closes the impl, and the new function is at line 102. The function needs to be inside the impl block. Let me fix this:Assistant
Now the
select_json_responseis inside the impl block. I need to add a closing brace for the impl block after it:Assistant
The structure looks right. Let me also check the full structure:
Assistant
Now let me try to compile:
Assistant
Need to borrow the schema. Let me fix:
Assistant
Wait, I see line 100 is now just a blank (was a closing brace). And the impl block is now closed only by the brace at line ~135. Let me verify by looking at the full structure:
Assistant
Good. The impl block now closes at line 132 (the
}afterselect_json_response). Let me try to compile:Assistant
The library compiles. Now let me run my reproduction test:
Assistant
The fix works. Now cardinality is
List, type_ref islistfoo_row, projection isfooswithPublishedvisibility.Now let me also write tests for the missing/external ref diagnostics. First, let me run all the existing tests to make sure I didn't break anything:
Assistant
All 205 tests pass! Now let me think about edge cases:
- Missing response ref: e.g.,
$ref: '#/components/responses/Missing' - External response ref: e.g.,
$ref: 'other-file.yaml#/...' - Response ref where ref itself is broken or points to non-response object
- Combined case: response ref + schema ref
- Existing behavior should be preserved: response with
contentdirectly (no ref)
Let me think about case 3. With my current fix, when
resolve_refreturnsNone, the?causes the iteration to continue, but the diagnostic is already pushed byresolve_ref. Wait, but then the entireselect_json_responsereturnsNonewhich means we fall through toOutputCardinality::None— same as before. Let me check the test for missing refs again:- Missing response ref: e.g.,
Assistant
Looking at the existing test:
Assistant
This test checks that when the schema is a
$refthat doesn't exist,OPENAPI_RESPONSE_SCHEMA_UNRESOLVEDis in the codes. That still works with my fix.Now let me think about the missing response ref case. Let me write a test:
Assistant
Assistant
OK with single-threaded test execution we can see:
repro_external_response_ref: diagnostic codes["OPENAPI_EXTERNAL_REF_UNSUPPORTED"]- I need to add an assertion check on cardinality for this case.
Let me update the test to add a cardinality assertion:
Assistant
All three tests pass. Now let me clean up and remove my reproduction test. According to the issue's acceptance criteria, I need a "regression test covers a 200 response that references #/components/responses/... and verifies the projection is published." This test should be a proper, permanent regression test in the existing test file.
Assistant
Good. Now let me add the proper regression test to the existing
openapi_tests.rs:Assistant
Let me add the regression test for response refs at the end of
openapi_tests.rs:Assistant
All 9 openapi tests pass, including the two new regression tests. Now let me run the entire coral-spec test suite to make sure nothing is broken:
Assistant
All 206 tests pass (up from 205 since I added one regression test - wait, I added 2 tests. Let me check):
Assistant
Originally 205, now 206. Hmm, I added 2 tests but only one extra test ran. Let me check the count again:
Assistant
There are 9 tests in
openapi_tests, original had 7 (extracts_openapi_document_metadata, extracts_openapi_server_url_with_variable_defaults, importer_recognizes_common_wrapped_list_response_fields, importer_handles_recursive_schema_refs, importer_preserves_non_string_parameter_defaults, importer_recognizes_single_array_payload_wrappers, importer_warns_for_invalid_parameters_and_unresolved_responses). Now there are 9, I added 2: importer_resolves_response_refs_from_components_responses and importer_diagnoses_missing_and_external_response_refs.Wait, the original was 205 and now 206. Let me re-count:
Assistant
Hmm, originally 204 passed. With my changes + 2 new tests, should be 204 + 2 = 206. But the previous test run reported 205, and now 206. Wait, the stashed run was 204 (without my changes), the un-stashed run is 206 (with my changes + 2 new tests).
But earlier I saw "test result: ok. 205 passed". Let me check again carefully:
The 205 result I saw earlier was BEFORE I added the new regression tests (because I added the regression tests later). After adding the regression tests, we have 206 (204 + 2 = 206). All correct.
Wait, but I saw 205 earlier. Let me re-check - that was right after the source code change but before I added regression tests. The 205 was the original 204 + my code-only changes (which shouldn't change test count, but maybe was 205 due to something).
Actually, the
eprintln!calls inselect_json_response... no wait, my old reproduction test had eprintln statements but it was deleted. So the 205 count was just from 204 + something. Let me check git status:Assistant
Good. Now let me look at the full diff:
Assistant
The diff looks clean. Let me also look at the openapi_tests.rs diff:
Assistant
Now let me also think about additional edge cases. What if the response ref is on a status code other than 200, like 201?
Let me think about the
resolve_refinteraction. The existingresolve_reffunction:rustAssistant
Both edge cases work as expected:
response_ref_pointing_to_schema: A response ref that points to a schema (nocontent) returnsOutputCardinality::None. This is correct because the ref-resolved object doesn't have thecontentfield.response_ref_with_schema_ref: A response ref where the schema insidecontentis itself a$refto a schema works correctly. The type_ref isfooitem(the schema name).
Now let me clean up these temporary test files:
Assistant
Now let me run the full test suite for the entire workspace to make sure nothing is broken:
Assistant
All tests pass. Now let me also run clippy to check for code quality issues:
Assistant
Clippy passes. Let me also try to run the broader test suite to make sure nothing else is broken:
Assistant
Workspace builds. Now let me verify the original test referenced by the issue description still passes:
Assistant
Good. Let me also re-read the original issue text to make sure I've covered everything:
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.
Let me look at my current changes more carefully to make sure they're complete:
Assistant
The diff is clean. Let me also re-run all coral-spec tests to ensure I didn't break anything:
Assistant
All 206 tests pass. Let me also try running make rust-checks to make sure I'm aligned with the project's CI:
Assistant
Format check passes. Let me also try cargo clippy on the whole workspace to see if my changes cause issues:
Assistant
Clippy passes. Let me also check if cargo nextest is available:
Assistant
Nextest is not available. The regular
cargo testworks. Let me run one more broader test to make sure my changes don't break anything:Assistant
All 206 tests pass with all features enabled. Let me also test broader packages to make sure I didn't break anything:
Assistant
All tests pass. Let me also check if there's any documentation I should update. Let me search for documentation about this area:
Assistant
No documentation references to update. Let me also look at the AGENTS.md and CHANGELOG to see if I should update those.
Assistant
The CHANGELOG is auto-generated by release-please. Let me verify the final state of my changes:
Assistant
Now let me also verify the complete file looks right:
Assistant
The file looks clean. Let me also verify the test file is correct:
Assistant
Let me now make a final check that all tests pass:
Assistant
All tests pass. Let me also do a final verification by running my exact reproduction case from the issue:
Assistant
Let me check the final git status to confirm what will be submitted:
Assistant
Let me go through the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.