Separate swagger into files - node.js

Hi guys i'm works with swagger ui v2, and has a problem with organization.
The current structure of my project is like this.
const swaggerDocument = {
swagger: "2.0",
info: {
version: "1.0.0",
title: "Hello",
description: "hello",
},
basePath: "/api",
tags: [
{
name: "Users",
description: "API for users in the system",
},
],
schemes: [
"https",
"http",
],
consumes: [
"application/json",
],
produces: [
"application/json",
],
paths: {
"/users": {
// ...
},
},
definitions: {
User: {
// ...
},
},
};
In my path there are several routes (many actually) that reference my definitions, example: " $ref: "#/definitions/Users"," and my swagger.ts file is gigantic, I would like a better solution to organize, I tried something below but it didn't work.
swagger.ts
import { user, userDefinitions } from './user';
const swaggerDocument = {
paths: {
"/users": {
...user,
},
},
definitions: {
User: {
...userDefinitions,
},
},
};
Can someone help me?
User.ts
const user = {
"/users": {
...
},
};
const userDefinitions = {
User: {
properties: {
...
},
},
};
export { user, userDefinitions };

Related

How can I make Soap api call from node js using soap npm

I tried to use "soap" npm and build an object to be sent as param but the object is not able to be converted to envelope. I posted the file and response below
app.js file contain the below
var soap = require('soap');
const express = require('express');
const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
const url = 'https://files.developer.sabre.com/wsdl/sabreXML1.0.00/shopping/SSSAdvShopRQ_v5-4-0.wsdl';
let params = {
Envelope: {
Header: {
Action:"SSSAdvShopRQ",
Security: {
BinarySecurityToken: "Token"
},
MessageHeader: {
From: {.
PartyId:[ "WebServiceClient"]
},
To: {
PartyId:[ "WebServiceSupplier"]
},
CPAId: "ET",
ConversationId: "TestSession",
Service: "SSSAdvShop",
Action: "SSSAdvShopRQ"
},
},
Body: {
OTA_AirLowFareSearchRQ: {
POS: {
Source: {
RequestorID: {
CompanyName: {
Code: "SSW"
},
Type: "1",
ID: "1"
},
PseudoCityCode: "ADD"
}
},
OriginDestinationInformation: [
{
DepartureDateTime: "2023-01-25T00:00:00",
OriginLocation: {
LocationCode: "ADD"
},
DestinationLocation: {
LocationCode: "DXB"
},
TPA_Extensions: "",
RPH: "1"
},
{
DepartureDateTime: "2023-01-31T00:00:00",
OriginLocation: {
LocationCode: "DXB"
},
DestinationLocation: {
LocationCode: "SEA"
},
TPA_Extensions: "",
RPH: "2"
}
],
TravelPreferences: "",
TravelerInfoSummary: {
AirTravelerAvail: {
PassengerTypeQuantity: {
Code: "ADT",
Quantity: "1"
}
},
PriceRequestInformation: {
TPA_Extensions: {
Indicators: {
RetainFare: {
Ind: "true"
},
MinMaxStay: {
Ind: "true"
},
RefundPenalty: {
Ind: "true"
},
ResTicketing: {
Ind: "true"
},
TravelPolicy: {
Ind: "true"
}
},
PointOfSaleOverride: {
Code: "ADD"
}
},
CurrencyCode: "ETB"
}
},
TPA_Extensions: {
IntelliSellTransaction: {
RequestType: {
Name: "ADVBRD"
},
ServiceTag: {
Name: "ET"
}
}
},
Version: "5.4.0"
},
}
}
};
app.get('/', function (req, res) {
soap.createClient(url, function (err, client) {
client.SSSAdvShopRQAsync(params, function (err, response) {
console.log(response.data);
res.setHeader('Content-Type', 'application/json');
res.status(200).send(response.data);
});
});
});
app.listen(3000, () => {
console.log("Server started at port 3000");
});
I get the below response
soap-env:Fault
soap-env:Client.InvalidEbXmlMessage
Missing <soap-env:Header> in <soap-env:Envelope>
javax.xml.soap.SOAPException: Missing <soap-env:Header> in <soap-env:Envelope>
</soap-env:Fault>
I am looking how to convert from object to request envelope.
I have no token and username/password. I can't test this API.
But I can suggest your try this steps.
#1 Find correct input data parameters before node.js call using soapUI.
This is detail information for using simple calculator.
Example: You need to enter this values
<sec:Username>your user name</sec:Username>
<sec:Password>your user password</sec:Password>
<sec:BinarySecurityToken>real binary token</sec:BinarySecurityToken>
#2 Then resume node.js without express
This is detail information for soap-npm node.js.
In I found more easy way to consume SOAP service section.
#3 With express

Multiple swagger opitons in one project

I have multiple API path for admin level APIs and for customer APIs, I have defined two route folders. I want to set two swaggerOptions, but Unfortunately it only read one of them but not both, how can I set both of them but different routes.
Customer Level:
const swaggeroption1: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Customer API",
version: "x.x.x",
description: "Customer level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server1",
},
],
},
apis: ["./routes/customer/*.ts"],
};
Admin Level:
const swaggeroption2: swaggerJsDoc.Options = {
definition: {
openapi: "x.x.x",
info: {
title: "Admin API",
version: "x.x.x",
description: "Admin level",
},
servers: [
{
url: "http://localhost:80",
description: "server 1",
},
{
url: "XXXXXX",
description: "server2",
},
],
},
apis: ["./routes/admin/*.ts"],
};
Any Idea, how to handle these, in a single file?

Failed to de-identify patient name in DICOM tag (0010, 0010) by calling API "deidentify()" in library #googleapis/healthcare

I am working on a Cloud service for de-identifying DICOM data in a Google Healthcare DICOM store (not DICOM set). I want to replace patient name (value in DICOM tag (0010, 0010)) with a special char (such as '*') or with the name of the value's infoType (such as 'PERSON_NAME').
I tried following test code, NONE of them changed patient Name (i.e. After "deidentify()" call, the patient name in DICOM tag (0010,0010) remains same). Anything wrong in the code ?
Test Code #1:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS',
},
text: {
transformations: [
{
infoTypes:['PERSON_NAME'],
characterMaskConfig:{maskingCharacter: ''}
}
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Test Code #2:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
},
text: {
transformations: [
{
infoTypes:['PERSON_NAME'],
characterMaskConfig:{maskingCharacter: '*'}
},
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Test Code #3:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
},
text: {
transformations: [
// replace relevant values with their infoTypes
{
infoTypes: [],
replaceWithInfoTypeConfig: {}
} ,
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Test Code #4:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
},
text: {
transformations: [
{
infoTypes:['PERSON_NAME'],
redactConfig:{},
},
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Test Code #5:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
},
text: {
transformations: [
{
infoTypes:[],
redactConfig:{},
},
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Test Code #6:
const res = await healthcare.projects.locations.datasets.dicomStores.deidentify({
sourceStore: sourceStore,
destinationStore: destinationStore,
resource: {
config: {
dicom: {
filterProfile: 'DEIDENTIFY_TAG_CONTENTS'
},
text: {
transformations: [
]
},
image: {
textRedactionMode: 'REDACT_SENSITIVE_TEXT',
},
},
filterConfig: {
},
},
});
Related google de-ide docs:
https://cloud.google.com/healthcare-api/docs/reference/rest/v1/DeidentifyConfig#TagFilterProfile
https://cloud.google.com/healthcare-api/docs/how-tos/dicom-deidentify#default_dicom_infotypes
Any help is appreciated !

Feathers js - google login lead to delete of existing user

Steps to reproduce
1. Generate google access token in Frontend(I am using React library `react-google-login`)
2.Login using `local` strategy using email A(User A)
POST /authentication
body
{
"strategy": "local",
"email": "{{email A}}",
"password": "{{password}}"
}
3.Login as User B using `google` strategy of using jwt token(generated in step 2) in Authorization of account A
POST /authentication
body
{
"strategy": "google",
"access_token": "<google access token in step 1>"
}
Expected behavior
User B created.
Actual behavior
User B created, while User A is deleted in Database
Code
authentication.js
const { AuthenticationService, AuthenticationBaseStrategy, JWTStrategy } = require('#feathersjs/authentication');
const { LocalStrategy } = require('#feathersjs/authentication-local');
const { expressOauth } = require('#feathersjs/authentication-oauth');
const { discard, iff, isProvider, lowerCase, keep } = require('feathers-hooks-common')
const { OAuthStrategy } = require('#feathersjs/authentication-oauth');
class GoogleStrategy extends OAuthStrategy {
async getEntityData(profile) {
// this will set 'googleId'
const baseData = await super.getEntityData(profile);
const existingOauthEntity = await super.findEntity(profile)
// Check if user already exist
if(existingOauthEntity){
return {
...baseData
}
}else{
return {
...baseData,
email: profile.email,
};
}
}
}
module.exports = app => {
const authentication = new AuthenticationService(app);
authentication.register('jwt', new JWTStrategy());
authentication.register('local', new LocalStrategy());
authentication.register('google', new GoogleStrategy());
app.use('/authentication', authentication);
app.configure(expressOauth());
app.service('authentication').hooks({
before: {},
after: {
create: [
discard('authentication')
]
}
});
};
users.hook.js
const { iff, isProvider, keep, required, disallow, disablePagination, preventChanges, sequelizeConvert} = require('feathers-hooks-common');
const { authenticate } = require('#feathersjs/authentication').hooks;
const checkPermissions = require('feathers-permissions');
const errors = require('#feathersjs/errors');
const {
hashPassword, protect
} = require('#feathersjs/authentication-local').hooks;
module.exports = {
before: {
all: [
sequelizeConvert({
isEmailVerified: 'boolean',
}),
],
find: [
iff(isProvider('external'),
authenticate('jwt'),
checkPermissions({
roles: [ 'superadmin', 'admin'],
error: true,
})
)
],
get: [
iff(isProvider('external'),
iff(!(context => {return (context.params.authStrategies[0] === 'google')}),
authenticate('jwt'),
checkPermissions({
roles: [ 'admin'],
error: true,
})
)
)
],
create: [
iff(isProvider('external'),
iff((context => !context.params.authStrategies) || (context => !(context.params.authStrategies[0] === 'google')),
authenticate('jwt'),
checkPermissions({
roles: [ 'admin'],
error: true,
}),
required('email', 'password'),
hashPassword('password'),
)
)
],
update: [disallow()],
patch: [
iff(isProvider('external'),
preventChanges(true, [
'id',
'password',
'passwordResetEmailToken',
'passwordResetToken',
'passwordResetRequestedAt',
'passwordResetExpiresAt',
]),
authenticate('jwt'),
checkPermissions({
roles: ['admin'],
error: false,
}),
)
],
},
after: {
all: [
sequelizeConvert({
isEmailVerified: 'boolean',
}),
protect(
'password',
'passwordResetEmailToken'
)
],
find: [],
get: [],
create: [],
update: [disallow('external')],
patch: [],
remove: []
},
};

Not Getting Search value in Sencha Touch using searchfield

I want to display predictive text in search field, value for predictive text which comes from server. Here is my code so far:
View:
Ext.define('MyApp.view.AutoSearch', {
extend: 'Ext.dataview.List',
alias : 'widget.mainPanel',
config: {
store : 'AutoSearchStore',
itemTpl: '<div class="myWord">'+
'<div>Word is --<b>{name}</b>--- after search!!!</div>' +
'</div>',
emptyText: '<div class="myWord">No Matching Words</div>',
items: [
{
xtype: 'toolbar',
docked: 'top',
items: [
{
xtype: 'searchfield',
placeHolder: 'Search...',
itemId: 'searchBox'
}
]
}
]
}
});
Store:
Ext.define('MyApp.store.AutoSearchStore',{
extend: 'Ext.data.Store',
config:
{
model: 'MyApp.model.AutoSearchModel',
autoLoad:true,
id:'Contacts',
proxy:
{
type: 'ajax',
url: 'http://alucio.com.np/trunk/dev/sillydic/admin/api/word/categories/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363',
reader:
{
rootProperty:''
}
}
}
});
Model:
Ext.define('MyApp.model.AutoSearchModel', {
extend: 'Ext.data.Model',
requires: ['MyApp.model.AutoSearchModelMenu'],
config: {
fields: [
{name:'data', mapping: 'data'},
{name: 'name'},
],
},
});
and
Ext.define('MyApp.model.AutoSearchModelMenu', {
extend: 'Ext.data.Model',
config: {
fields: [
'name',
],
belongsTo: "MyApp.model.AutoSearchModel"
}
});
Controller:
Ext.define('MyApp.controller.SearchAutoComplete', {
extend : 'Ext.app.Controller',
config: {
profile: Ext.os.deviceType.toLowerCase(),
stores : ['MyApp.store.AutoSearchStore'],
models : ['MyApp.model.AutoSearchModel'],
refs: {
myContainer: 'mainPanel'
},
control: {
'mainPanel': {
activate: 'onActivate'
},
'mainPanel searchfield[itemId=searchBox]' : {
clearicontap : 'onClearSearch',
keyup: 'onSearchKeyUp'
}
}
},
onActivate: function() {
console.log('Main container is active--Search');
},
onSearchKeyUp: function(searchField) {
queryString = searchField.getValue();
console.log(this,'Please search by: ' + queryString);
var store = Ext.getStore('AutoSearchStore');
store.clearFilter();
if(queryString){
var thisRegEx = new RegExp(queryString, "i");
store.filterBy(function(record) {
if (thisRegEx.test(record.get('name'))) {
return true;
};
return false;
});
}
},
onClearSearch: function() {
console.log('Clear icon is tapped');
var store = Ext.getStore('AutoSearchStore');
store.clearFilter();
},
init: function() {
console.log('Controller initialized for SearchAutoComplete');
}
});
Json Data Looks Like:
"data":[
{
"name":"paint",
"author":"admin",
"word_id":"1",
"category":"Business",
"is_favourite":"yesStar"
},
{
"name":"abacus",
"author":"admin",
"word_id":"2",
"category":"Education",
"is_favourite":"yesStar"
},
{
"name":"abate",
"author":"admin",
"word_id":"3",
"category":"Education",
"is_favourite":"noStar"
},
{
"name":"testing adsf",
"author":"admin",
"word_id":"7",
"category":"Education",
"is_favourite":"noStar"
},
{
"name":"sprite",
"author":"admin",
"word_id":"6",
"category":"Business",
"is_favourite":"noStar"
},
{
"name":"newword",
"author":"admin",
"word_id":"8",
"category":"Architecture",
"is_favourite":"noStar"
}
]
})
If I type "A", then it displays No Matching Words, but I have words from "A" on json coming from server. How to solve this problem?
Any idea!
Code Sources Link
I don't know why you are using two models but just one thing you need to specify in AutoSearchStore :
reader:
{
rootProperty:'data'
}
instead of
reader:
{
rootProperty:''
}
to get the expected results in the list.
Hope this will be helpful :)

Resources