Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.d.ts 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. This is type definition for typescript.
  3. This is for library users. Thus, properties and methods for internal use is omitted.
  4. */
  5. export declare class Validator {
  6. constructor();
  7. customFormats: {[formatName: string]: CustomFormat};
  8. schemas: {[id: string]: Schema};
  9. unresolvedRefs: string[];
  10. attributes: {[property: string]: CustomProperty};
  11. addSchema(schema?: Schema, uri?: string): Schema|void;
  12. validate(instance: any, schema: Schema, options?: Options, ctx?: SchemaContext): ValidatorResult;
  13. }
  14. export declare class ValidatorResult {
  15. constructor(instance: any, schema: Schema, options: Options, ctx: SchemaContext)
  16. instance: any;
  17. schema: Schema;
  18. propertyPath: string;
  19. errors: ValidationError[];
  20. throwError: boolean;
  21. disableFormat: boolean;
  22. valid: boolean;
  23. addError(detail: string|ErrorDetail): ValidationError;
  24. toString(): string;
  25. }
  26. export declare class ValidationError {
  27. constructor(message?: string, instance?: any, schema?: Schema, propertyPath?: any, name?: string, argument?: any);
  28. property: string;
  29. message: string;
  30. schema: string|Schema;
  31. instance: any;
  32. name: string;
  33. argument: any;
  34. toString(): string;
  35. }
  36. export declare class SchemaError extends Error{
  37. constructor(msg: string, schema: Schema);
  38. schema: Schema;
  39. message: string;
  40. }
  41. export declare function validate(instance: any, schema: any, options?: Options): ValidatorResult
  42. export interface Schema {
  43. id?: string
  44. $schema?: string
  45. $ref?: string
  46. title?: string
  47. description?: string
  48. multipleOf?: number
  49. maximum?: number
  50. exclusiveMaximum?: boolean
  51. minimum?: number
  52. exclusiveMinimum?: boolean
  53. maxLength?: number
  54. minLength?: number
  55. pattern?: string
  56. additionalItems?: boolean | Schema
  57. items?: Schema | Schema[]
  58. maxItems?: number
  59. minItems?: number
  60. uniqueItems?: boolean
  61. maxProperties?: number
  62. minProperties?: number
  63. required?: string[]
  64. additionalProperties?: boolean | Schema
  65. definitions?: {
  66. [name: string]: Schema
  67. }
  68. properties?: {
  69. [name: string]: Schema
  70. }
  71. patternProperties?: {
  72. [name: string]: Schema
  73. }
  74. dependencies?: {
  75. [name: string]: Schema | string[]
  76. }
  77. 'enum'?: any[]
  78. type?: string | string[]
  79. format?: string
  80. allOf?: Schema[]
  81. anyOf?: Schema[]
  82. oneOf?: Schema[]
  83. not?: Schema
  84. }
  85. export interface Options {
  86. skipAttributes?: string[];
  87. allowUnknownAttributes?: boolean;
  88. rewrite?: RewriteFunction;
  89. propertyName?: string;
  90. base?: string;
  91. throwError?: boolean;
  92. }
  93. export interface RewriteFunction {
  94. (instance: any, schema: Schema, options: Options, ctx: SchemaContext): any;
  95. }
  96. export interface SchemaContext {
  97. schema: Schema;
  98. options: Options;
  99. propertyPath: string;
  100. base: string;
  101. schemas: {[base: string]: Schema};
  102. }
  103. export interface CustomFormat {
  104. (input: any): boolean;
  105. }
  106. export interface CustomProperty {
  107. (instance: any, schema: Schema, options: Options, ctx: SchemaContext): string|ValidatorResult;
  108. }
  109. export interface ErrorDetail {
  110. message: string;
  111. name: string;
  112. argument: string;
  113. }