Skip to content

Commit

Permalink
feat(ruleset-migrator): relax validation
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Oct 14, 2022
1 parent 9b50f88 commit 4531c84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 210 deletions.
21 changes: 18 additions & 3 deletions packages/ruleset-migrator/src/transformers/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@ import { builders as b, namedTypes } from 'ast-types';
import { Transformer, TransformerCtx } from '../types';
import { assertArray, assertString } from '../validation';

import schema from '../validation/schema';

const ALIASES: Record<string, string> = {
'json-schema-2019-09': 'json-schema-draft-2019-09',
'json-schema-2020-12': 'json-schema-draft-2020-12',
};

const FORMATS = [
'oas2',
'oas3',
'oas3.0',
'oas3.1',
'asyncapi2',
'json-schema',
'json-schema-loose',
'json-schema-draft4',
'json-schema-draft6',
'json-schema-draft7',
'json-schema-draft-2019-09',
'json-schema-2019-09',
'json-schema-draft-2020-12',
'json-schema-2020-12',
];

const REPLACEMENTS = Object.fromEntries(
schema.properties.formats.items.enum.map(format => [
FORMATS.map(format => [
format,
(ALIASES[format] ?? format)
.replace(/\.|(?<=[0-9])-(?=[0-9])/g, '_')
Expand Down
55 changes: 0 additions & 55 deletions packages/ruleset-migrator/src/validation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,6 @@ const schema = {
properties: {
aliases: {
type: 'object',
additionalProperties: {
oneOf: [
{
type: 'array',
items: {
type: 'string',
},
},
{
type: 'object',
properties: {
description: {
type: 'string',
},
targets: {
type: 'array',
minItems: 1,
items: {
type: 'object',
properties: {
formats: {
$ref: '#/properties/formats',
},
given: {
type: 'array',
items: {
type: 'string',
},
},
},
required: ['formats', 'given'],
},
},
},
required: ['targets'],
},
],
},
},
except: {
type: 'object',
Expand Down Expand Up @@ -85,25 +47,8 @@ const schema = {
},
formats: {
type: 'array',
minItems: 1,
items: {
type: 'string',
enum: [
'oas2',
'oas3',
'oas3.0',
'oas3.1',
'asyncapi2',
'json-schema',
'json-schema-loose',
'json-schema-draft4',
'json-schema-draft6',
'json-schema-draft7',
'json-schema-draft-2019-09',
'json-schema-2019-09',
'json-schema-draft-2020-12',
'json-schema-2020-12',
],
},
},
functions: {
Expand Down
155 changes: 3 additions & 152 deletions packages/ruleset-migrator/src/validation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,166 +2,17 @@

export interface Ruleset {
aliases?: {
[k: string]:
| string[]
| {
description?: string;
targets: [
{
formats: [
(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
),
...(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
)[]
];
given: string[];
[k: string]: unknown;
},
...{
formats: [
(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
),
...(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
)[]
];
given: string[];
[k: string]: unknown;
}[]
];
[k: string]: unknown;
};
[k: string]: unknown;
};
except?: {
[k: string]: string[];
};
extends?: string | (string | [string, 'all' | 'recommended' | 'off'])[];
formats?: [
(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
),
...(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
)[]
];
formats?: string[];
functions?: string[];
functionsDir?: string;
rules?: {
formats?: [
(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
),
...(
| 'oas2'
| 'oas3'
| 'oas3.0'
| 'oas3.1'
| 'asyncapi2'
| 'json-schema'
| 'json-schema-loose'
| 'json-schema-draft4'
| 'json-schema-draft6'
| 'json-schema-draft7'
| 'json-schema-draft-2019-09'
| 'json-schema-2019-09'
| 'json-schema-draft-2020-12'
| 'json-schema-2020-12'
)[]
];
formats?: string[];
[k: string]: unknown;
};
[k: string]: unknown;
Expand Down

0 comments on commit 4531c84

Please sign in to comment.