Repository navigation
feat: support json_body and body_from_file in static mock YAML files - #299
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The static mock YAML format silently dropped json_body and body_from_file because StaticHTTPResponse did not define these fields, leaving responses without a body. - json_body is converted to the runtime response body. A YAML string value is parsed as JSON, matching the documented examples. - body_from_file is resolved by the static mock directory loader relative to the YAML file. The resolved path must stay inside the configured static mock directory; absolute paths, .. escapes, directories, and symlinks escaping the directory are rejected. Outside the loader (e.g. recordings imported via the HTTP API), body_from_file is rejected with a clear error, and recording export never emits it.
alexliesenfeld
force-pushed
the
static-yaml-response-bodies
branch
from
September 2, 2026 19:53
ccdd1f5 to
72cc84a
Compare
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The static mock YAML format silently dropped
json_bodyandbody_from_filebecauseStaticHTTPResponsedid not define these fields, so Serde discarded them and the mock responded without a body.Closes #118
Closes #185
Changes
json_bodyis converted to the runtime response body. A YAML string value is parsed as JSON (matching the examples in the issues), structured YAML values are serialized as JSON. No content-type header is added, consistent with the RustThen::json_bodyAPI.body_from_fileis resolved by the static mock directory loader relative to the YAML file that references it. The resolved path must stay inside the configured static mock directory: absolute paths,..escapes, directories, and symlinks escaping the directory are rejected. The file is read once at load time.body_from_fileis rejected with a clear error. Recording export never emitsjson_bodyorbody_from_file.Design notes
File resolution lives entirely in
server/persistence.rs: the loader takes thebody_from_filereference out of the parsed definition, converts the rest with the ordinary IO-free conversion incommon/data.rs, then reads the file and sets the runtime response body. The response body field precedence (json_body>body>body_base64, with a resolved file reference always winning) is documented and implemented in one place.Tests
Unit tests cover the
json_bodyconversion, path confinement forbody_from_file(including..and symlink escapes), and the rejection ofbody_from_fileoutside the static mock directory loader.