Skip to content

Conversation

@waldekmastykarz
Copy link
Collaborator

Fixes hot reload of CRUD API data file. Closes #1390

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner December 30, 2025 12:26
Copilot AI review requested due to automatic review settings December 30, 2025 12:26
@waldekmastykarz waldekmastykarz added the pr-bugfix Fixes a bug label Dec 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CRUD API plugin to enable hot reload of the data file by introducing a dedicated CrudApiDataLoader class that leverages the existing BaseLoader infrastructure with file watching capabilities. The changes separate concerns between API definition loading and data loading, allowing both to be independently monitored and reloaded.

Key changes:

  • Introduced CrudApiDataLoader to handle data file loading with hot reload support
  • Renamed _loader to _definitionLoader in CrudApiPlugin for clarity
  • Updated BaseLoader to skip schema validation for JSON arrays (data files)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
DevProxy.Plugins/Mocking/CrudApiPlugin.cs Refactored to use separate loaders for API definition and data, removing inline LoadData() method
DevProxy.Plugins/Mocking/CrudApiDataLoader.cs New loader class that extends BaseLoader to provide hot reload functionality for CRUD API data files
DevProxy.Abstractions/Plugins/BaseLoader.cs Updated schema validation to skip JSON arrays, enabling validation of data files

Comment on lines 30 to 43
protected override void LoadData(string fileContents)
{
try
{
var data = JArray.Parse(fileContents);
_onDataLoaded(data);
Logger.LogInformation("Data for CRUD API loaded from {DataFile}", _configuration.DataFile);
}
catch (Exception ex)
{
Logger.LogError(ex, "An error has occurred while reading {DataFile}", _configuration.DataFile);
_onDataLoaded(null);
}
}
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handling in LoadData doesn't replicate the behavior from the removed LoadData method in CrudApiPlugin. The old implementation would disable the API by setting Configuration.Actions to an empty array when the data file doesn't exist, preventing the plugin from processing requests. The new implementation only sets data to null via the callback, which means the API remains enabled but _data is null. This could lead to issues when API actions are invoked with null data. Consider either:

  1. Passing the Configuration to the data loader so it can disable actions on file not found, or
  2. Returning a success/failure status from InitFileWatcherAsync so the plugin can disable itself in InitializeAsync when data loading fails.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@garrytrinder garrytrinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm. I tested changing data and changing actions, all worked perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Dev Proxy does not restart when updating CRUD API data file

2 participants