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

openapi-client-axios

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-client-axios - npm Package Compare versions

Comparing version 6.1.5 to 7.0.0

13

client.d.ts
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import RefParser from '@anttiviljami/json-schema-ref-parser';
import { Document, Operation, UnknownOperationMethod, OperationMethodArguments, UnknownOperationMethods, RequestConfig, UnknownPathsDictionary, Server } from './types/client';

@@ -41,3 +40,2 @@ /**

axiosConfigDefaults: AxiosRequestConfig;
swaggerParserOpts: RefParser.Options;
private defaultServer;

@@ -63,3 +61,2 @@ private baseURLVariables;

axiosConfigDefaults?: AxiosRequestConfig;
swaggerParserOpts?: RefParser.Options;
withServer?: number | string | Server;

@@ -101,4 +98,6 @@ baseURLVariables?: {

/**
* Loads the input document asynchronously and sets this.document
* Loads document from inputDocument
*
* Supports loading from a string (url) or an object (json)
*
* @memberof OpenAPIClientAxios

@@ -110,3 +109,3 @@ */

*
* Note: Only works when the input definition is a valid OpenAPI v3 object and doesn't contain remote $refs.
* Note: Only works when the input definition is a valid OpenAPI v3 object (URLs are not supported)
*

@@ -117,2 +116,6 @@ * @memberof OpenAPIClientAxios

/**
* Creates a new axios instance with defaults and returns it
*/
getAxiosInstance: () => AxiosInstance;
/**
* Creates a new axios instance, extends it and returns it

@@ -119,0 +122,0 @@ *

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

};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -93,6 +112,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var bath_es5_1 = __importDefault(require("bath-es5"));
var json_schema_ref_parser_1 = __importDefault(require("@anttiviljami/json-schema-ref-parser"));
var dereference_1 = __importDefault(require("@anttiviljami/json-schema-ref-parser/lib/dereference"));
var options_1 = __importDefault(require("@anttiviljami/json-schema-ref-parser/lib/options"));
var copy_anything_1 = require("copy-anything");
var dereference_json_schema_1 = require("dereference-json-schema");
var client_1 = require("./types/client");

@@ -143,30 +159,9 @@ var DefaultRunnerKey = 'default';

this.init = function () { return __awaiter(_this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!this.quick) return [3 /*break*/, 2];
// to save time, just dereference input document
_a = this;
return [4 /*yield*/, json_schema_ref_parser_1.default.dereference(this.inputDocument, this.swaggerParserOpts)];
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.loadDocument()];
case 1:
// to save time, just dereference input document
_a.definition = (_c.sent());
// in quick mode no guarantees document will be the original document
this.document = typeof this.inputDocument === 'object' ? this.inputDocument : this.definition;
return [3 /*break*/, 5];
case 2:
// load and parse the document
return [4 /*yield*/, this.loadDocument()];
case 3:
// load and parse the document
_c.sent();
_a.sent();
// dereference the document into definition
_b = this;
return [4 /*yield*/, json_schema_ref_parser_1.default.dereference((0, copy_anything_1.copy)(this.document), this.swaggerParserOpts)];
case 4:
// dereference the document into definition
_b.definition = (_c.sent());
_c.label = 5;
case 5:
this.definition = (0, dereference_json_schema_1.dereferenceSync)(this.document);
// create axios instance

@@ -183,3 +178,3 @@ this.instance = this.createAxiosInstance();

*
* Note: Only works when the input definition is a valid OpenAPI v3 object and doesn't contain remote $refs.
* Note: Only works when the input definition is a valid OpenAPI v3 object (URLs are not supported)
*

@@ -195,7 +190,3 @@ * @memberof OpenAPIClientAxios

// dereference the document into definition
_this.definition = (0, copy_anything_1.copy)(_this.document);
var parser = new json_schema_ref_parser_1.default();
parser.parse(_this.definition);
parser.schema = _this.definition;
(0, dereference_1.default)(parser, new options_1.default(_this.swaggerParserOpts)); // mutates this.definition (synchronous)
_this.definition = (0, dereference_json_schema_1.dereferenceSync)(_this.document);
// create axios instance

@@ -208,2 +199,9 @@ _this.instance = _this.createAxiosInstance();

/**
* Creates a new axios instance with defaults and returns it
*/
this.getAxiosInstance = function () {
var instance = axios_1.default.create(_this.axiosConfigDefaults);
return instance;
};
/**
* Creates a new axios instance, extends it and returns it

@@ -216,3 +214,3 @@ *

// create axios instance
var instance = axios_1.default.create(_this.axiosConfigDefaults);
var instance = _this.getAxiosInstance();
// set baseURL to the one found in the definition servers (if not set in axios defaults)

@@ -646,7 +644,6 @@ var baseURL = _this.getBaseURL();

};
var optsWithDefaults = __assign(__assign({ quick: false, withServer: 0, baseURLVariables: {}, swaggerParserOpts: {}, transformOperationName: function (operationId) { return operationId; }, transformOperationMethod: function (operationMethod) { return operationMethod; }, axiosRunner: function (axiosConfig) { return _this.client.request(axiosConfig); }, applyMethodCommonHeaders: false }, opts), { axiosConfigDefaults: __assign({}, (opts.axiosConfigDefaults || {})) });
var optsWithDefaults = __assign(__assign({ quick: false, withServer: 0, baseURLVariables: {}, transformOperationName: function (operationId) { return operationId; }, transformOperationMethod: function (operationMethod) { return operationMethod; }, axiosRunner: function (axiosConfig) { return _this.client.request(axiosConfig); }, applyMethodCommonHeaders: false }, opts), { axiosConfigDefaults: __assign({}, (opts.axiosConfigDefaults || {})) });
this.inputDocument = optsWithDefaults.definition;
this.quick = optsWithDefaults.quick;
this.axiosConfigDefaults = optsWithDefaults.axiosConfigDefaults;
this.swaggerParserOpts = optsWithDefaults.swaggerParserOpts;
this.defaultServer = optsWithDefaults.withServer;

@@ -681,4 +678,6 @@ this.baseURLVariables = optsWithDefaults.baseURLVariables;

/**
* Loads the input document asynchronously and sets this.document
* Loads document from inputDocument
*
* Supports loading from a string (url) or an object (json)
*
* @memberof OpenAPIClientAxios

@@ -688,11 +687,32 @@ */

return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
var client, documentRes, yaml, err;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a = this;
return [4 /*yield*/, json_schema_ref_parser_1.default.parse(this.inputDocument, this.swaggerParserOpts)];
if (!(typeof this.inputDocument === 'object')) return [3 /*break*/, 1];
this.document = this.inputDocument;
return [3 /*break*/, 6];
case 1:
_a.document = (_b.sent());
return [2 /*return*/, this.document];
client = this.getAxiosInstance();
return [4 /*yield*/, client.get(this.inputDocument)
// set document
];
case 2:
documentRes = _a.sent();
if (!(typeof documentRes.data === 'object')) return [3 /*break*/, 3];
// json response
this.document = documentRes.data;
return [3 /*break*/, 6];
case 3:
if (!(typeof documentRes.data === 'string' && documentRes.headers['content-type'] === 'application/yaml')) return [3 /*break*/, 5];
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('js-yaml')); })];
case 4:
yaml = _a.sent();
this.document = yaml.load(documentRes.data);
return [3 /*break*/, 6];
case 5:
err = new Error("Invalid fesponse fetching OpenAPI definition: ".concat(documentRes));
err.response = documentRes;
throw err;
case 6: return [2 /*return*/, this.document];
}

@@ -699,0 +719,0 @@ });

{
"name": "openapi-client-axios",
"description": "JavaScript client library for consuming OpenAPI-enabled APIs with axios. Types included.",
"version": "6.1.5",
"version": "7.0.0",
"author": "Viljami Kuosmanen <viljami@viljami.io>",

@@ -46,5 +46,4 @@ "funding": "https://github.com/sponsors/anttiviljami",

"dependencies": {
"@anttiviljami/json-schema-ref-parser": "^9.2.2",
"bath-es5": "^3.0.3",
"copy-anything": "^3.0.2",
"dereference-json-schema": "^0.1.1",
"openapi-types": "^12.0.2"

@@ -55,2 +54,3 @@ },

"@types/jest": "^29.2.2",
"@types/js-yaml": "^4.0.5",
"@types/json-schema": "^7.0.6",

@@ -63,2 +63,3 @@ "axios": "^1.1.3",

"json-schema-deref-sync": "^0.14.0",
"msw": "^1.0.1",
"openapi-types": "^12.0.2",

@@ -79,3 +80,3 @@ "prettier": "^2.7.1",

},
"gitHead": "a780e5258435af2ae03e60cdaec34ae5fe5658a4"
"gitHead": "fc357ffefd65b9500a50b98489059d28df90389b"
}

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