Skip to content

Commit

Permalink
fix(core): invalid then produced by Rule#toJSON (#2496)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Jul 7, 2023
1 parent ed6e1dc commit db91553
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ commands:
steps:
- checkout
- cached-dependencies
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
- build

jobs:
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/ruleset/__tests__/ruleset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,11 @@ describe('Ruleset', () => {
severity: DiagnosticSeverity.Warning,
then: [
{
field: 'name',
function: 'pattern',
functionOptions: 'Object{}',
functionOptions: {
match: 'Stoplight',
},
},
],
},
Expand All @@ -637,8 +640,11 @@ describe('Ruleset', () => {
severity: DiagnosticSeverity.Error,
then: [
{
field: 'description',
function: 'pattern',
functionOptions: 'Object{}',
functionOptions: {
match: 'Stoplight',
},
},
],
},
Expand All @@ -657,8 +663,11 @@ describe('Ruleset', () => {
severity: DiagnosticSeverity.Warning,
then: [
{
field: 'title',
function: 'pattern',
functionOptions: 'Object{}',
functionOptions: {
match: 'Stoplight',
},
},
],
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/ruleset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export { createRulesetFunction, SchemaDefinition as RulesetFunctionSchemaDefinit
export { Format } from './format';
export { RulesetDefinition, RuleDefinition, ParserOptions, HumanReadableDiagnosticSeverity } from './types';
export { Ruleset, StringifiedRuleset } from './ruleset';
export { Formats } from './formats';
export { Rule, StringifiedRule } from './rule';
6 changes: 2 additions & 4 deletions packages/core/src/ruleset/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { isString } from 'lodash';
import { DiagnosticSeverity, JsonPath, Optional } from '@stoplight/types';
import { dirname, relative } from '@stoplight/path';
import { pathToPointer } from '@stoplight/json';
import { printValue } from '@stoplight/spectral-runtime';

import { DEFAULT_SEVERITY_LEVEL, getDiagnosticSeverity } from './utils/severity';
import { Ruleset } from './ruleset';
Expand All @@ -29,7 +28,7 @@ export interface IRule {

type RuleJson = Omit<IRule, 'then'> & {
name: string;
then: (Pick<IRuleThen, 'field'> & { function: string; functionOptions?: string })[];
then: (Omit<IRuleThen, 'function'> & { function: string })[];
owner: number;
};

Expand Down Expand Up @@ -185,9 +184,8 @@ export class Rule implements IRule {
resolved: this.resolved,
formats: this.formats,
then: this.then.map(then => ({
...then.function,
...then,
function: then.function.name,
...('functionOptions' in then ? { functionOptions: printValue(then.functionOptions) } : null),
})),
given: Array.isArray(this.definition.given) ? this.definition.given : [this.definition.given],
owner: this.owner.id,
Expand Down

0 comments on commit db91553

Please sign in to comment.