Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@redocly/openapi-core

Package Overview
Dependencies
Maintainers
9
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redocly/openapi-core - npm Package Compare versions

Comparing version 1.18.0 to 1.18.1

10

CHANGELOG.md
# @redocly/openapi-core
## 1.18.1
### Patch Changes
- Allowed the `theme.openapi` configuration option to accept settings specific to Redoc 2.x and earlier.
- Fixed an issue in the OpenAPI `spec` rule where `dependentSchemas` was parsed as an array.
It is now correctly parsed as a map.
- Fixed bundling of `$refs` inside `patternProperties`.
- Updated AsyncAPI v2 typings to abide by JSON Schema draft-07 specification.
## 1.18.0

@@ -4,0 +14,0 @@

2

lib/bundle.d.ts

@@ -50,2 +50,2 @@ import { BaseResolver } from './resolve';

}): Promise<BundleResult>;
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "parameters" | "examples" | "headers" | "schemas" | "responses" | "requestBodies" | "securitySchemes" | "links" | "callbacks" | null;
export declare function mapTypeToComponent(typeName: string, version: SpecMajorVersion): "definitions" | "links" | "responses" | "parameters" | "examples" | "headers" | "schemas" | "requestBodies" | "securitySchemes" | "callbacks" | null;

@@ -13,3 +13,2 @@ "use strict";

exports.mapTypeToComponent = exports.bundleDocument = exports.bundleFromString = exports.bundle = exports.bundleConfig = exports.OasVersion = void 0;
const isEqual = require("lodash.isequal");
const resolve_1 = require("./resolve");

@@ -336,3 +335,3 @@ const visitors_1 = require("./visitors");

}
return isEqual(node, target.node);
return (0, utils_1.dequal)(node, target.node);
}

@@ -339,0 +338,0 @@ function getComponentName(target, componentType, ctx) {

import { Config } from './config';
import { BaseResolver } from '../resolve';
import type { Document } from '../resolve';
import type { Document, ResolvedRefMap } from '../resolve';
import type { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
import type { RawConfig, RawUniversalConfig, Region } from './types';
import type { ResolvedRefMap } from '../resolve';
export type RawConfigProcessor = (params: {

@@ -8,0 +7,0 @@ document: Document;

@@ -32,2 +32,2 @@ import { Oas3Rule, Oas3Preprocessor, Oas2Rule, Oas2Preprocessor, Async2Preprocessor, Async2Rule, ArazzoPreprocessor, ArazzoRule } from './visitors';

export declare function getMajorSpecVersion(version: SpecVersion): SpecMajorVersion;
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "WebhooksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems" | "DependentRequired", import("./types").NodeType>;
export declare function getTypes(spec: SpecVersion): Record<string, import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Parameter" | "Operation" | "Example" | "Header" | "Responses" | "Response" | "Schema" | "Xml" | "SchemaProperties" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedSecuritySchemes" | "SecurityScheme" | "Examples" | "ExamplesMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "ParameterItems" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "XServer" | "XServerList", import("./types").NodeType> | Record<"Root" | "Tag" | "ExternalDocs" | "Server" | "ServerVariable" | "SecurityRequirement" | "Info" | "Contact" | "License" | "Paths" | "PathItem" | "Callback" | "CallbacksMap" | "Parameter" | "Operation" | "RequestBody" | "MediaTypesMap" | "MediaType" | "Example" | "Encoding" | "Header" | "Responses" | "Response" | "Link" | "Schema" | "Xml" | "SchemaProperties" | "DiscriminatorMapping" | "Discriminator" | "Components" | "NamedSchemas" | "NamedResponses" | "NamedParameters" | "NamedExamples" | "NamedRequestBodies" | "NamedHeaders" | "NamedSecuritySchemes" | "NamedLinks" | "NamedCallbacks" | "ImplicitFlow" | "PasswordFlow" | "ClientCredentials" | "AuthorizationCode" | "OAuth2Flows" | "SecurityScheme" | "ServerVariablesMap" | "ExamplesMap" | "EncodingMap" | "HeadersMap" | "LinksMap" | "TagList" | "SecurityRequirementList" | "ParameterList" | "TagGroup" | "TagGroups" | "EnumDescriptions" | "Logo" | "XCodeSample" | "XCodeSampleList" | "ServerList" | "XUsePkce" | "WebhooksMap", import("./types").NodeType> | Record<"Root" | "Info" | "License" | "Operation" | "Schema" | "SchemaProperties" | "Components" | "SecurityScheme" | "NamedPathItems" | "DependentRequired", import("./types").NodeType>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PathSegmentPlural = void 0;
const pluralize = require("pluralize");
const utils_1 = require("../../utils");

@@ -20,3 +21,3 @@ const PathSegmentPlural = (opts) => {

continue;
if (!(0, utils_1.isPathParameter)(pathSegment) && (0, utils_1.isSingular)(pathSegment)) {
if (!(0, utils_1.isPathParameter)(pathSegment) && pluralize.isSingular(pathSegment)) {
report({

@@ -23,0 +24,0 @@ message: `path segment \`${pathSegment}\` should be plural.`,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArazzoTypes = exports.arazzoSchema = exports.ARAZZO_ROOT_TYPE = void 0;
exports.ArazzoTypes = exports.arazzoSchema = exports.workflow = exports.step = exports.inherit = exports.criteriaObject = exports.requestBody = exports.replacement = exports.infoObject = exports.parameter = exports.sourceDescriptionSchema = exports.expectSchema = exports.operationMethod = exports.ARAZZO_ROOT_TYPE = void 0;
const json_schema_adapter_1 = require("./json-schema-adapter");
exports.ARAZZO_ROOT_TYPE = 'Root';
const operationMethod = {
exports.operationMethod = {
type: 'string',
enum: ['get', 'post', 'put', 'delete', 'patch'],
};
const expectSchema = {
exports.expectSchema = {
type: 'object',

@@ -60,3 +60,3 @@ properties: {

};
const sourceDescriptionSchema = {
exports.sourceDescriptionSchema = {
type: 'object',

@@ -71,3 +71,3 @@ oneOf: [

type: 'array',
items: sourceDescriptionSchema,
items: exports.sourceDescriptionSchema,
};

@@ -78,3 +78,3 @@ const extendedOperation = {

path: { type: 'string' },
method: operationMethod,
method: exports.operationMethod,
sourceDescriptionName: { type: 'string' },

@@ -86,3 +86,3 @@ serverUrl: { type: 'string' },

};
const parameter = {
exports.parameter = {
type: 'object',

@@ -105,13 +105,2 @@ oneOf: [

properties: {
$ref: { type: 'string' },
value: {
oneOf: [{ type: 'string' }, { type: 'number' }, { type: 'boolean' }],
},
},
required: ['$ref'],
additionalProperties: false,
},
{
type: 'object',
properties: {
reference: { type: 'string' },

@@ -129,5 +118,5 @@ value: {

type: 'array',
items: parameter,
items: exports.parameter,
};
const infoObject = {
exports.infoObject = {
type: 'object',

@@ -143,3 +132,3 @@ properties: {

};
const replacement = {
exports.replacement = {
type: 'object',

@@ -159,3 +148,3 @@ properties: {

};
const requestBody = {
exports.requestBody = {
type: 'object',

@@ -176,3 +165,3 @@ properties: {

type: 'array',
items: replacement,
items: exports.replacement,
},

@@ -183,3 +172,3 @@ },

};
const criteriaObject = {
exports.criteriaObject = {
type: 'object',

@@ -214,5 +203,5 @@ properties: {

type: 'array',
items: criteriaObject,
items: exports.criteriaObject,
};
const inherit = {
exports.inherit = {
type: 'string',

@@ -255,3 +244,3 @@ enum: ['auto', 'none'],

};
const step = {
exports.step = {
type: 'object',

@@ -271,10 +260,26 @@ properties: {

additionalProperties: {
type: 'string',
oneOf: [
{
type: 'string',
},
{
type: 'object',
},
{
type: 'array',
},
{
type: 'boolean',
},
{
type: 'number',
},
],
},
},
'x-inherit': inherit,
'x-expect': expectSchema,
'x-inherit': exports.inherit,
'x-expect': exports.expectSchema,
'x-assert': { type: 'string' },
'x-operation': extendedOperation,
requestBody: requestBody,
requestBody: exports.requestBody,
},

@@ -291,3 +296,3 @@ required: ['stepId'],

type: 'array',
items: step,
items: exports.step,
};

@@ -317,3 +322,3 @@ const JSONSchema = {

};
const workflow = {
exports.workflow = {
type: 'object',

@@ -348,3 +353,3 @@ properties: {

type: 'array',
items: workflow,
items: exports.workflow,
};

@@ -355,3 +360,3 @@ exports.arazzoSchema = {

arazzo: { type: 'string', enum: ['1.0.0'] },
info: infoObject,
info: exports.infoObject,
sourceDescriptions: sourceDescriptionsSchema,

@@ -382,3 +387,3 @@ 'x-parameters': parameters,

type: 'object',
additionalProperties: parameter,
additionalProperties: exports.parameter,
},

@@ -385,0 +390,0 @@ successActions: {

@@ -311,7 +311,4 @@ "use strict";

$id: { type: 'string' },
id: { type: 'string' },
$schema: { type: 'string' },
definitions: 'NamedSchemas',
$defs: 'NamedSchemas',
$vocabulary: { type: 'string' },
externalDocs: 'ExternalDocs',

@@ -337,13 +334,10 @@ discriminator: 'Discriminator',

type: (value) => {
if (Array.isArray(value)) {
return {
return Array.isArray(value)
? {
type: 'array',
items: { enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'] },
};
}
else {
return {
}
: {
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
};
}
},

@@ -357,34 +351,8 @@ allOf: (0, _1.listOf)('Schema'),

else: 'Schema',
dependentSchemas: (0, _1.listOf)('Schema'),
prefixItems: (0, _1.listOf)('Schema'),
contains: 'Schema',
minContains: { type: 'integer', minimum: 0 },
maxContains: { type: 'integer', minimum: 0 },
patternProperties: { type: 'object' },
propertyNames: 'Schema',
unevaluatedItems: (value) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
else {
return 'Schema';
}
},
unevaluatedProperties: (value) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
else {
return 'Schema';
}
},
summary: { type: 'string' },
properties: 'SchemaProperties',
items: (value) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
else {
return 'Schema';
}
return Array.isArray(value) ? (0, _1.listOf)('Schema') : 'Schema';
},

@@ -401,3 +369,2 @@ additionalProperties: (value) => {

writeOnly: { type: 'boolean' },
// xml: 'Xml',
examples: { type: 'array' },

@@ -408,3 +375,6 @@ example: { isExample: true },

$comment: { type: 'string' },
dependencies: { type: 'object' }, // TODO
additionalItems: (value) => {
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
},
dependencies: 'Dependencies',
},

@@ -415,6 +385,3 @@ };

additionalProperties: (value) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
return 'Schema';
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
},

@@ -561,2 +528,8 @@ };

};
const Dependencies = {
properties: {},
additionalProperties: (value) => {
return Array.isArray(value) ? { type: 'array', items: { type: 'string' } } : 'Schema';
},
};
// --- Per-protocol node types

@@ -1035,2 +1008,3 @@ // http

CorrelationId,
Dependencies,
};

@@ -131,3 +131,3 @@ "use strict";

else: 'Schema',
dependentSchemas: (0, _1.listOf)('Schema'),
dependentSchemas: (0, _1.mapOf)('Schema'),
dependentRequired: 'DependentRequired',

@@ -138,3 +138,3 @@ prefixItems: (0, _1.listOf)('Schema'),

maxContains: { type: 'integer', minimum: 0 },
patternProperties: { type: 'object' },
patternProperties: 'SchemaProperties',
propertyNames: 'Schema',

@@ -141,0 +141,0 @@ unevaluatedItems: (value) => {

import type { FromSchema } from 'json-schema-to-ts';
import type { arazzoSchema } from '../types/arazzo';
import type { arazzoSchema, parameter, operationMethod, expectSchema, sourceDescriptionSchema, infoObject, requestBody, replacement, inherit, criteriaObject, step, workflow } from '../types/arazzo';
export type ArazzoDefinition = FromSchema<typeof arazzoSchema>;
export type OperationMethod = FromSchema<typeof operationMethod>;
export type ResponseContext = {
statusCode: number;
body: any;
headers: Headers;
mimeType: string;
} & Record<string, any>;
export type Expect = FromSchema<typeof expectSchema>;
export type SourceDescription = FromSchema<typeof sourceDescriptionSchema>;
export type Parameter = FromSchema<typeof parameter>;
export type InfoObject = FromSchema<typeof infoObject>;
export type RequestBody = FromSchema<typeof requestBody>;
export type Replacement = FromSchema<typeof replacement>;
export type Inherit = FromSchema<typeof inherit>;
export type CriteriaObject = FromSchema<typeof criteriaObject>;
export type VerboseLog = {
method: OperationMethod;
path: string;
host: string;
body?: any;
headerParams?: Record<string, string>;
statusCode?: number;
};
export type Step = FromSchema<typeof step>;
export type Workflow = FromSchema<typeof workflow> & {
steps: Step[];
};

@@ -1,4 +0,4 @@

import { UserContext } from './walk';
import { HttpResolveConfig } from './config';
import { HttpsProxyAgent } from 'https-proxy-agent';
import type { HttpResolveConfig } from './config';
import type { UserContext } from './walk';
export { parseYaml, stringifyYaml } from './js-yaml';

@@ -31,3 +31,2 @@ export type StackFrame<T> = {

export declare function validateMimeTypeOAS3({ type, value }: any, { report, location }: UserContext, allowedValues: string[]): void;
export declare function isSingular(path: string): boolean;
export declare function readFileAsStringSync(filePath: string): string;

@@ -54,4 +53,9 @@ export declare function yamlAndJsonSyncReader<T>(filePath: string): T;

export declare function pickDefined<T extends Record<string, unknown>>(obj?: T): Record<string, unknown> | undefined;
export declare function nextTick(): void;
export declare function nextTick(): Promise<unknown>;
export declare function pause(ms: number): Promise<void>;
export declare function getProxyAgent(): HttpsProxyAgent<string> | undefined;
/**
* Checks if two objects are deeply equal.
* Borrowed the source code from https://github.com/lukeed/dequal.
*/
export declare function dequal(foo: any, bar: any): boolean;

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getProxyAgent = exports.pause = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.isSingular = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
exports.dequal = exports.getProxyAgent = exports.pause = exports.nextTick = exports.pickDefined = exports.keysOf = exports.identity = exports.isTruthy = exports.showErrorForDeprecatedField = exports.showWarningForDeprecatedField = exports.doesYamlFileExist = exports.isCustomRuleId = exports.getMatchingStatusCodeRange = exports.assignExisting = exports.isNotString = exports.isString = exports.isNotEmptyObject = exports.slash = exports.isPathParameter = exports.yamlAndJsonSyncReader = exports.readFileAsStringSync = exports.validateMimeTypeOAS3 = exports.validateMimeType = exports.splitCamelCaseIntoWords = exports.omitObjectProps = exports.pickObjectProps = exports.readFileFromUrl = exports.isEmptyArray = exports.isEmptyObject = exports.isPlainObject = exports.isDefined = exports.loadYaml = exports.popStack = exports.pushStack = exports.stringifyYaml = exports.parseYaml = void 0;
const fs = require("fs");

@@ -18,3 +18,2 @@ const path_1 = require("path");

const node_fetch_1 = require("node-fetch");
const pluralize = require("pluralize");
const js_yaml_1 = require("./js-yaml");

@@ -137,6 +136,2 @@ const env_1 = require("./env");

exports.validateMimeTypeOAS3 = validateMimeTypeOAS3;
function isSingular(path) {
return pluralize.isSingular(path);
}
exports.isSingular = isSingular;
function readFileAsStringSync(filePath) {

@@ -239,3 +234,3 @@ return fs.readFileSync(filePath, 'utf-8');

function nextTick() {
new Promise((resolve) => {
return new Promise((resolve) => {
setTimeout(resolve);

@@ -259,1 +254,37 @@ });

exports.getProxyAgent = getProxyAgent;
/**
* Checks if two objects are deeply equal.
* Borrowed the source code from https://github.com/lukeed/dequal.
*/
function dequal(foo, bar) {
let ctor, len;
if (foo === bar)
return true;
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
if (ctor === Date)
return foo.getTime() === bar.getTime();
if (ctor === RegExp)
return foo.toString() === bar.toString();
if (ctor === Array) {
if ((len = foo.length) === bar.length) {
while (len-- && dequal(foo[len], bar[len]))
;
}
return len === -1;
}
if (!ctor || typeof foo === 'object') {
len = 0;
for (ctor in foo) {
if (Object.prototype.hasOwnProperty.call(foo, ctor) &&
++len &&
!Object.prototype.hasOwnProperty.call(bar, ctor))
return false;
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
return false;
}
return Object.keys(bar).length === len;
}
}
return foo !== foo && bar !== bar;
}
exports.dequal = dequal;
{
"name": "@redocly/openapi-core",
"version": "1.18.0",
"version": "1.18.1",
"description": "",

@@ -39,3 +39,3 @@ "main": "lib/index.js",

"@redocly/ajv": "^8.11.0",
"@redocly/config": "^0.6.2",
"@redocly/config": "^0.7.0",
"colorette": "^1.2.0",

@@ -42,0 +42,0 @@ "https-proxy-agent": "^7.0.4",

@@ -107,10 +107,2 @@ import * as path from 'path';

basic:
type: BASIC
credentials:
- teams:
- 789 # Must be a string
- correct
# username: Must be reported as a missing required prop
sso:

@@ -401,16 +393,2 @@ - WRONG # Does not match allowed options

{
"pointer": "#/theme/openapi/showConsole",
"reportOnKey": true,
"source": "",
},
],
"message": "Property \`showConsole\` is not expected here.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/theme/openapi/layout",

@@ -921,30 +899,2 @@ "reportOnKey": false,

{
"pointer": "#/ssoOnPrem/basic/credentials/0",
"reportOnKey": true,
"source": "",
},
],
"message": "The field \`username\` must be present on this level.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/ssoOnPrem/basic/credentials/0/teams/0",
"reportOnKey": false,
"source": "",
},
],
"message": "Expected type \`string\` but got \`integer\`.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/developerOnboarding/wrong",

@@ -951,0 +901,0 @@ "reportOnKey": true,

@@ -1,2 +0,1 @@

import isEqual = require('lodash.isequal');
import { BaseResolver, resolveDocument, makeRefId, makeDocumentFromString } from './resolve';

@@ -16,3 +15,3 @@ import { normalizeVisitors } from './visitors';

import { reportUnresolvedRef } from './rules/no-unresolved-refs';
import { isPlainObject, isTruthy } from './utils';
import { dequal, isPlainObject, isTruthy } from './utils';
import { isRedoclyRegistryURL } from './redocly/domains';

@@ -450,3 +449,3 @@ import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './decorators/oas2/remove-unused-components';

return isEqual(node, target.node);
return dequal(node, target.node);
}

@@ -453,0 +452,0 @@

@@ -13,6 +13,5 @@ import * as fs from 'fs';

import type { Document } from '../resolve';
import type { Document, ResolvedRefMap } from '../resolve';
import type { RegionalToken, RegionalTokenWithValidity } from '../redocly/redocly-client-types';
import type { RawConfig, RawUniversalConfig, Region } from './types';
import type { ResolvedRefMap } from '../resolve';
import { DOMAINS } from '../redocly/domains';

@@ -19,0 +18,0 @@

@@ -610,2 +610,49 @@ import { outdent } from 'outdent';

});
it('should flag invalid dependentSchemas', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.1.0
info:
version: 1.0.0
title: Example.com
description: info,
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
components:
schemas:
withInvalidDependentSchemas:
dependentSchemas:
- invalid1
- invalid2
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ spec: 'error' }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"from": undefined,
"location": [
{
"pointer": "#/components/schemas/withInvalidDependentSchemas/dependentSchemas",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Expected type \`SchemaMap\` (object) but got \`array\`",
"ruleId": "spec",
"severity": "error",
"suggest": [],
},
]
`);
});
});

@@ -1,5 +0,6 @@

import { UserContext } from '../../walk';
import { Oas3_1Schema } from '../../typings/openapi';
import { getAdditionalPropertiesOption, validateExample } from '../utils';
import type { UserContext } from '../../walk';
import type { Oas3_1Schema } from '../../typings/openapi';
export const NoInvalidSchemaExamples: any = (opts: any) => {

@@ -6,0 +7,0 @@ const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;

@@ -0,4 +1,5 @@

import * as pluralize from 'pluralize';
import { Oas3Rule, Oas2Rule } from '../../visitors';
import { UserContext } from '../../walk';
import { isPathParameter, isSingular } from '../../utils';
import { isPathParameter } from '../../utils';

@@ -20,3 +21,3 @@ export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {

if (exceptions && exceptions.includes(pathSegment)) continue;
if (!isPathParameter(pathSegment) && isSingular(pathSegment)) {
if (!isPathParameter(pathSegment) && pluralize.isSingular(pathSegment)) {
report({

@@ -23,0 +24,0 @@ message: `path segment \`${pathSegment}\` should be plural.`,

@@ -7,7 +7,7 @@ import type { NodeType } from '.';

const operationMethod = {
export const operationMethod = {
type: 'string',
enum: ['get', 'post', 'put', 'delete', 'patch'],
} as const;
const expectSchema = {
export const expectSchema = {
type: 'object',

@@ -62,3 +62,3 @@ properties: {

} as const;
const sourceDescriptionSchema = {
export const sourceDescriptionSchema = {
type: 'object',

@@ -86,3 +86,3 @@ oneOf: [

} as const;
const parameter = {
export const parameter = {
type: 'object',

@@ -105,13 +105,2 @@ oneOf: [

properties: {
$ref: { type: 'string' },
value: {
oneOf: [{ type: 'string' }, { type: 'number' }, { type: 'boolean' }],
},
},
required: ['$ref'],
additionalProperties: false,
},
{
type: 'object',
properties: {
reference: { type: 'string' },

@@ -131,3 +120,3 @@ value: {

} as const;
const infoObject = {
export const infoObject = {
type: 'object',

@@ -143,3 +132,3 @@ properties: {

} as const;
const replacement = {
export const replacement = {
type: 'object',

@@ -159,3 +148,3 @@ properties: {

} as const;
const requestBody = {
export const requestBody = {
type: 'object',

@@ -182,3 +171,3 @@ properties: {

} as const;
const criteriaObject = {
export const criteriaObject = {
type: 'object',

@@ -215,3 +204,3 @@ properties: {

} as const;
const inherit = {
export const inherit = {
type: 'string',

@@ -254,3 +243,3 @@ enum: ['auto', 'none'],

} as const;
const step = {
export const step = {
type: 'object',

@@ -270,3 +259,19 @@ properties: {

additionalProperties: {
type: 'string',
oneOf: [
{
type: 'string',
},
{
type: 'object',
},
{
type: 'array',
},
{
type: 'boolean',
},
{
type: 'number',
},
],
},

@@ -315,3 +320,3 @@ },

} as const;
const workflow = {
export const workflow = {
type: 'object',

@@ -318,0 +323,0 @@ properties: {

@@ -337,7 +337,4 @@ import { NodeType, listOf, mapOf } from '.';

$id: { type: 'string' },
id: { type: 'string' },
$schema: { type: 'string' },
definitions: 'NamedSchemas',
$defs: 'NamedSchemas',
$vocabulary: { type: 'string' },
externalDocs: 'ExternalDocs',

@@ -363,12 +360,10 @@ discriminator: 'Discriminator',

type: (value: any) => {
if (Array.isArray(value)) {
return {
type: 'array',
items: { enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'] },
};
} else {
return {
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
};
}
return Array.isArray(value)
? {
type: 'array',
items: { enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'] },
}
: {
enum: ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null'],
};
},

@@ -382,31 +377,8 @@ allOf: listOf('Schema'),

else: 'Schema',
dependentSchemas: listOf('Schema'),
prefixItems: listOf('Schema'),
contains: 'Schema',
minContains: { type: 'integer', minimum: 0 },
maxContains: { type: 'integer', minimum: 0 },
patternProperties: { type: 'object' },
propertyNames: 'Schema',
unevaluatedItems: (value: unknown) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
} else {
return 'Schema';
}
},
unevaluatedProperties: (value: unknown) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
} else {
return 'Schema';
}
},
summary: { type: 'string' },
properties: 'SchemaProperties',
items: (value: any) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
} else {
return 'Schema';
}
return Array.isArray(value) ? listOf('Schema') : 'Schema';
},

@@ -423,3 +395,2 @@ additionalProperties: (value: any) => {

writeOnly: { type: 'boolean' },
// xml: 'Xml',
examples: { type: 'array' },

@@ -430,3 +401,6 @@ example: { isExample: true },

$comment: { type: 'string' },
dependencies: { type: 'object' }, // TODO
additionalItems: (value: any) => {
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
},
dependencies: 'Dependencies',
},

@@ -438,6 +412,3 @@ };

additionalProperties: (value: any) => {
if (typeof value === 'boolean') {
return { type: 'boolean' };
}
return 'Schema';
return typeof value === 'boolean' ? { type: 'boolean' } : 'Schema';
},

@@ -593,2 +564,9 @@ };

const Dependencies: NodeType = {
properties: {},
additionalProperties: (value: any) => {
return Array.isArray(value) ? { type: 'array', items: { type: 'string' } } : 'Schema';
},
};
// --- Per-protocol node types

@@ -1143,2 +1121,3 @@

CorrelationId,
Dependencies,
};

@@ -136,3 +136,3 @@ import { listOf, mapOf } from '.';

else: 'Schema',
dependentSchemas: listOf('Schema'),
dependentSchemas: mapOf('Schema'),
dependentRequired: 'DependentRequired',

@@ -143,3 +143,3 @@ prefixItems: listOf('Schema'),

maxContains: { type: 'integer', minimum: 0 },
patternProperties: { type: 'object' },
patternProperties: 'SchemaProperties',
propertyNames: 'Schema',

@@ -146,0 +146,0 @@ unevaluatedItems: (value: unknown) => {

import type { FromSchema } from 'json-schema-to-ts';
import type { arazzoSchema } from '../types/arazzo';
import type {
arazzoSchema,
parameter,
operationMethod,
expectSchema,
sourceDescriptionSchema,
infoObject,
requestBody,
replacement,
inherit,
criteriaObject,
step,
workflow,
} from '../types/arazzo';
export type ArazzoDefinition = FromSchema<typeof arazzoSchema>;
export type OperationMethod = FromSchema<typeof operationMethod>;
export type ResponseContext = {
statusCode: number;
body: any;
headers: Headers;
mimeType: string;
} & Record<string, any>;
export type Expect = FromSchema<typeof expectSchema>;
export type SourceDescription = FromSchema<typeof sourceDescriptionSchema>;
export type Parameter = FromSchema<typeof parameter>;
export type InfoObject = FromSchema<typeof infoObject>;
export type RequestBody = FromSchema<typeof requestBody>;
export type Replacement = FromSchema<typeof replacement>;
export type Inherit = FromSchema<typeof inherit>;
export type CriteriaObject = FromSchema<typeof criteriaObject>;
export type VerboseLog = {
method: OperationMethod;
path: string;
host: string;
body?: any;
headerParams?: Record<string, string>;
statusCode?: number;
};
export type Step = FromSchema<typeof step>;
export type Workflow = FromSchema<typeof workflow> & {
steps: Step[];
};

@@ -5,10 +5,10 @@ import * as fs from 'fs';

import fetch from 'node-fetch';
import * as pluralize from 'pluralize';
import { parseYaml } from './js-yaml';
import { UserContext } from './walk';
import { env } from './env';
import { logger, colorize } from './logger';
import { HttpResolveConfig } from './config';
import { HttpsProxyAgent } from 'https-proxy-agent';
import type { HttpResolveConfig } from './config';
import type { UserContext } from './walk';
export { parseYaml, stringifyYaml } from './js-yaml';

@@ -150,6 +150,2 @@

export function isSingular(path: string) {
return pluralize.isSingular(path);
}
export function readFileAsStringSync(filePath: string) {

@@ -272,3 +268,3 @@ return fs.readFileSync(filePath, 'utf-8');

export function nextTick() {
new Promise((resolve) => {
return new Promise((resolve) => {
setTimeout(resolve);

@@ -290,1 +286,38 @@ });

}
/**
* Checks if two objects are deeply equal.
* Borrowed the source code from https://github.com/lukeed/dequal.
*/
export function dequal(foo: any, bar: any): boolean {
let ctor, len;
if (foo === bar) return true;
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
if (ctor === Date) return foo.getTime() === bar.getTime();
if (ctor === RegExp) return foo.toString() === bar.toString();
if (ctor === Array) {
if ((len = foo.length) === bar.length) {
while (len-- && dequal(foo[len], bar[len]));
}
return len === -1;
}
if (!ctor || typeof foo === 'object') {
len = 0;
for (ctor in foo) {
if (
Object.prototype.hasOwnProperty.call(foo, ctor) &&
++len &&
!Object.prototype.hasOwnProperty.call(bar, ctor)
)
return false;
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
}
return Object.keys(bar).length === len;
}
}
return foo !== foo && bar !== bar;
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc