Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Correct the profile of cache layer schema for Canner Persistence Store #276

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/build/src/lib/schema-parser/schemaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class SchemaParser {
for await (const schemaData of this.schemaReader.readSchema()) {
const schema = await this.parseContent(schemaData);
schema.metadata = metadata?.[schema.templateSource || schema.sourceName];
schema.urlPath = `/api${schema.urlPath}`
// execute middleware
await execute(schema);
schemas.push(schema as APISchema);
Expand Down
2 changes: 1 addition & 1 deletion packages/catalog-server/utils/vulcanSQLAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class VulcanSQLAdapter {
return isParam
? result.replace(param, filter[key])
: `${result}${querySymbol}${key}=${filter[key]}`;
}, schema.urlPath);
}, `/api${schema.urlPath}`);

const actualUrl = `${VULCAN_SQL_HOST}${actualPath}`;
console.log('actualUrl: ', actualUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ export class CannerPersistenceStore extends PersistentStore {
merged.templates[workspaceSourceName] = value;
});
// API Schemas
const profile = `canner-${workspaceSqlName}`;
artifact.schemas.forEach((schema) => {
// concat the workspace sql name prefix to urlPath, urlPath has the "/" prefix, so concat directly
schema.urlPath = `${workspaceSqlName}${schema.urlPath}`;
// concat the workspace sql name prefix to template source, so it could find the "sourceName" in templates
schema.templateSource = `${workspaceSqlName}/${schema.templateSource}`;
// replace the profile to the canner enterprise integration used profile name, it will match to the profiles from canner profile reader.
schema.profiles = [`canner-${workspaceSqlName}`];
schema.profiles = [profile];
schema.cache =
schema.cache?.map((cacheData) => ({ ...cacheData, profile })) || [];

merged.schemas.push(schema);
});
// Specs, only support the oas3 specification for canner enterprise integration used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as sinon from 'ts-sinon';
import faker from '@faker-js/faker';
import * as oas3 from 'openapi3-ts';
import { BaseStorageService } from '@canner/canner-storage';
import { APISchema, ArtifactBuilderOptions } from '@vulcan-sql/core';
import {
APISchema,
ArtifactBuilderOptions,
CacheLayerInfo,
} from '@vulcan-sql/core';
import * as storageServiceModule from '../lib/storageService';
import {
BuiltInArtifact,
Expand Down Expand Up @@ -160,6 +164,12 @@ describe('Test CannerPersistenceStore', () => {
urlPath: '/orders',
templateSource: 'sales/orders',
profiles: [faker.word.noun()],
cache: [
{
...sinon.stubInterface<CacheLayerInfo>(),
profile: faker.lorem.word(),
},
],
},
],
specs: {
Expand All @@ -184,6 +194,7 @@ describe('Test CannerPersistenceStore', () => {
urlPath: '/products/:id',
templateSource: 'marketing/products',
profiles: [faker.word.noun()],
cache: [],
},
],
specs: {
Expand Down Expand Up @@ -213,11 +224,17 @@ describe('Test CannerPersistenceStore', () => {
urlPath: `${fakeWorkspaces.ws1.sqlName}/orders`,
templateSource: `${fakeWorkspaces.ws1.sqlName}/sales/orders`,
profiles: [`canner-${fakeWorkspaces.ws1.sqlName}`],
cache: [
{
profile: `canner-${fakeWorkspaces.ws1.sqlName}`,
},
],
},
{
urlPath: `${fakeWorkspaces.ws2.sqlName}/products/:id`,
templateSource: `${fakeWorkspaces.ws2.sqlName}/marketing/products`,
profiles: [`canner-${fakeWorkspaces.ws2.sqlName}`],
cache: [],
},
],
specs: {
Expand Down
4 changes: 2 additions & 2 deletions packages/serve/src/lib/catalog-router/catalogRouters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CatalogRouters extends CatalogRouter {
const baseUrl = `${ctx.protocol}://${ctx.host}`;
const result = {
...schema,
url: `${baseUrl}${schema.urlPath}`,
url: `${baseUrl}/api${schema.urlPath}`,
apiDocUrl: `${baseUrl}${this.getAPIDocUrl(schema)}`,
shareKey: this.getShareKey(ctx.request.headers.authorization),
responseFormat: responseFormatOption.enabled
Expand All @@ -60,7 +60,7 @@ export class CatalogRouters extends CatalogRouter {
const result = schemas.map((schema) => {
return {
...schema,
url: `${baseUrl}${schema.urlPath}`,
url: `${baseUrl}/api${schema.urlPath}`,
apiDocUrl: `${baseUrl}${this.getAPIDocUrl(schema)}`,
shareKey: this.getShareKey(ctx.request.headers.authorization),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class RestfulRoute extends BaseRoute {
constructor(options: RouteOptions) {
super(options);
const { apiSchema } = options;
this.urlPath = apiSchema.urlPath;
this.urlPath = this.combineURLs('/api', apiSchema.urlPath);
}

public async respond(ctx: KoaContext) {
Expand Down
2 changes: 1 addition & 1 deletion packages/serve/test/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ describe('Test vulcan server for calling restful APIs', () => {
.listen(faker.datatype.number({ min: 20000, max: 30000 }));

// arrange input api url
const apiUrl = KoaRouter.url(schema.urlPath, ctx.params);
const apiUrl = KoaRouter.url('/api' + schema.urlPath, ctx.params);

// arrange expected result
const expected: RequestParameters = {};
Expand Down