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.
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:
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files mentioned in the issue. Let's first check the current directory.
- Assistant
Good, there's the file. Let me also look at the overall structure to understand what we're dealing with.
- Assistant
Let me open the file mentioned in the issue to understand the code.
- Assistant
The file is only 54 lines long, so the line numbers mentioned in the issue (972 and 1290) must refer to a different file or there's something else going on. Let me check the actual content.
- Assistant
This is a module file that re-exports from other modules. I need to find the actual implementation files that contain the functions mentioned in the issue (import_response, select_json_response). Let me search for these functions across the codebase.
- Assistant
Perfect! I found the relevant files. Let me examine the responses.rs file to understand the current implementation and see what needs to be changed.
- Assistant
Now I can see the issue! The
select_json_responsefunction (lines 100-130) directly looks forcontenton each response object without first resolving$ref. According to the issue, when a response is expressed as a$ref, like:responses: '200': $ref: '#/components/responses/Foo'The current code will skip it because it checks for
contentdirectly on the response object, but the response object itself is a$refthat needs to be resolved first.Let me also check how
resolve_refworks to understand the pattern for resolving references. Let me look at the import.rs file to see how it's implemented. - Assistant
Let me check the import.rs file to understand the resolve_ref method.
- Assistant
Perfect! Now I can see how
resolve_refworks. It takes a value that might be a$refand resolves it to the actual value from the document. The function is already available in theOpenApiImporterstruct.Now I need to understand how the current code flows:
import_responsecallsselect_json_responsewithoperation.get("responses")select_json_responseiterates over responses, but it only looks forcontentdirectly on each response object without resolving$refs
The fix should be to resolve
$refs in the responses before passing them toselect_json_response. Let me also check if there are any existing tests to understand the expected behavior better. - Assistant
Let me check the openapi_tests.rs file to see if there are existing tests that might help me understand the expected behavior and create a regression test.
- Assistant
Let me run the existing tests to make sure they pass before making changes.
- Assistant
Now let me check how the code handles parameters to understand the pattern for resolving
$refs: - Assistant
Good! I can see that other parts of the code use
resolve_refto resolve$refs. Now let me examine the operations.rs file to see how parameters are handled. - Assistant
Perfect! I can see the pattern now. In
import_parameters, line 106, they callself.resolve_ref(parameter, operation_id, diagnostics)to resolve$refs for parameters. Similarly, inimport_request_body, line 217, they callself.resolve_ref(body, operation_id, diagnostics).Now, looking back at the responses.rs file, the issue is that
select_json_responseis a standalone function that doesn't have access to the importer instance. The best approach is to resolve all response$refs before callingselect_json_responseinimport_response.Let me create a helper method that resolves response
$refs and returns a resolved responses map. Then we can pass that toselect_json_response. - Assistant
Let me now understand the full picture by looking at how the tests use the code and what the existing pattern for ref resolution is. Let me examine the code structure more carefully and then make the fix.
- Assistant
Let me now open the responses.rs file and make the fix. The approach is:
- Modify
select_json_responseto accept the OpenAPI document so it can resolve response-level$refs before looking forcontenton each response. - Add diagnostic messages consistent with existing patterns.
- Modify
- Assistant
Now I'll modify the
import_responsemethod to pass the document toselect_json_response, and modifyselect_json_responseto resolve response$refs.The approach:
- Change
import_responseto passself.documentandself.surface.idand diagnostics toselect_json_response. - Modify
select_json_responseto resolve response-level$refs using the document.
Wait, actually there's a lifetime issue.
select_json_responsecurrently returns&Valueborrowed from the responses map, which ultimately borrows fromself.document. If I passdocument: &Valuedirectly, when we resolve a$ref, we getdocument.pointer(...)which returns&Valueborrowing fromdocument. Since the responses also borrow fromdocument(transitively throughoperation), all the lifetimes should be compatible.Let me plan the exact changes:
- Change the signature of
select_json_responseto accept the document. - In the loop, when we encounter a response with , resolve it using the document pointer.
- Change
- Assistant
Now I have a clear understanding of the problem and the solution. Let me implement the fix. I'll modify
select_json_responseto accept the document and resolve response$refs: - Assistant
Good, now I need to modify the
select_json_responsefunction to accept the document and resolve response$refs. Let me update it: - Assistant
It seems like the old function body was not replaced but instead the new one was inserted above it. Let me look at the full file and fix the duplication:
- Assistant
I see there's a duplicate old function body that needs to be removed. Let me delete it:
- Assistant
Let me check the full file to see what happened:
- Assistant
The file seems to have gotten corrupted. Let me restore from git and redo the edit cleanly.
- Assistant
Good, now let me look at the original file again and make a clean edit:
- Assistant
Good, the file is back to its original state. Let me write the entire file using a script to avoid the edit tool issues:
- Assistant
Good. Now let me verify the file was written correctly:
- Assistant
Now let me run the existing tests to make sure my changes don't break anything:
- Assistant
All existing tests pass. Now I need to add a regression test that covers the
$refresponse scenario. Let me add a test to openapi_tests.rs: - Assistant
Let me see the end of the test file:
- Assistant
Now I need to add a new test at the end of the file that tests the
$refresponse scenario. Let me append the test to the file: - Assistant
Now let me run the tests to see if my new test passes:
- Assistant
Excellent! The new test passes. Now let me run all the existing tests to make sure they still pass:
- Assistant
All 8 tests pass (7 existing + 1 new). Now let me run all tests in the crate to make sure nothing else is broken:
- Assistant
All 205 tests pass, including my new test. Now let me verify the changes by looking at the diff:
- Assistant
Let me also run the full test suite for the repository to make sure nothing else is broken:
- Assistant
The 2 failing tests are in
coral-appcrate (integration tests for gRPC), not related to my changes at all. They seem to be pre-existing test failures related to file system operations. Let me verify by checking if these tests fail even without my changes: - Assistant
Good, the 2 failing tests are pre-existing failures unrelated to my changes. Let me restore my changes:
- Assistant
Let me also add a test for external response refs and missing response refs to ensure diagnostics are emitted. Let me check if there's a test for external refs and add more edge case tests:
- Assistant
Let me run the new tests to make sure they pass:
- Assistant
All 9 tests pass. Let me run the full coral-spec tests one more time to confirm everything is good:
- Assistant
All 206 tests pass. Let me do a final review of my changes:
- Assistant
Let me review the responses.rs diff one more time to make sure it's correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.