natenho / Mockaco

🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
https://natenho.github.io/Mockaco/
Other
336 stars 39 forks source link

Support for External JSON File References in Mock Configurations #121

Open rhenness opened 1 year ago

rhenness commented 1 year ago

Prerequisites

Description

We often have scenarios where our mocked HTTP responses are quite extensive, making our Mockaco configuration JSON files long and harder to manage. To enhance readability and maintainability, we'd like to propose a feature that allows external JSON file references within the mock files.

Proposed solution

It would be beneficial to have a syntax or mechanism in the mock configurations that can specify an external JSON file to be read and inlined during the mock's runtime. For example:

{
  "request": {
    "method": "GET",
    "route": "largeResponseEndpoint"
  },
  "response": {
    "status": "OK",
    "body": "<#= ReadExternalJson("Mocks/some-data.json") #>"
  }
}

Alternatives

Enhance the Global object to allow users to define and set values that persist throughout the lifecycle of the Mockaco service. This would enable setting large common response structures or data once and then reference them in multiple mock endpoints.

For example:

<#
Global["some-data"] = { name: 'Bob' }
#>

Additional context

No response

natenho commented 1 year ago

Hi @ryan-henness-trimble, have you considered the file attribute? Please have a look at

Let me know if that works for you.