Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d60ff7efdf | |||
| f29623c084 | |||
| d152920692 | |||
| 5628ce6328 | |||
| a24e7c6f73 | |||
| 8d9d3f92db | |||
| cdb3c27637 | |||
| d11adfc704 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartswagger",
|
"name": "@pushrocks/smartswagger",
|
||||||
"version": "1.0.4",
|
"version": "1.0.8",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartswagger",
|
"name": "@pushrocks/smartswagger",
|
||||||
"version": "1.0.4",
|
"version": "1.0.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apidevtools/swagger-parser": "^10.0.3",
|
"@apidevtools/swagger-parser": "^10.0.3",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartswagger",
|
"name": "@pushrocks/smartswagger",
|
||||||
"version": "1.0.4",
|
"version": "1.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a swagger tookit for working with swagger files",
|
"description": "a swagger tookit for working with swagger files",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
|||||||
52
test/test.ts
52
test/test.ts
@@ -1,8 +1,58 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartswagger from '../ts/index';
|
import * as smartswagger from '../ts/index';
|
||||||
|
|
||||||
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
|
|
||||||
|
let testSmartswaggerInstance: smartswagger.Smartswagger;
|
||||||
|
let testExpressServer: smartexpress.Server;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
console.log(smartswagger.standardExport);
|
testSmartswaggerInstance = await smartswagger.Smartswagger.createFromUrl(
|
||||||
|
'https://my.sevdesk.de/OpenAPI/ReceiptAPI/openApi.json'
|
||||||
|
);
|
||||||
|
await testSmartswaggerInstance.mergeDocumentFromUrl(
|
||||||
|
'https://my.sevdesk.de/OpenAPI/ContactAPI/openApi.json',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
await testSmartswaggerInstance.mergeDocumentFromUrl(
|
||||||
|
'https://my.sevdesk.de/OpenAPI/InvoiceAPI/openApi.json',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
await testSmartswaggerInstance.mergeDocumentFromUrl(
|
||||||
|
'https://my.sevdesk.de/OpenAPI/OrderAPI/openApi.json',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
await testSmartswaggerInstance.mergeDocumentFromUrl(
|
||||||
|
'https://my.sevdesk.de/OpenAPI/InventoryAPI/openApi.json',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
// express stuff
|
||||||
|
testExpressServer = new smartexpress.Server({
|
||||||
|
cors: true,
|
||||||
|
});
|
||||||
|
testExpressServer.addRoute(
|
||||||
|
'/apiui',
|
||||||
|
new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashApiUiMiddleware())
|
||||||
|
);
|
||||||
|
testExpressServer.addRoute(
|
||||||
|
'/apiredoc',
|
||||||
|
new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashRedocMiddleware())
|
||||||
|
);
|
||||||
|
|
||||||
|
testExpressServer.addRoute(
|
||||||
|
'/apischema',
|
||||||
|
new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashApiSchemaMiddleware())
|
||||||
|
);
|
||||||
|
await testExpressServer.start(3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should run for a few seconds', async (toolsArg) => {
|
||||||
|
await toolsArg.delayFor(5000);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should end smartswagger', async () => {
|
||||||
|
await testExpressServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ export class Smartswagger {
|
|||||||
* dereferences the document at hand
|
* dereferences the document at hand
|
||||||
*/
|
*/
|
||||||
public async deref() {
|
public async deref() {
|
||||||
this.apiDoc = (await plugins.swaggerParser.dereference(
|
this.apiDoc = (await plugins.swaggerParser.dereference(this.apiDoc)) as IExtendedApiDoc;
|
||||||
this.apiDoc
|
|
||||||
)) as IExtendedApiDoc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addServer(serverArg: plugins.openapiTypes.OpenAPIV3.ServerObject) {
|
public async addServer(serverArg: plugins.openapiTypes.OpenAPIV3.ServerObject) {
|
||||||
@@ -56,10 +54,7 @@ export class Smartswagger {
|
|||||||
* @param documentToMergeArg
|
* @param documentToMergeArg
|
||||||
* @param basePathArg
|
* @param basePathArg
|
||||||
*/
|
*/
|
||||||
public async mergeDocument(
|
public async mergeDocument(documentToMergeArg: IExtendedApiDoc, basePathArg: string) {
|
||||||
documentToMergeArg: IExtendedApiDoc,
|
|
||||||
basePathArg: string
|
|
||||||
) {
|
|
||||||
console.log(`merging document with name ${documentToMergeArg.info?.title}`);
|
console.log(`merging document with name ${documentToMergeArg.info?.title}`);
|
||||||
await this.deref();
|
await this.deref();
|
||||||
// lets get a dereferenced version of the document we want to merge
|
// lets get a dereferenced version of the document we want to merge
|
||||||
@@ -85,8 +80,8 @@ export class Smartswagger {
|
|||||||
/**
|
/**
|
||||||
* merges a document from url
|
* merges a document from url
|
||||||
*/
|
*/
|
||||||
public async mergeDocumentFromUrl(documentUrlArg: string, basePathArg: string) {
|
public async mergeDocumentFromUrl(documentUrlArg: string, basePathArg: string = '') {
|
||||||
console.log(`getting document at ${documentUrlArg} for merging...`)
|
console.log(`getting document at ${documentUrlArg} for merging...`);
|
||||||
const documentResponse = await plugins.nodeFetch(documentUrlArg, {
|
const documentResponse = await plugins.nodeFetch(documentUrlArg, {
|
||||||
headers: {
|
headers: {
|
||||||
'accept-encoding': 'application/json',
|
'accept-encoding': 'application/json',
|
||||||
@@ -98,6 +93,18 @@ export class Smartswagger {
|
|||||||
await this.mergeDocument(apiDoc, basePathArg);
|
await this.mergeDocument(apiDoc, basePathArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merge multiple documents in parallel
|
||||||
|
* @param urlArrayArg
|
||||||
|
*/
|
||||||
|
public async mergeManyDocumentsFromUrl(urlArrayArg: { url: string; basePath: string }[]) {
|
||||||
|
const promiseArray: Promise<void>[] = [];
|
||||||
|
for (const urlArg of urlArrayArg) {
|
||||||
|
promiseArray.push(this.mergeDocumentFromUrl(urlArg.url, urlArg.basePath));
|
||||||
|
}
|
||||||
|
await Promise.all(promiseArray);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* merges a component to routes based on regex
|
* merges a component to routes based on regex
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,26 +1,17 @@
|
|||||||
// node native
|
// node native
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export {
|
export { path };
|
||||||
path
|
|
||||||
}
|
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as smartexpress from '@pushrocks/smartexpress';
|
import * as smartexpress from '@pushrocks/smartexpress';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export {
|
export { smartexpress, smartpromise };
|
||||||
smartexpress,
|
|
||||||
smartpromise
|
|
||||||
}
|
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import * as openapiTypes from 'openapi-types';
|
import * as openapiTypes from 'openapi-types';
|
||||||
import swaggerParser from '@apidevtools/swagger-parser';
|
import swaggerParser from '@apidevtools/swagger-parser';
|
||||||
import nodeFetch from 'node-fetch';
|
import nodeFetch from 'node-fetch';
|
||||||
|
|
||||||
export {
|
export { openapiTypes, swaggerParser, nodeFetch };
|
||||||
openapiTypes,
|
|
||||||
swaggerParser,
|
|
||||||
nodeFetch
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user