Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const initPublicApiSwagger = (app: ExpressKit) => {
const swaggerOptions = {
url: jsonPath,
validatorUrl: null,
tagsSorter: 'alpha',
operationsSorter: 'alpha',
};

app.express.use(
Expand Down
11 changes: 11 additions & 0 deletions src/shared/components/public-api/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const registeredComponents = new Set<string>();

export const registerComponentId = (id: string): string => {
if (registeredComponents.has(id)) {
throw new Error(`OpenAPI component ${id} is already registered`);
}

registeredComponents.add(id);

return id;
};
35 changes: 34 additions & 1 deletion src/shared/schema/gateway-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const VALIDATION_SCHEMA_KEY = Symbol('$schema');
const registerValidationSchema = <T extends object>(value: T, schema: TypedActionSchema): T => {
Object.defineProperty(value, VALIDATION_SCHEMA_KEY, {
value: schema,
enumerable: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because default is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

configurable: true,
});

return value;
Expand Down Expand Up @@ -62,6 +62,39 @@ export const createTypedAction = <TOutput, TParams, TTransformed = TOutput>(
return registerValidationSchema(actionConfig, schemaValidationObject);
};

export const createExtendedTypedAction =
<TConfigOutput, TConfigParams, TConfigTransformed = TConfigOutput>(
actionConfig: ApiServiceActionConfig<
AppContext,
Request,
Response,
TConfigOutput,
TConfigParams,
TConfigTransformed
>,
) =>
<TResult extends TConfigTransformed, TParams extends TConfigParams>(schema: {
resultSchema: z.ZodType<TResult>;
paramsSchema: z.ZodType<TParams>;
}) => {
const schemaValidationObject = {
paramsSchema: schema.paramsSchema,
resultSchema: schema.resultSchema,
};

return registerValidationSchema(
actionConfig as unknown as ApiServiceActionConfig<
AppContext,
Request,
Response,
TConfigOutput,
TParams,
TResult
>,
schemaValidationObject,
);
};

type AuthArgsData = {
userAccessToken?: string;
serviceUserAccessToken?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/schema/mix/schemas/ql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const deleteQLChartResultSchema = z.object({});

export const getQLChartArgsSchema = z.strictObject({
chartId: z.string(),
workbookId: z.union([z.string(), z.null()]).optional(),
workbookId: z.string().nullable().optional(),
revId: z.string().optional(),
includePermissions: z.boolean().optional(),
includeLinks: z.boolean().optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/shared/schema/mix/schemas/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const deleteWizardChartResultSchema = z.object({});

export const getWizardChartArgsSchema = z.strictObject({
chartId: z.string(),
workbookId: z.union([z.string(), z.null()]).optional(),
workbookId: z.string().nullable().optional(),
revId: z.string().optional(),
includePermissions: z.boolean().optional(),
includeLinks: z.boolean().optional(),
Expand Down
8 changes: 7 additions & 1 deletion src/shared/schema/us/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const editorActions = {
path: () => `${PATH_PREFIX}/entries`,
params: (
{
version,
type,
key,
data,
Expand All @@ -31,6 +32,7 @@ export const editorActions = {
) => {
return {
body: {
version,
scope: 'widget',
type,
key,
Expand All @@ -52,9 +54,13 @@ export const editorActions = {
method: 'POST',
path: ({entryId}) => `${PATH_PREFIX}/entries/${filterUrlFragment(entryId)}`,

params: ({data, mode, revId, meta = {}, links, annotation, description = ''}, headers) => {
params: (
{version, data, mode, revId, meta = {}, links, annotation, description = ''},
headers,
) => {
return {
body: {
version,
mode,
meta,
data,
Expand Down
2 changes: 0 additions & 2 deletions src/shared/schema/us/schemas/entries/list-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const listDirectoryArgsSchema = z.object({
page: z.number().optional(),
pageSize: z.number().optional(),
includePermissionsInfo: z.boolean().optional(),
// Broken in US controller
// ignoreWorkbookEntries: z.boolean().optional(),
});

export const listDirectoryBreadCrumbSchema = z.object({
Expand Down
2 changes: 2 additions & 0 deletions src/shared/schema/us/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface CreateEditorChartResponse extends EntryFields {
}

export interface CreateEditorChartArgs {
version?: number;
type: string;
data: EntryFieldData;
key?: string;
Expand All @@ -24,6 +25,7 @@ export interface UpdateEditorChartResponse extends EntryFields {
}

export interface UpdateEditorChartArgs {
version?: number;
entryId: string;
mode: 'save' | 'publish';
data: EntryFieldData;
Expand Down
1 change: 1 addition & 0 deletions src/shared/schema/us/types/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type EntryFieldPublishedId = null | string;

// corresponds to RETURN_COLUMNS from US
export interface EntryFields {
version?: number | null;
displayAlias?: string | null;
createdAt: string;
createdBy: string;
Expand Down
5 changes: 5 additions & 0 deletions src/shared/utils/array/assert-non-empty-array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function assertNonEmptyArray<T>(arr: T[], message?: string): asserts arr is [T, ...T[]] {
if (arr.length === 0) {
throw new Error(message ?? 'Array must not be empty!');
}
}
1 change: 1 addition & 0 deletions src/shared/utils/array/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {assertNonEmptyArray} from './assert-non-empty-array';
Loading