Merge pull request #24779 from davidfestal/restore-external-config-schema-support
fix(app-backend): restore external config schema support
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-app-backend': patch
|
||||
---
|
||||
|
||||
Restore the support of external config schema in the router of the `app-backend` plugin, which was broken in release `1.26.0`.
|
||||
This support is critical for dynamic frontend plugins to have access to their config values.
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"backstageConfigSchemaVersion": 1,
|
||||
"schemas": []
|
||||
}
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import express from 'express';
|
||||
import Router from 'express-promise-router';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import request from 'supertest';
|
||||
import { createRouter } from './router';
|
||||
import { loadConfigSchema } from '@backstage/config-loader';
|
||||
|
||||
jest.mock('../lib/config', () => ({
|
||||
injectConfig: jest.fn(),
|
||||
@@ -115,3 +116,75 @@ describe('createRouter with static fallback handler', () => {
|
||||
expect(response3.status).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createRouter config schema test', () => {
|
||||
const libConfigs = require('../lib/config');
|
||||
const libConfigsActual = jest.requireActual('../lib/config');
|
||||
const readConfigsMock: jest.Mock = libConfigs.readConfigs;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
readConfigsMock.mockImplementation(libConfigsActual.readConfigs);
|
||||
});
|
||||
|
||||
it('uses an external schema', async () => {
|
||||
await createRouter({
|
||||
logger: getVoidLogger(),
|
||||
config: new ConfigReader({
|
||||
test: 'value',
|
||||
}),
|
||||
appPackageName: 'example-app',
|
||||
schema: await loadConfigSchema({
|
||||
serialized: {
|
||||
schemas: [
|
||||
{
|
||||
value: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
test: {
|
||||
visibility: 'frontend',
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
path: '/mock',
|
||||
},
|
||||
],
|
||||
backstageConfigSchemaVersion: 1,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const results = readConfigsMock.mock.results;
|
||||
expect(results.length).toBe(1);
|
||||
|
||||
const mockedResult = results[0];
|
||||
expect(mockedResult.type).toBe('return');
|
||||
const result = await (mockedResult.value as Promise<AppConfig[]>);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].data).toStrictEqual({
|
||||
test: 'value',
|
||||
});
|
||||
});
|
||||
|
||||
it('uses no external schema', async () => {
|
||||
await createRouter({
|
||||
logger: getVoidLogger(),
|
||||
config: new ConfigReader({
|
||||
test: 'value',
|
||||
}),
|
||||
appPackageName: 'example-app',
|
||||
});
|
||||
|
||||
const results = readConfigsMock.mock.results;
|
||||
expect(results.length).toBe(1);
|
||||
|
||||
const mockedResult = results[0];
|
||||
expect(mockedResult.type).toBe('return');
|
||||
const result = await (mockedResult.value as Promise<AppConfig[]>);
|
||||
|
||||
expect(result.length).toBe(1);
|
||||
expect(result[0].data).toStrictEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,6 +113,7 @@ export async function createRouter(
|
||||
staticFallbackHandler,
|
||||
auth,
|
||||
httpAuth,
|
||||
schema,
|
||||
} = options;
|
||||
|
||||
const disableConfigInjection =
|
||||
@@ -143,6 +144,7 @@ export async function createRouter(
|
||||
config,
|
||||
appDistDir,
|
||||
env: process.env,
|
||||
schema,
|
||||
});
|
||||
|
||||
const assetStore =
|
||||
|
||||
Reference in New Issue
Block a user