Migrating from v3 to v4
If you are already using Mocks Server v2.x you should migrate first from v2.x to v3.x, and then read this chapter to prepare migration to v4.x.
V4 motivationβ
A lot of great changes were introduced in v3 minor versions. Those changes were mainly focused on changing the main concepts of the project and modifying the APIs in order to make them more modular and scalable, making easier to implement the oncoming features. Each one of those changes were progressively introduced in v3 minor versions in order to provide backward compatibility mechanisms, allowing users to progressively adapt to the new APIs. Using legacy APIs in v3 produced alerts, so the users could know what things they should change in order to be ready for the v4 version, which definitively removes the legacy code, reducing the complexity and the amount of tests, and consequently, it allows us to focus on giving the next steps for improving the developer experience and provide new awesome features π.
So, the v4 mainly removes the legacy code that was progressively deprecated in v3 minor versions. Then, if you update to v3.12 and follow the guide to prepare your code from v3 to v4, it would be very easy to update to v4 taking into account some few breaking changes.
First update to v3.12, which is mostly compatible with v4.x. You will receive alerts for each thing you have to change before updating to v4.x. So, you can modify your code progressively until there are no more alerts, and then you'll be able to update to v4 reading the breaking changes guide in this page.
Changes summaryβ
The main breaking changes in v4.x are:
- Removed legacy properties in collections and variants. Read collections and variants for further info.
- Removed legacy options. Read options for further info.
- Removed legacy methods in the JavaScript API. Read JavaScript API for further info.
- Removed legacy Administration REST API path. Read Administration REST API path for further info.
- Removed legacy formats for defining plugins, and removed legacy plugin parameters. Read plugins for further info.
- Removed legacy format for defining variant handlers. Read variant handlers for further info.
- Removed legacy proxy handler. proxy-v4 handler renamed into proxy. Read proxy handler for further info.
Changes in other packages related to this releaseβ
- Admin API Client. The
@mocks-server/admin-api-clientpackage release 7.0 removes the legacy default API client methods. TheAdminApiClientclass has to be used instead.
Collectionsβ
- In collection definitions, the properties
routeVariantsandroutesVariantsare not supported any more. Theroutesproperty must be used instead.
Variantsβ
- In route variants definitions, the property
responseis not supported any more. Options for the variant handler must be defined in the variantoptionsproperty. - Do not support
handlerproperty in variants, which was an alias fortype. From now, onlytypeis supported (and required, unless thedisabledproperty is true) - Remove the default route handler. Now the
typeproperty is mandatory in variants
Optionsβ
- Remove legacy
routesHandlersoption - Remove legacy
mocks.selectedoption - Remove legacy
mocks.delayoption
JavaScript APIβ
- Remove legacy
core.addRoutesHandlermethod - Remove legacy
core.loadMocksmethod - Remove legacy
core.loadRoutesmethod - Remove legacy
core.onChangeMocksmethod - Remove legacy
core.onChangeAlertsmethod - Remove legacy
core.onChangeLogsmethod - Remove legacy
core.restartServermethod - Remove legacy
core.addRoutermethod - Remove legacy
core.removeRoutermethod - Remove
contextproperty fromalerts.flatcollection items - Remove legacy
core.alertsApigetter. Nowcore.alertsmust be used instead - Remove legacy
core.mocksgetter - Remove legacy
core.tracergetter - Remove legacy
core.logsgetter - Remove legacy
core.mock.currentsetter - Remove legacy
core.mock.restoreRoutesVariantsmethod - Remove legacy
core.mock.customRoutesVariantsgetter - Remove legacy
core.mock.currentgetter - Remove legacy
core.mock.idsgetter - Remove legacy
core.mock.plainMocksgetter - Remove legacy
core.mock.plainRoutesgetter - Remove legacy
core.mock.plainRoutesVariantsgetter - Remove legacy
core.mock.errorgetter - The
core.alertsgetter now returns the root alerts API, not a flat collection of alerts. If you want to get the flat alerts collection, usecore.alerts.flat
Administration REST APIβ
- Remove custom router
/adminfrom mock server. Admin API is only available at its own server from now.
Pluginsβ
- Remove support for defining plugins as objects, functions, etc. Now, only classes are supported. If the class has not a static id, the
alerts,configandloggerproperties wonβt be available in the core passed to the constructor. If the class has an id getter, those properties will be received in start, stop, init and register methods, but not in the constructor. - Remove legacy methods passed to the plugins as parameter properties:
loadMocks,loadRoutes,addAlert,removeAlert,core. Now, only the core is passed as argument (with namespaced alerts, logger and config)
Variant handlersβ
- Ignore
versionproperty in variant handlers. From now, all handlers are considered to be defined in βv4β format - Do not support
plainResponsePreviewgetter in variant handlers. Now onlypreviewgetter is supported
Proxy handlerβ
- In v3, a new variant handler was released: "proxy-v4". It was named so because the "proxy" one couldn't be modified without producing a breaking change, so, the new handler was provided with a different name. In v4, the old "proxy" has been removed and the "proxy-v4" has been renamed into "proxy".
Breaking changes from v3.12β
Even if you were using v3.12 and you were not receiving any deprecation alert, you still may have to make some changes when updating to v4:
- Change your variants of type "proxy-v4" to type "proxy". Only the type property has to be changed, the options are still compatible.
- The
contextproperty has been removed from thealerts.flatcollection of items. - The
core.alertsgetter now returns the root alerts API, not a flat collection of alerts. If you want to get the flat alerts collection, usecore.alerts.flat - The
core.alertsApigetter has been removed. Now you must usecore.alertsinstead. - The
handlerproperty in variants, which was an alias fortype, is not supported any more. From now, onlytypeis supported (and required, unless thedisabledproperty is true) - In collection definitions, the property
routeVariantsis not supported any more. Theroutesproperty must be used instead.