Skip to content

Commit

Permalink
feat(ruleset-migrator): support scoped aliases (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Sep 26, 2021
1 parent 7492214 commit af58656
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
aliases: {
PathItem: '$.paths[*][*]',
Description: '$..description',
Name: '$..name',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
aliases: {
PathItem: '$.paths[*][*]',
Description: '$..description',
Name: '$..name',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aliases:
PathItem: $.paths[*][*]
Description: $..description
Name: $..name
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { oas2: oas2, oas3_0: oas3_0, oas3_1: oas3_1 } = require('@stoplight/spectral-formats');
module.exports = {
aliases: {
schema: {
description: 'Foo',
targets: [
{
formats: [oas2],
given: '$.definitions[*]',
},
{
formats: [oas3_0, oas3_1],
given: '$.components.schemas[*]',
},
],
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { oas2, oas3_0, oas3_1 } from '@stoplight/spectral-formats';
export default {
aliases: {
schema: {
description: 'Foo',
targets: [
{
formats: [oas2],
given: '$.definitions[*]',
},
{
formats: [oas3_0, oas3_1],
given: '$.components.schemas[*]',
},
],
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
aliases:
schema:
description: Foo
targets:
- formats:
- oas2
given: $.definitions[*]
- formats:
- oas3.0
- oas3.1
given: $.components.schemas[*]
1 change: 1 addition & 0 deletions packages/ruleset-migrator/src/transformers/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { transformer as default };
const transformer: Transformer = function (ctx) {
const t = transform.bind(null, ctx);

ctx.hooks.add([/^\/aliases\/[^/]+\/targets\/\d+\/formats$/, t]);
ctx.hooks.add([/^(\/overrides\/\d+)?\/formats$/, t]);
ctx.hooks.add([/^(\/overrides\/\d+)?\/rules\/[^/]+\/formats$/, t]);
};
36 changes: 36 additions & 0 deletions packages/ruleset-migrator/src/validation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,41 @@ const schema = {
$schema: 'http://json-schema.org/draft-07/schema#',
type: 'object',
properties: {
aliases: {
type: 'object',
additionalProperties: {
oneOf: [
{
type: 'string',
},
{
type: 'object',
properties: {
description: {
type: 'string',
},
targets: {
type: 'array',
minItems: 1,
items: {
type: 'object',
properties: {
formats: {
$ref: '#/properties/formats',
},
given: {
type: 'string',
},
},
required: ['formats', 'given'],
},
},
},
required: ['targets'],
},
],
},
},
except: {
type: 'object',
additionalProperties: {
Expand Down Expand Up @@ -44,6 +79,7 @@ const schema = {
},
formats: {
type: 'array',
minItems: 1,
items: {
type: 'string',
enum: [
Expand Down
164 changes: 143 additions & 21 deletions packages/ruleset-migrator/src/validation/types.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,98 @@
/*eslint-disable*/

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;
};
};
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'
)[];
functions?: string[];
functionsDir?: string;
rules?: {
formats?: (
formats?: [
(
| 'oas2'
| 'oas3'
| 'oas3.0'
Expand All @@ -39,7 +107,61 @@ export interface Ruleset {
| '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'
)[]
];
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'
)[]
];
[k: string]: unknown;
};
[k: string]: unknown;
Expand Down

0 comments on commit af58656

Please sign in to comment.