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

Feature: Define Artifact and Validator contracts #2

Merged
merged 1 commit into from
May 3, 2022
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
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './lib/core';
export * from './models';
export * from './validators';
57 changes: 57 additions & 0 deletions packages/core/src/models/artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
=== Schema Sample Format ===
name: user
url: /user/:id
request:
parameters:
id:
in: query # path / query / header
description: user id
validators:
- name: Date
args:
format: 'yyyy-MM-dd'
- name: required
error:
- code: Forbidden
message: 'You are not allowed to access this resource'
*/

export enum FieldInType {
QUERY = 'QUERY',
HEADER = 'HEADER',
}

export interface ValidatorDefinition<T = any> {
name: string;
args: T;
}

export interface RequestParameter {
fieldName: string;
// the field put in query parameter or headers
fieldIn: FieldInType;
description: string;
validators: Array<ValidatorDefinition>;
}

export interface ErrorInfo {
code: string;
message: string;
}

export interface APISchema {
// graphql operation name
operationName: string;
// restful url path
urlPath: string;
// template, could be name or path
templateSource: string;
request: Array<RequestParameter>;
errors: Array<ErrorInfo>;
response: any;
}

export interface BuiltArtifact {
apiSchemas: Array<APISchema>;
}
1 change: 1 addition & 0 deletions packages/core/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './artifact';
1 change: 1 addition & 0 deletions packages/core/src/validators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './interface';
8 changes: 8 additions & 0 deletions packages/core/src/validators/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface IValidator<T = any> {
// validator name
name: string;
// validate Schema format
validateSchema(args: T): boolean;
// validate input data
validateData(data: string, args: T): boolean;
}