Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
ibm-openapi-support
Advanced tools
This module is a utility to make the process of loading and parsing documents in the OpenAPI (swagger) format a simple task. The primary use case for this is code generation where a swagger document is loaded, parsed and then relavent data structures for building api endpoints are made available.
Swaggerize contains two modules, index.js and utils.js. They are described below:
var swaggerize = require('ibm-openapi-support')
var loadedApi
var parsedSwagger
var memFs = require('mem-fs')
var editor = require('mem-fs-editor')
var store = memFs.create()
var fs = editor.create(store)
return utils.loadAsync('../resources/person_dino.json', fs)
.then(loaded => swaggerize.parse(loaded, formatters))
.then(response => {
loadedApi = response.loaded
parsedSwagger = response.parsed
})
var swaggerize = require('ibm-openapi-support')
var swaggerizeUtils = require('ibm-openapi-support/utils')
var swaggerDocument = 'your OpenApi (swagger) document goes here'
function reformatPathToNodeExpress (thepath) {
// take a swagger path and convert the parameters to express format.
// i.e. convert "/path/to/{param1}/{param2}" to "/path/to/:param1/:param2"
var newPath = thepath.replace(/{/g, ':')
return newPath.replace(/}/g, '')
}
function resourceNameFromPath (thePath) {
// grab the first valid element of a path (or partial path) and return it.
return thePath.match(/^\/*([^/]+)/)[1]
}
this.parsedSwagger = undefined;
var formatters = {
'pathFormatter': helpers.reformatPathToNodeExpress,
'resourceFormatter': helpers.resourceNameFromPath
}
if (swaggerDocument !== undefined) {
return swaggerize.parse(swaggerDocument, formatters)
.then(response => {
this.loadedApi = response.loaded
this.parsedSwagger = response.parsed
})
.catch(err => {
err.message = 'failed to parse document ' + err.message
throw err
})
}
if (this.parsedSwagger) {
Object.keys(this.parsedSwagger.resources).forEach(function(resource) {
var context = {
'resource': resource,
'routes': this.parsedSwagger.resources[resource],
'basepath': this.parsedSwagger.basepath
}
this.fs.copyTpl(this.templatePath('fromswagger/routers/router.js'), this.destinationPath(`server/routers/${resource}.js`), context)
this.fs.copyTpl(this.templatePath('test/resource.js'), this.destinationPath(`test/${resource}.js`), context)
}.bind(this))
}
FAQs
utility for loading and parsing swagger
The npm package ibm-openapi-support receives a total of 3 weekly downloads. As such, ibm-openapi-support popularity was classified as not popular.
We found that ibm-openapi-support demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.