@backstage/backend-openapi-utils 0.0.5 → 0.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/index.cjs.js +43 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +20 -2
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/backend-openapi-utils
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 785fb1ea75: Adds a new route, `/openapi.json` to validated routers for displaying their full OpenAPI spec in a standard endpoint.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 6694b369a3: Adds a new function `wrapInOpenApiTestServer` that allows for proxied requests at runtime. This will support the new `yarn backstage-repo-tools schema openapi test` command.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @backstage/backend-plugin-api@0.6.7-next.0
|
|
14
|
+
- @backstage/config@1.1.1
|
|
15
|
+
- @backstage/errors@1.2.3
|
|
16
|
+
|
|
3
17
|
## 0.0.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ export function createRouter() {
|
|
|
65
65
|
|
|
66
66
|
### Why am I getting `unknown` as the type for a response?
|
|
67
67
|
|
|
68
|
-
This can happen when you have a `charset` defined in your `response.content` section. Something like `response.content[
|
|
68
|
+
This can happen when you have a `charset` defined in your `response.content` section. Something like `response.content['application/json; charset=utf-8:']` will cause this issue.
|
|
69
69
|
|
|
70
70
|
## INTERNAL
|
|
71
71
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -6,6 +6,7 @@ var PromiseRouter = require('express-promise-router');
|
|
|
6
6
|
var express = require('express');
|
|
7
7
|
var errors = require('@backstage/errors');
|
|
8
8
|
var expressOpenapiValidator = require('express-openapi-validator');
|
|
9
|
+
var openapiMerge = require('openapi-merge');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
12
|
|
|
@@ -15,6 +16,8 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
15
16
|
__proto__: null
|
|
16
17
|
});
|
|
17
18
|
|
|
19
|
+
const OPENAPI_SPEC_ROUTE = "/openapi.json";
|
|
20
|
+
|
|
18
21
|
const baseUrlSymbol = Symbol();
|
|
19
22
|
const originalUrlSymbol = Symbol();
|
|
20
23
|
function validatorErrorTransformer() {
|
|
@@ -25,6 +28,9 @@ function validatorErrorTransformer() {
|
|
|
25
28
|
function getDefaultRouterMiddleware() {
|
|
26
29
|
return [express.json()];
|
|
27
30
|
}
|
|
31
|
+
function getOpenApiSpecRoute(baseUrl) {
|
|
32
|
+
return `${baseUrl}${OPENAPI_SPEC_ROUTE}`;
|
|
33
|
+
}
|
|
28
34
|
function createValidatedOpenApiRouter(spec, options) {
|
|
29
35
|
const router = PromiseRouter__default["default"]();
|
|
30
36
|
router.use((options == null ? void 0 : options.middleware) || getDefaultRouterMiddleware());
|
|
@@ -57,9 +63,46 @@ function createValidatedOpenApiRouter(spec, options) {
|
|
|
57
63
|
next();
|
|
58
64
|
});
|
|
59
65
|
router.use(validatorErrorTransformer());
|
|
66
|
+
router.get(OPENAPI_SPEC_ROUTE, async (req, res) => {
|
|
67
|
+
const mergeOutput = openapiMerge.merge([
|
|
68
|
+
{
|
|
69
|
+
oas: spec,
|
|
70
|
+
pathModification: {
|
|
71
|
+
/**
|
|
72
|
+
* Get the route that this OpenAPI spec is hosted on. The other
|
|
73
|
+
* approach of using the discovery API increases the router constructor
|
|
74
|
+
* significantly and since we're just looking for path and not full URL,
|
|
75
|
+
* this works.
|
|
76
|
+
*
|
|
77
|
+
* If we wanted to add a list of servers, there may be a case for adding
|
|
78
|
+
* discovery API to get an exhaustive list of upstream servers, but that's
|
|
79
|
+
* also not currently supported.
|
|
80
|
+
*/
|
|
81
|
+
prepend: req.originalUrl.replace(OPENAPI_SPEC_ROUTE, "")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
if (openapiMerge.isErrorResult(mergeOutput)) {
|
|
86
|
+
throw new errors.InputError("Invalid spec defined");
|
|
87
|
+
}
|
|
88
|
+
res.json(mergeOutput.output);
|
|
89
|
+
});
|
|
60
90
|
return router;
|
|
61
91
|
}
|
|
62
92
|
|
|
93
|
+
const wrapInOpenApiTestServer = (app) => {
|
|
94
|
+
if (process.env.OPTIC_PROXY) {
|
|
95
|
+
const server = app.listen(+process.env.PORT);
|
|
96
|
+
return {
|
|
97
|
+
...server,
|
|
98
|
+
address: () => new URL(process.env.OPTIC_PROXY)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return app;
|
|
102
|
+
};
|
|
103
|
+
|
|
63
104
|
exports.createValidatedOpenApiRouter = createValidatedOpenApiRouter;
|
|
105
|
+
exports.getOpenApiSpecRoute = getOpenApiSpecRoute;
|
|
64
106
|
exports.internal = index;
|
|
107
|
+
exports.wrapInOpenApiTestServer = wrapInOpenApiTestServer;
|
|
65
108
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/stub.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport PromiseRouter from 'express-promise-router';\nimport { ApiRouter } from './router';\nimport { RequiredDoc } from './types';\nimport {\n ErrorRequestHandler,\n RequestHandler,\n NextFunction,\n Request,\n Response,\n json,\n} from 'express';\nimport { InputError } from '@backstage/errors';\nimport { middleware as OpenApiValidator } from 'express-openapi-validator';\n\ntype PropertyOverrideRequest = Request & {\n [key: symbol]: string;\n};\n\nconst baseUrlSymbol = Symbol();\nconst originalUrlSymbol = Symbol();\n\nfunction validatorErrorTransformer(): ErrorRequestHandler {\n return (error: Error, _: Request, _2: Response, next: NextFunction) => {\n next(new InputError(error.message));\n };\n}\n\nexport function getDefaultRouterMiddleware() {\n return [json()];\n}\n\n/**\n * Create a new OpenAPI router with some default middleware.\n * @param spec - Your OpenAPI spec imported as a JSON object.\n * @param validatorOptions - `openapi-express-validator` options to override the defaults.\n * @returns A new express router with validation middleware.\n * @public\n */\nexport function createValidatedOpenApiRouter<T extends RequiredDoc>(\n spec: T,\n options?: {\n validatorOptions?: Partial<Parameters<typeof OpenApiValidator>['0']>;\n middleware?: RequestHandler[];\n },\n) {\n const router = PromiseRouter() as ApiRouter<typeof spec>;\n router.use(options?.middleware || getDefaultRouterMiddleware());\n\n /**\n * Middleware to setup the routing for OpenApiValidator. OpenApiValidator expects `req.originalUrl`\n * and `req.baseUrl` to be the full path. We adjust them here to basically be nothing and then\n * revive the old values in the last function in this method. We could instead update `req.path`\n * but that might affect the routing and I'd rather not.\n *\n * TODO: I opened https://github.com/cdimascio/express-openapi-validator/issues/843\n * to track this on the middleware side, but there was a similar ticket, https://github.com/cdimascio/express-openapi-validator/issues/113\n * that has had minimal activity. If that changes, update this to use a new option on their side.\n */\n router.use((req: Request, _, next) => {\n /**\n * Express typings are weird. They don't recognize PropertyOverrideRequest as a valid\n * Request child and try to overload as PathParams. Just cast it here, since we know\n * what we're doing.\n */\n const customRequest = req as PropertyOverrideRequest;\n customRequest[baseUrlSymbol] = customRequest.baseUrl;\n customRequest.baseUrl = '';\n customRequest[originalUrlSymbol] = customRequest.originalUrl;\n customRequest.originalUrl = customRequest.url;\n next();\n });\n\n // TODO: Handle errors by converting from OpenApiValidator errors to known @backstage/errors errors.\n router.use(\n OpenApiValidator({\n validateRequests: {\n coerceTypes: false,\n allowUnknownQueryParameters: false,\n },\n ignoreUndocumented: true,\n validateResponses: false,\n ...options?.validatorOptions,\n apiSpec: spec as any,\n }),\n );\n\n /**\n * Revert `req.baseUrl` and `req.originalUrl` changes. This ensures that any further usage\n * of these variables will be unchanged.\n */\n router.use((req: Request, _, next) => {\n const customRequest = req as PropertyOverrideRequest;\n customRequest.baseUrl = customRequest[baseUrlSymbol];\n customRequest.originalUrl = customRequest[originalUrlSymbol];\n delete customRequest[baseUrlSymbol];\n delete customRequest[originalUrlSymbol];\n next();\n });\n\n // Any errors from the middleware get through here.\n router.use(validatorErrorTransformer());\n\n return router;\n}\n"],"names":["InputError","json","PromiseRouter","OpenApiValidator"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,MAAM,gBAAgB,MAAO,EAAA,CAAA;AAC7B,MAAM,oBAAoB,MAAO,EAAA,CAAA;AAEjC,SAAS,yBAAiD,GAAA;AACxD,EAAA,OAAO,CAAC,KAAA,EAAc,CAAY,EAAA,EAAA,EAAc,IAAuB,KAAA;AACrE,IAAA,IAAA,CAAK,IAAIA,iBAAA,CAAW,KAAM,CAAA,OAAO,CAAC,CAAA,CAAA;AAAA,GACpC,CAAA;AACF,CAAA;AAEO,SAAS,0BAA6B,GAAA;AAC3C,EAAO,OAAA,CAACC,cAAM,CAAA,CAAA;AAChB,CAAA;AASgB,SAAA,4BAAA,CACd,MACA,OAIA,EAAA;AACA,EAAA,MAAM,SAASC,iCAAc,EAAA,CAAA;AAC7B,EAAA,MAAA,CAAO,GAAI,CAAA,CAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAS,UAAc,KAAA,0BAAA,EAA4B,CAAA,CAAA;AAY9D,EAAA,MAAA,CAAO,GAAI,CAAA,CAAC,GAAc,EAAA,CAAA,EAAG,IAAS,KAAA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ts","../src/testUtils.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The route that all OpenAPI specs should be served from.\n * @public\n */\nexport const OPENAPI_SPEC_ROUTE = '/openapi.json';\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport PromiseRouter from 'express-promise-router';\nimport { ApiRouter } from './router';\nimport { RequiredDoc } from './types';\nimport {\n ErrorRequestHandler,\n RequestHandler,\n NextFunction,\n Request,\n Response,\n json,\n} from 'express';\nimport { InputError } from '@backstage/errors';\nimport { middleware as OpenApiValidator } from 'express-openapi-validator';\nimport { OPENAPI_SPEC_ROUTE } from './constants';\nimport { isErrorResult, merge } from 'openapi-merge';\n\ntype PropertyOverrideRequest = Request & {\n [key: symbol]: string;\n};\n\nconst baseUrlSymbol = Symbol();\nconst originalUrlSymbol = Symbol();\n\nfunction validatorErrorTransformer(): ErrorRequestHandler {\n return (error: Error, _: Request, _2: Response, next: NextFunction) => {\n next(new InputError(error.message));\n };\n}\n\nexport function getDefaultRouterMiddleware() {\n return [json()];\n}\n\n/**\n * Given a base url for a plugin, find the given OpenAPI spec for that plugin.\n * @param baseUrl - Plugin base url.\n * @returns OpenAPI spec route for the base url.\n * @public\n */\nexport function getOpenApiSpecRoute(baseUrl: string) {\n return `${baseUrl}${OPENAPI_SPEC_ROUTE}`;\n}\n\n/**\n * Create a new OpenAPI router with some default middleware.\n * @param spec - Your OpenAPI spec imported as a JSON object.\n * @param validatorOptions - `openapi-express-validator` options to override the defaults.\n * @returns A new express router with validation middleware.\n * @public\n */\nexport function createValidatedOpenApiRouter<T extends RequiredDoc>(\n spec: T,\n options?: {\n validatorOptions?: Partial<Parameters<typeof OpenApiValidator>['0']>;\n middleware?: RequestHandler[];\n },\n) {\n const router = PromiseRouter();\n router.use(options?.middleware || getDefaultRouterMiddleware());\n\n /**\n * Middleware to setup the routing for OpenApiValidator. OpenApiValidator expects `req.originalUrl`\n * and `req.baseUrl` to be the full path. We adjust them here to basically be nothing and then\n * revive the old values in the last function in this method. We could instead update `req.path`\n * but that might affect the routing and I'd rather not.\n *\n * TODO: I opened https://github.com/cdimascio/express-openapi-validator/issues/843\n * to track this on the middleware side, but there was a similar ticket, https://github.com/cdimascio/express-openapi-validator/issues/113\n * that has had minimal activity. If that changes, update this to use a new option on their side.\n */\n router.use((req: Request, _, next) => {\n /**\n * Express typings are weird. They don't recognize PropertyOverrideRequest as a valid\n * Request child and try to overload as PathParams. Just cast it here, since we know\n * what we're doing.\n */\n const customRequest = req as PropertyOverrideRequest;\n customRequest[baseUrlSymbol] = customRequest.baseUrl;\n customRequest.baseUrl = '';\n customRequest[originalUrlSymbol] = customRequest.originalUrl;\n customRequest.originalUrl = customRequest.url;\n next();\n });\n\n // TODO: Handle errors by converting from OpenApiValidator errors to known @backstage/errors errors.\n router.use(\n OpenApiValidator({\n validateRequests: {\n coerceTypes: false,\n allowUnknownQueryParameters: false,\n },\n ignoreUndocumented: true,\n validateResponses: false,\n ...options?.validatorOptions,\n apiSpec: spec as any,\n }),\n );\n\n /**\n * Revert `req.baseUrl` and `req.originalUrl` changes. This ensures that any further usage\n * of these variables will be unchanged.\n */\n router.use((req: Request, _, next) => {\n const customRequest = req as PropertyOverrideRequest;\n customRequest.baseUrl = customRequest[baseUrlSymbol];\n customRequest.originalUrl = customRequest[originalUrlSymbol];\n delete customRequest[baseUrlSymbol];\n delete customRequest[originalUrlSymbol];\n next();\n });\n\n // Any errors from the middleware get through here.\n router.use(validatorErrorTransformer());\n\n router.get(OPENAPI_SPEC_ROUTE, async (req, res) => {\n const mergeOutput = merge([\n {\n oas: spec as any,\n pathModification: {\n /**\n * Get the route that this OpenAPI spec is hosted on. The other\n * approach of using the discovery API increases the router constructor\n * significantly and since we're just looking for path and not full URL,\n * this works.\n *\n * If we wanted to add a list of servers, there may be a case for adding\n * discovery API to get an exhaustive list of upstream servers, but that's\n * also not currently supported.\n */\n prepend: req.originalUrl.replace(OPENAPI_SPEC_ROUTE, ''),\n },\n },\n ]);\n if (isErrorResult(mergeOutput)) {\n throw new InputError('Invalid spec defined');\n }\n res.json(mergeOutput.output);\n });\n\n return router as ApiRouter<typeof spec>;\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Express } from 'express';\nimport { Server } from 'http';\n\n/**\n * !!! THIS CURRENTLY ONLY SUPPORTS SUPERTEST !!!\n * Running against supertest, we need some way to hit the optic proxy. This ensures that\n * that happens at runtime when in the context of a `yarn optic capture` command.\n * @param app - Express router that would be passed to supertest's `request`.\n * @returns A wrapper around the express router (or the router untouched) that still works with supertest.\n * @public\n */\nexport const wrapInOpenApiTestServer = (app: Express): Server | Express => {\n if (process.env.OPTIC_PROXY) {\n const server = app.listen(+process.env.PORT!);\n return {\n ...server,\n address: () => new URL(process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AC,0BAAA,CAAc,WAAW,CAAG,EAAA;AAC9B,MAAM,MAAA,IAAIL,kBAAW,sBAAsB,CAAA,CAAA;AAAA,KAC7C;AACA,IAAI,GAAA,CAAA,IAAA,CAAK,YAAY,MAAM,CAAA,CAAA;AAAA,GAC5B,CAAA,CAAA;AAED,EAAO,OAAA,MAAA,CAAA;AACT;;AClIa,MAAA,uBAAA,GAA0B,CAAC,GAAmC,KAAA;AACzE,EAAI,IAAA,OAAA,CAAQ,IAAI,WAAa,EAAA;AAC3B,IAAA,MAAM,SAAS,GAAI,CAAA,MAAA,CAAO,CAAC,OAAA,CAAQ,IAAI,IAAK,CAAA,CAAA;AAC5C,IAAO,OAAA;AAAA,MACL,GAAG,MAAA;AAAA,MACH,SAAS,MAAM,IAAI,GAAI,CAAA,OAAA,CAAQ,IAAI,WAAY,CAAA;AAAA,KACjD,CAAA;AAAA,GACF;AACA,EAAO,OAAA,GAAA,CAAA;AACT;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { JSONSchema7, FromSchema } from 'json-schema-to-ts';
|
|
2
2
|
import { ReferenceObject, OpenAPIObject, ContentObject, RequestBodyObject, ResponseObject, ParameterObject, SchemaObject } from 'openapi3-ts';
|
|
3
3
|
import core from 'express-serve-static-core';
|
|
4
|
-
import { Router, RequestHandler } from 'express';
|
|
4
|
+
import { Router, RequestHandler, Express } from 'express';
|
|
5
5
|
import { middleware } from 'express-openapi-validator';
|
|
6
|
+
import { Server } from 'http';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* This file is meant to hold Immutable overwrites of the values provided by the `openapi3-ts`
|
|
@@ -576,6 +577,13 @@ interface ApiRouter<Doc extends RequiredDoc> extends Router {
|
|
|
576
577
|
head: DocRequestMatcher<Doc, this, 'head'>;
|
|
577
578
|
}
|
|
578
579
|
|
|
580
|
+
/**
|
|
581
|
+
* Given a base url for a plugin, find the given OpenAPI spec for that plugin.
|
|
582
|
+
* @param baseUrl - Plugin base url.
|
|
583
|
+
* @returns OpenAPI spec route for the base url.
|
|
584
|
+
* @public
|
|
585
|
+
*/
|
|
586
|
+
declare function getOpenApiSpecRoute(baseUrl: string): string;
|
|
579
587
|
/**
|
|
580
588
|
* Create a new OpenAPI router with some default middleware.
|
|
581
589
|
* @param spec - Your OpenAPI spec imported as a JSON object.
|
|
@@ -588,4 +596,14 @@ declare function createValidatedOpenApiRouter<T extends RequiredDoc>(spec: T, op
|
|
|
588
596
|
middleware?: RequestHandler[];
|
|
589
597
|
}): ApiRouter<T>;
|
|
590
598
|
|
|
591
|
-
|
|
599
|
+
/**
|
|
600
|
+
* !!! THIS CURRENTLY ONLY SUPPORTS SUPERTEST !!!
|
|
601
|
+
* Running against supertest, we need some way to hit the optic proxy. This ensures that
|
|
602
|
+
* that happens at runtime when in the context of a `yarn optic capture` command.
|
|
603
|
+
* @param app - Express router that would be passed to supertest's `request`.
|
|
604
|
+
* @returns A wrapper around the express router (or the router untouched) that still works with supertest.
|
|
605
|
+
* @public
|
|
606
|
+
*/
|
|
607
|
+
declare const wrapInOpenApiTestServer: (app: Express) => Server | Express;
|
|
608
|
+
|
|
609
|
+
export { ApiRouter, CookieParameters, HeaderParameters, PathParameters, QueryParameters, Request, Response, createValidatedOpenApiRouter, getOpenApiSpecRoute, index_d as internal, wrapInOpenApiTestServer };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-openapi-utils",
|
|
3
3
|
"description": "OpenAPI typescript support.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.1.0-next.0",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -30,13 +30,15 @@
|
|
|
30
30
|
"postpack": "backstage-cli package postpack"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@backstage/cli": "^0.
|
|
33
|
+
"@backstage/cli": "^0.24.0-next.0",
|
|
34
34
|
"supertest": "^6.1.3"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@backstage/backend-plugin-api": "^0.6.7-next.0",
|
|
41
|
+
"@backstage/config": "^1.1.1",
|
|
40
42
|
"@backstage/errors": "^1.2.3",
|
|
41
43
|
"@types/express": "^4.17.6",
|
|
42
44
|
"@types/express-serve-static-core": "^4.17.5",
|
|
@@ -45,6 +47,7 @@
|
|
|
45
47
|
"express-promise-router": "^4.1.0",
|
|
46
48
|
"json-schema-to-ts": "^2.6.2",
|
|
47
49
|
"lodash": "^4.17.21",
|
|
50
|
+
"openapi-merge": "^1.3.2",
|
|
48
51
|
"openapi3-ts": "^3.1.2"
|
|
49
52
|
},
|
|
50
53
|
"module": "dist/index.esm.js"
|