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

feat(rulesets): add oas3-server-variables rule #2526

Merged
merged 12 commits into from
Aug 29, 2023
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { createRulesetFunction } from '@stoplight/spectral-core';

import { parseUrlVariables } from './utils/parseUrlVariables';
import { getMissingProps } from './utils/getMissingProps';
import { getRedundantProps } from './utils/getRedundantProps';

import type { IFunctionResult } from '@stoplight/spectral-core';
import { parseUrlVariables } from '../../shared/functions/serverVariables/utils/parseUrlVariables';
import { getMissingProps } from '../../shared/utils/getMissingProps';
import { getRedundantProps } from '../../shared/utils/getRedundantProps';

export default createRulesetFunction<{ parameters: Record<string, unknown> }, null>(
{
Expand All @@ -26,7 +25,7 @@ export default createRulesetFunction<{ parameters: Record<string, unknown> }, nu
const parameters = parseUrlVariables(path);
if (parameters.length === 0) return;

const missingParameters = getMissingProps(parameters, targetVal.parameters);
const missingParameters = getMissingProps(parameters, Object.keys(targetVal.parameters));
if (missingParameters.length) {
results.push({
message: `Not all channel's parameters are described with "parameters" object. Missed: ${missingParameters.join(
Expand All @@ -36,7 +35,7 @@ export default createRulesetFunction<{ parameters: Record<string, unknown> }, nu
});
}

const redundantParameters = getRedundantProps(parameters, targetVal.parameters);
const redundantParameters = getRedundantProps(parameters, Object.keys(targetVal.parameters));
if (redundantParameters.length) {
redundantParameters.forEach(param => {
results.push({
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions packages/rulesets/src/asyncapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import asyncApi2MessageIdUniqueness from './functions/asyncApi2MessageIdUniquene
import asyncApi2OperationIdUniqueness from './functions/asyncApi2OperationIdUniqueness';
import asyncApi2SchemaValidation from './functions/asyncApi2SchemaValidation';
import asyncApi2PayloadValidation from './functions/asyncApi2PayloadValidation';
import asyncApi2ServerVariables from './functions/asyncApi2ServerVariables';
import serverVariables from '../shared/functions/serverVariables';
import { uniquenessTags } from '../shared/functions';
import asyncApi2Security from './functions/asyncApi2Security';
import { latestVersion } from './functions/utils/specs';
Expand Down Expand Up @@ -370,7 +370,7 @@ export default {
recommended: true,
given: ['$.servers.*', '$.components.servers.*'],
then: {
function: asyncApi2ServerVariables,
function: serverVariables,
},
},
'asyncapi-server-no-empty-variable': {
Expand Down
Loading