fix(core): update

This commit is contained in:
Philipp Kunz 2021-11-20 22:38:37 +01:00
parent d152920692
commit f29623c084
6 changed files with 45 additions and 36 deletions

View File

@ -126,7 +126,7 @@ pages:
- npmci node install lts - npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci command npm install --prod - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless - lossless

View File

@ -7,20 +7,43 @@ let testSmartswaggerInstance: smartswagger.Smartswagger;
let testExpressServer: smartexpress.Server; let testExpressServer: smartexpress.Server;
tap.test('first test', async () => { tap.test('first test', async () => {
testSmartswaggerInstance = await smartswagger.Smartswagger.createFromUrl('https://my.sevdesk.de/OpenAPI/ReceiptAPI/openApi.json'); testSmartswaggerInstance = await smartswagger.Smartswagger.createFromUrl(
await testSmartswaggerInstance.mergeDocumentFromUrl('https://my.sevdesk.de/OpenAPI/ContactAPI/openApi.json', ''); 'https://my.sevdesk.de/OpenAPI/ReceiptAPI/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(
await testSmartswaggerInstance.mergeDocumentFromUrl('https://my.sevdesk.de/OpenAPI/InventoryAPI/openApi.json', ''); '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 // express stuff
testExpressServer = new smartexpress.Server({ testExpressServer = new smartexpress.Server({
cors: true, cors: true,
}); });
testExpressServer.addRoute('/apiui', new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashApiUiMiddleware())); testExpressServer.addRoute(
testExpressServer.addRoute('/apiredoc', new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashRedocMiddleware())) '/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())); testExpressServer.addRoute(
'/apischema',
new smartexpress.Handler('ALL', testSmartswaggerInstance.getSlashApiSchemaMiddleware())
);
await testExpressServer.start(3000); await testExpressServer.start(3000);
}); });
@ -30,6 +53,6 @@ tap.test('should run for a few seconds', async (toolsArg) => {
tap.test('should end smartswagger', async () => { tap.test('should end smartswagger', async () => {
await testExpressServer.stop(); await testExpressServer.stop();
}) });
tap.start(); tap.start();

View File

@ -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
@ -86,7 +81,7 @@ 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',
@ -102,11 +97,11 @@ export class Smartswagger {
* merge multiple documents in parallel * merge multiple documents in parallel
* @param urlArrayArg * @param urlArrayArg
*/ */
public async mergeManyDocumentsFromUrl(urlArrayArg: {url: string, basePath: string}[]) { public async mergeManyDocumentsFromUrl(urlArrayArg: { url: string; basePath: string }[]) {
const promiseArray: Promise<void>[] = []; const promiseArray: Promise<void>[] = [];
for (const urlArg of urlArrayArg) { for (const urlArg of urlArrayArg) {
promiseArray.push(this.mergeDocumentFromUrl(urlArg.url, urlArg.basePath)); promiseArray.push(this.mergeDocumentFromUrl(urlArg.url, urlArg.basePath));
}; }
await Promise.all(promiseArray); await Promise.all(promiseArray);
} }

View File

@ -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
}