Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 77b5898

Browse files
committed
feat: Remove adminApiDeprecatedPaths option. Move legacy api under main api path
1 parent 5d2335f commit 77b5898

3 files changed

Lines changed: 20 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
### Added
1313
- Add mocks, routes and routes-variants apis
1414
### Changed
15-
- Move behaviors and fixtures apis to legacy folder
15+
- Move behaviors and fixtures apis under legacy folder
1616
### Fixed
1717
### Removed
1818
- Remove deprecated api paths
19+
- Remove adminApiDeprecatedPaths option.
1920

2021
## [1.5.0] - 2020-12-25
2122

src/Plugin.js

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,29 @@ const Mocks = require("./Mocks");
3131
const Routes = require("./Routes");
3232
const RoutesVariants = require("./RoutesVariants");
3333

34-
const {
35-
ADMIN_API_PATH_OPTION,
36-
ADMIN_API_DEPRECATED_PATHS_OPTION,
37-
PLUGIN_NAME,
38-
} = require("./constants");
34+
const { ADMIN_API_PATH_OPTION, PLUGIN_NAME } = require("./constants");
3935

4036
class Plugin {
41-
constructor(core) {
37+
constructor(core, { addAlert }) {
4238
this._core = core;
4339
this._tracer = core.tracer;
4440
this._settings = this._core.settings;
45-
this._deprecatedApi = new DeprecatedApi(core);
41+
42+
this._legacyApi = new DeprecatedApi(core, { addAlert });
4643
this._settingsApi = new Settings(this._core);
4744
this._mocksApi = new Mocks(this._core);
4845
this._alertsApi = new Alerts(this._core);
4946
this._aboutApi = new About(this._core);
5047
this._routesApi = new Routes(this._core);
5148
this._routesVariantsApi = new RoutesVariants(this._core);
49+
5250
core.addSetting({
5351
name: ADMIN_API_PATH_OPTION,
5452
type: "string",
5553
description: `Api path for ${PLUGIN_NAME}`,
5654
default: DEFAULT_BASE_PATH,
5755
});
5856

59-
core.addSetting({
60-
name: ADMIN_API_DEPRECATED_PATHS_OPTION,
61-
type: "boolean",
62-
description: `Disable deprecated paths of ${PLUGIN_NAME}`,
63-
default: true,
64-
});
65-
6657
this._onChangeSettings = this._onChangeSettings.bind(this);
6758
}
6859

@@ -71,21 +62,19 @@ class Plugin {
7162
}
7263

7364
init() {
74-
this._deprecatedApi.init();
65+
this._legacyApi.init();
7566
this._initRouter();
7667
}
7768

7869
start() {
7970
this._stopListeningOnChangeSettings = this._core.onChangeSettings(this._onChangeSettings);
80-
this._addDeprecatedRouter();
8171
this._addRouter();
8272
}
8373

8474
stop() {
8575
if (this._stopListeningOnChangeSettings) {
8676
this._stopListeningOnChangeSettings();
8777
}
88-
this._removeDeprecatedRouter();
8978
this._removeRouter();
9079
}
9180

@@ -97,24 +86,7 @@ class Plugin {
9786
this._router.use(MOCKS, this._mocksApi.router);
9887
this._router.use(ROUTES, this._routesApi.router);
9988
this._router.use(ROUTES_VARIANTS, this._routesVariantsApi.router);
100-
}
101-
102-
_addDeprecatedRouter() {
103-
this._removeDeprecatedRouter();
104-
if (
105-
this._settings.get(ADMIN_API_DEPRECATED_PATHS_OPTION) === true &&
106-
!this._addedDeprecatedRouter
107-
) {
108-
this._core.addRouter(LEGACY, this._deprecatedApi.router);
109-
this._addedDeprecatedRouter = true;
110-
}
111-
}
112-
113-
_removeDeprecatedRouter() {
114-
if (this._addedDeprecatedRouter) {
115-
this._core.removeRouter(LEGACY, this._deprecatedApi.router);
116-
this._addedDeprecatedRouter = false;
117-
}
89+
this._router.use(LEGACY, this._legacyApi.router);
11890
}
11991

12092
_addRouter() {
@@ -131,9 +103,6 @@ class Plugin {
131103
}
132104

133105
_onChangeSettings(newSettings) {
134-
if (newSettings.hasOwnProperty(ADMIN_API_DEPRECATED_PATHS_OPTION)) {
135-
this._addDeprecatedRouter();
136-
}
137106
if (newSettings.hasOwnProperty(ADMIN_API_PATH_OPTION)) {
138107
this._addRouter();
139108
}

src/deprecated/Api.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,36 @@ Unless required by applicable law or agreed to in writing, software distributed
1010
*/
1111

1212
const express = require("express");
13-
const { DEFAULT_BASE_PATH, BEHAVIORS, FIXTURES } = require("@mocks-server/admin-api-paths");
13+
const {
14+
DEFAULT_BASE_PATH,
15+
BEHAVIORS,
16+
FIXTURES,
17+
LEGACY,
18+
} = require("@mocks-server/admin-api-paths");
1419

1520
const Behaviors = require("./Behaviors");
1621
const Fixtures = require("./Fixtures");
1722

18-
const { DEPRECATED_API_PATH, PLUGIN_NAME } = require("../constants");
23+
const { PLUGIN_NAME } = require("../constants");
1924

2025
// TODO, deprecate mocks router
2126

2227
class Api {
23-
constructor(core) {
28+
constructor(core, { addAlert }) {
2429
this._core = core;
2530
this._tracer = core.tracer;
31+
this._addAlert = addAlert;
2632
}
2733

2834
init() {
2935
const behaviorsRouter = new Behaviors(this._core).router;
3036
const fixturesRouter = new Fixtures(this._core).router;
3137
this._router = express.Router();
3238
this._router.use((req, res, next) => {
33-
this._core.tracer.deprecationWarn(
34-
`"${DEPRECATED_API_PATH}" ${PLUGIN_NAME} path`,
35-
DEFAULT_BASE_PATH
36-
);
39+
this._addAlert("legacy", `Detected usage of deprecated api path "${LEGACY}"`);
40+
this._core.tracer.deprecationWarn(`"${LEGACY}" ${PLUGIN_NAME} path`, DEFAULT_BASE_PATH);
3741
next();
3842
});
39-
4043
this._router.use(FIXTURES, fixturesRouter);
4144
this._router.use(BEHAVIORS, behaviorsRouter);
4245
}

0 commit comments

Comments
 (0)