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

@useoptic/openapi-utilities

Package Overview
Dependencies
Maintainers
4
Versions
571
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@useoptic/openapi-utilities - npm Package Compare versions

Comparing version 0.54.4 to 0.54.5

20

build/openapi3/group-diff.d.ts

@@ -57,6 +57,18 @@ import { OpenAPIV3 } from 'openapi-types';

constructor();
getOrSetEndpoint(endpointId: string): Endpoint;
getOrSetRequestBody(endpointId: string, contentType: string): Body;
getOrSetResponse(endpointId: string, statusCode: string): Response;
getOrSetResponseBody(endpointId: string, statusCode: string, contentType: string): Body;
getOrSetEndpoint(e: {
path: string;
method: string;
}): Endpoint;
getOrSetRequestBody(e: {
path: string;
method: string;
}, contentType: string): Body;
getOrSetResponse(e: {
path: string;
method: string;
}, statusCode: string): Response;
getOrSetResponseBody(e: {
path: string;
method: string;
}, statusCode: string, contentType: string): Body;
}

@@ -63,0 +75,0 @@ export declare function groupDiffsByEndpoint(specs: {

72

build/openapi3/group-diff.js

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

const id_1 = require("../utilities/id");
const openapi_traverser_1 = require("./implementations/openapi3/openapi-traverser");
function constructTree(spec) {

@@ -81,3 +82,7 @@ const traverser = new traverser_1.OpenApiV3Traverser();

}
getOrSetEndpoint(endpointId) {
getOrSetEndpoint(e) {
const endpointId = (0, id_1.getEndpointId)({
path: (0, openapi_traverser_1.normalizeOpenApiPath)(e.path),
method: e.method,
});
if (this.endpoints[endpointId]) {

@@ -87,5 +92,5 @@ return this.endpoints[endpointId];

else {
const { path, method } = (0, id_1.getPathAndMethodFromEndpointId)(endpointId);
const { path, method } = e;
const endpoint = {
method,
method: method.toUpperCase(),
path,

@@ -109,4 +114,4 @@ diffs: [],

}
getOrSetRequestBody(endpointId, contentType) {
const endpoint = this.getOrSetEndpoint(endpointId);
getOrSetRequestBody(e, contentType) {
const endpoint = this.getOrSetEndpoint(e);
if (endpoint.request.contents[contentType]) {

@@ -124,4 +129,4 @@ return endpoint.request.contents[contentType];

}
getOrSetResponse(endpointId, statusCode) {
const endpoint = this.getOrSetEndpoint(endpointId);
getOrSetResponse(e, statusCode) {
const endpoint = this.getOrSetEndpoint(e);
if (endpoint.responses[statusCode]) {

@@ -141,4 +146,4 @@ return endpoint.responses[statusCode];

}
getOrSetResponseBody(endpointId, statusCode, contentType) {
const response = this.getOrSetResponse(endpointId, statusCode);
getOrSetResponseBody(e, statusCode, contentType) {
const response = this.getOrSetResponse(e, statusCode);
if (response.contents[contentType]) {

@@ -276,4 +281,6 @@ return response.contents[contentType];

};
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({
path: pathPattern,
method,
});
endpoint.diffs.push(newDiff);

@@ -294,4 +301,6 @@ }

};
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({
path: pathPattern,
method,
});
endpoint.diffs.push(newDiff);

@@ -305,4 +314,3 @@ }

const { pathPattern, method } = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
type === 'diffs' ? endpoint.diffs.push(item) : endpoint.rules.push(item);

@@ -322,4 +330,3 @@ }

const { pathPattern, method } = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
const name = getParameterName(specToFetchFrom, fact.location.jsonPath);

@@ -342,4 +349,3 @@ if (endpoint[parameter][name]) {

const { pathPattern, method } = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
type === 'diffs'

@@ -351,4 +357,3 @@ ? endpoint.request.diffs.push(item)

const { pathPattern, method, statusCode } = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const response = grouped.getOrSetResponse(endpointId, statusCode);
const response = grouped.getOrSetResponse({ path: pathPattern, method }, statusCode);
type === 'diffs' ? response.diffs.push(item) : response.rules.push(item);

@@ -358,4 +363,3 @@ }

const { pathPattern, method, statusCode, headerName } = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({ path: pathPattern, method });
const response = grouped.getOrSetResponse(endpointId, statusCode);
const response = grouped.getOrSetResponse({ path: pathPattern, method }, statusCode);
if (response.headers[headerName]) {

@@ -380,9 +384,5 @@ type === 'diffs'

}
const endpointId = (0, id_1.getEndpointId)({
path: location.pathPattern,
method: location.method,
});
const body = location.location === 'request'
? grouped.getOrSetRequestBody(endpointId, location.contentType)
: grouped.getOrSetResponseBody(endpointId, location.statusCode, location.contentType);
? grouped.getOrSetRequestBody({ path: location.pathPattern, method: location.method }, location.contentType)
: grouped.getOrSetResponseBody({ path: location.pathPattern, method: location.method }, location.statusCode, location.contentType);
type === 'diffs'

@@ -394,9 +394,11 @@ ? body.examples.diffs.push(item)

const location = (0, traverser_1.getLocation)(fact);
const endpointId = (0, id_1.getEndpointId)({
path: location.pathPattern,
method: location.method,
});
const body = location.location === 'request'
? grouped.getOrSetRequestBody(endpointId, location.contentType)
: grouped.getOrSetResponseBody(endpointId, location.statusCode, location.contentType);
? grouped.getOrSetRequestBody({
path: location.pathPattern,
method: location.method,
}, location.contentType)
: grouped.getOrSetResponseBody({
path: location.pathPattern,
method: location.method,
}, location.statusCode, location.contentType);
let fieldKeys;

@@ -403,0 +405,0 @@ if (type === 'diffs') {

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

export declare const getPathAndMethodFromEndpointId: (endpointId: string) => {
method: string;
path: string;
};
export declare const getEndpointId: (endpoint: {

@@ -6,0 +2,0 @@ method: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEndpointId = exports.getPathAndMethodFromEndpointId = void 0;
exports.getEndpointId = void 0;
const ENDPOINT_ID_SEPARATOR = '-~_~-';
const getPathAndMethodFromEndpointId = (endpointId) => {
const [method, path] = endpointId.split(ENDPOINT_ID_SEPARATOR);
return { method, path };
};
exports.getPathAndMethodFromEndpointId = getPathAndMethodFromEndpointId;
const getEndpointId = (endpoint) => {

@@ -11,0 +6,0 @@ return `${endpoint.method.toUpperCase()}${ENDPOINT_ID_SEPARATOR}${endpoint.path}`;

@@ -5,3 +5,3 @@ {

"packageManager": "yarn@4.1.0",
"version": "0.54.4",
"version": "0.54.5",
"main": "build/index.js",

@@ -40,3 +40,3 @@ "types": "build/index.d.ts",

"dependencies": {
"@useoptic/json-pointer-helpers": "0.54.4",
"@useoptic/json-pointer-helpers": "0.54.5",
"ajv": "^8.6.0",

@@ -43,0 +43,0 @@ "ajv-errors": "~3.0.0",

@@ -11,3 +11,4 @@ import { jsonPointerHelpers } from '@useoptic/json-pointer-helpers';

import { RuleResult } from '../results';
import { getPathAndMethodFromEndpointId, getEndpointId } from '../utilities/id';
import { getEndpointId } from '../utilities/id';
import { normalizeOpenApiPath } from './implementations/openapi3/openapi-traverser';

@@ -148,9 +149,13 @@ function constructTree(spec: OpenAPIV3.Document) {

getOrSetEndpoint(endpointId: string): Endpoint {
getOrSetEndpoint(e: { path: string; method: string }): Endpoint {
const endpointId = getEndpointId({
path: normalizeOpenApiPath(e.path),
method: e.method,
});
if (this.endpoints[endpointId]) {
return this.endpoints[endpointId];
} else {
const { path, method } = getPathAndMethodFromEndpointId(endpointId);
const { path, method } = e;
const endpoint: Endpoint = {
method,
method: method.toUpperCase(),
path,

@@ -175,4 +180,7 @@ diffs: [],

getOrSetRequestBody(endpointId: string, contentType: string): Body {
const endpoint = this.getOrSetEndpoint(endpointId);
getOrSetRequestBody(
e: { path: string; method: string },
contentType: string
): Body {
const endpoint = this.getOrSetEndpoint(e);
if (endpoint.request.contents[contentType]) {

@@ -190,4 +198,7 @@ return endpoint.request.contents[contentType];

getOrSetResponse(endpointId: string, statusCode: string): Response {
const endpoint = this.getOrSetEndpoint(endpointId);
getOrSetResponse(
e: { path: string; method: string },
statusCode: string
): Response {
const endpoint = this.getOrSetEndpoint(e);

@@ -209,7 +220,7 @@ if (endpoint.responses[statusCode]) {

getOrSetResponseBody(
endpointId: string,
e: { path: string; method: string },
statusCode: string,
contentType: string
): Body {
const response = this.getOrSetResponse(endpointId, statusCode);
const response = this.getOrSetResponse(e, statusCode);
if (response.contents[contentType]) {

@@ -402,4 +413,6 @@ return response.contents[contentType];

};
const endpointId = getEndpointId({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({
path: pathPattern,
method,
});
endpoint.diffs.push(newDiff);

@@ -419,4 +432,6 @@ }

};
const endpointId = getEndpointId({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({
path: pathPattern,
method,
});
endpoint.diffs.push(newDiff);

@@ -429,4 +444,3 @@ }

const { pathPattern, method } = getLocation(fact);
const endpointId = getEndpointId({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
type === 'diffs' ? endpoint.diffs.push(item) : endpoint.rules.push(item);

@@ -448,4 +462,3 @@ } else if (

const { pathPattern, method } = getLocation(fact);
const endpointId = getEndpointId({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
const name = getParameterName(specToFetchFrom, fact.location.jsonPath);

@@ -466,4 +479,3 @@

const { pathPattern, method } = getLocation(fact);
const endpointId = getEndpointId({ path: pathPattern, method });
const endpoint = grouped.getOrSetEndpoint(endpointId);
const endpoint = grouped.getOrSetEndpoint({ path: pathPattern, method });
type === 'diffs'

@@ -474,9 +486,13 @@ ? endpoint.request.diffs.push(item)

const { pathPattern, method, statusCode } = getLocation(fact);
const endpointId = getEndpointId({ path: pathPattern, method });
const response = grouped.getOrSetResponse(endpointId, statusCode);
const response = grouped.getOrSetResponse(
{ path: pathPattern, method },
statusCode
);
type === 'diffs' ? response.diffs.push(item) : response.rules.push(item);
} else if (fact.type === 'response-header') {
const { pathPattern, method, statusCode, headerName } = getLocation(fact);
const endpointId = getEndpointId({ path: pathPattern, method });
const response = grouped.getOrSetResponse(endpointId, statusCode);
const response = grouped.getOrSetResponse(
{ path: pathPattern, method },
statusCode
);
if (response.headers[headerName]) {

@@ -502,11 +518,10 @@ type === 'diffs'

const endpointId = getEndpointId({
path: location.pathPattern,
method: location.method,
});
const body =
location.location === 'request'
? grouped.getOrSetRequestBody(endpointId, location.contentType)
? grouped.getOrSetRequestBody(
{ path: location.pathPattern, method: location.method },
location.contentType
)
: grouped.getOrSetResponseBody(
endpointId,
{ path: location.pathPattern, method: location.method },
location.statusCode,

@@ -521,11 +536,16 @@ location.contentType

const location = getLocation(fact);
const endpointId = getEndpointId({
path: location.pathPattern,
method: location.method,
});
const body =
location.location === 'request'
? grouped.getOrSetRequestBody(endpointId, location.contentType)
? grouped.getOrSetRequestBody(
{
path: location.pathPattern,
method: location.method,
},
location.contentType
)
: grouped.getOrSetResponseBody(
endpointId,
{
path: location.pathPattern,
method: location.method,
},
location.statusCode,

@@ -532,0 +552,0 @@ location.contentType

const ENDPOINT_ID_SEPARATOR = '-~_~-';
export const getPathAndMethodFromEndpointId = (
endpointId: string
): {
method: string;
path: string;
} => {
const [method, path] = endpointId.split(ENDPOINT_ID_SEPARATOR);
return { method, path };
};
export const getEndpointId = (endpoint: {

@@ -13,0 +3,0 @@ method: string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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