Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #439 from IBM-Swift/updateTo4.4.0
Browse files Browse the repository at this point in the history
Release 4.4.0

### Bug Fixes

* **package:** update generator-ibm-cloud-enablement to version 0.6.13 ([#416](#416)) ([13a14f5](13a14f5))
* **package:** update generator-ibm-service-enablement to version 0.6.5 ([#423](#423)) ([6769e0b](6769e0b))
* make RouteTests more lenient on index content ([#427](#427)) ([1ae501e](1ae501e))
* **unsupported services:** added tests to check for unwanted behavior when given unsupported service payloads from custom bluemix string ([#431](#431)) ([b3e1870](b3e1870))
* use correct redis default port ([#433](#433)) ([623f206](623f206))


### Features

* model support for swagger ([#422](#422)) ([9cb8438](9cb8438))
  • Loading branch information
tunniclm authored Jan 26, 2018
2 parents dfba19c + dada9ae commit d3a3a7d
Show file tree
Hide file tree
Showing 16 changed files with 1,030 additions and 213 deletions.
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="4.4.0"></a>
# [4.4.0](https://github.com/IBM-Swift/generator-swiftserver/compare/4.3.0...4.4.0) (2018-01-26)


### Bug Fixes

* **package:** update generator-ibm-cloud-enablement to version 0.6.13 ([#416](https://github.com/IBM-Swift/generator-swiftserver/issues/416)) ([13a14f5](https://github.com/IBM-Swift/generator-swiftserver/commit/13a14f5))
* **package:** update generator-ibm-service-enablement to version 0.6.5 ([#423](https://github.com/IBM-Swift/generator-swiftserver/issues/423)) ([6769e0b](https://github.com/IBM-Swift/generator-swiftserver/commit/6769e0b))
* make RouteTests more lenient on index content ([#427](https://github.com/IBM-Swift/generator-swiftserver/issues/427)) ([1ae501e](https://github.com/IBM-Swift/generator-swiftserver/commit/1ae501e))
* **unsupported services:** added tests to check for unwanted behavior when given unsupported service payloads from custom bluemix string ([#431](https://github.com/IBM-Swift/generator-swiftserver/issues/431)) ([b3e1870](https://github.com/IBM-Swift/generator-swiftserver/commit/b3e1870))
* use correct redis default port ([#433](https://github.com/IBM-Swift/generator-swiftserver/issues/433)) ([623f206](https://github.com/IBM-Swift/generator-swiftserver/commit/623f206))


### Features

* model support for swagger ([#422](https://github.com/IBM-Swift/generator-swiftserver/issues/422)) ([9cb8438](https://github.com/IBM-Swift/generator-swiftserver/commit/9cb8438))



<a name="4.3.0"></a>
# [4.3.0](https://github.com/IBM-Swift/generator-swiftserver/compare/4.2.3...4.3.0) (2018-01-10)

Expand Down
131 changes: 93 additions & 38 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ var format = require('util').format
var fs = require('fs')
var path = require('path')
var url = require('url')
var Promise = require('bluebird')
var request = require('request')
var requestAsync = Promise.promisify(request)
var YAML = require('js-yaml')
var chalk = require('chalk')

// Keywords which are reserved in Swift (taken from the Language Reference)
Expand Down Expand Up @@ -411,7 +407,7 @@ function sanitizeCredentialsAndFillInDefaults (serviceType, service) {
port: service.port || defaults.port
}
case 'redis':
var defaultRedisURI = { protocol: 'redis', auth: ':', hostname: 'localhost', port: 6397, slashes: true }
var defaultRedisURI = { protocol: 'redis', auth: ':', hostname: 'localhost', port: 6379, slashes: true }
if (service.host) defaultRedisURI.hostname = service.host
if (service.port) defaultRedisURI.port = service.port
if (service.password) defaultRedisURI.auth = `:${service.password}`
Expand Down Expand Up @@ -535,48 +531,107 @@ exports.getBluemixDefaultPlan = function (serviceType) {
}
}

function loadHttpAsync (uri) {
debug('in loadHttpAsync')
// take a swagger path and convert the parameters to Swift Kitura format.
// i.e. convert "/path/to/{param1}/{param2}" to "/path/to/:param1/:param2"
exports.reformatPathToSwiftKitura = (path) => path.replace(/{/g, ':').replace(/}/g, '')

return requestAsync({ method: 'GET', uri: uri })
.then(result => {
if (result.statusCode !== 200) {
debug('get request returned status:', result.statusCode)
throw new Error(chalk.red('failed to load swagger from:', uri, 'status:', result.statusCode))
}
return result.body
})
exports.resourceNameFromPath = function (thepath) {
// grab the first valid element of a path (or partial path) and return it capitalized.
var resource = thepath.match(/^\/*([^/]+)/)[1]
return resource.charAt(0).toUpperCase() + resource.slice(1)
}

function loadFileAsync (filePath, memfs) {
debug('in loadFileAsync')
exports.getRefName = function (ref) {
return ref.split('/').pop()
}

return Promise.try(() => memfs.read(filePath))
.then(data => {
if (data === undefined) {
// when file exists but cannot read content.
debug('cannot read file contents', filePath)
throw new Error(chalk.red('failed to load swagger from:', filePath))
}
return data
})
exports.capitalizeFirstLetter = function (toBeCapitalized) {
// capitalize the first letter
return toBeCapitalized.charAt(0).toUpperCase() + toBeCapitalized.slice(1)
}

exports.loadAsync = function (path, memfs) {
var isHttp = /^https?:\/\/\S+/.test(path)
var isYaml = (path.endsWith('.yaml') || path.endsWith('.yml'))
return (isHttp ? loadHttpAsync(path) : loadFileAsync(path, memfs))
.then(data => isYaml ? JSON.stringify(YAML.load(data)) : data)
exports.arrayContains = function (search, array) {
return array.indexOf(search) > -1
}

// take a swagger path and convert the parameters to Swift Kitura format.
// i.e. convert "/path/to/{param1}/{param2}" to "/path/to/:param1/:param2"
exports.reformatPathToSwiftKitura = (path) => path.replace(/{/g, ':').replace(/}/g, '')
exports.swiftTypeFromSwaggerProperty = function (property) {
// return a Swift type based on a swagger type and format.
var swaggerPropertyTypes = [
'boolean',
'integer',
'number',
'string'
]

var swaggerToSwiftInt = {
'int8': 'Int8',
'uint8': 'UInt8',
'int16': 'Int16',
'uint16': 'UInt16',
'int32': 'Int32',
'uint32': 'UInt32',
'int64': 'Int64',
'uint64': 'UInt64'
}

exports.resourceNameFromPath = function (thepath) {
// grab the first valid element of a path (or partial path) and return it capitalized.
var resource = thepath.match(/^\/*([^/]+)/)[1]
return resource.charAt(0).toUpperCase() + resource.slice(1)
var swaggerToSwift = {
boolean: 'Bool',
integer: 'Int',
number: 'Double',
string: 'String',
object: 'Dictionary<String, JSONValue>'
}

var format
var array
var mappingType
var swiftType

if (property.type) {
if (exports.arrayContains(property.type, swaggerPropertyTypes)) {
swiftType = swaggerToSwift[property.type]
format = property.format || undefined
} else if (property.type === 'ref' && property.$ref) {
swiftType = exports.getRefName(property.$ref)
format = undefined
} else if (property.type === 'object') {
if (property.additionalProperties && property.additionalProperties.type) {
swiftType = swaggerToSwift[property.additionalProperties.type]
format = property.additionalProperties.format || undefined
mappingType = true
}
} else if (property.type === 'array') {
if (property.items.$ref) {
// has a ref type, so set the swagger type to that.
swiftType = exports.getRefName(property.items.$ref)
} else if (property.items && property.items.type) {
swiftType = swaggerToSwift[property.items['type']]
format = property.items['format'] || undefined
}
array = true
}
}

// now check if the property has a format modifier and apply that if appropriate.
if (format) {
// a format modifier exists, so convert the swagger type if appropriate.
if (swiftType === 'Int') {
swiftType = swaggerToSwiftInt[format]
}

if (swiftType === 'Double' && format === 'float') {
swiftType = 'Float'
}
}

if (mappingType) {
swiftType = 'Dictionary<String, ' + swiftType + '>'
}

if (array) {
swiftType = '[' + swiftType + ']'
}
return swiftType
}

exports.isThisServiceAnArray = function (serviceType) {
Expand Down
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-swiftserver",
"version": "4.3.0",
"version": "4.4.0",
"description": "Generator for Kitura REST webservice servers",
"main": "app/index.js",
"scripts": {
Expand All @@ -26,11 +26,11 @@
"bluebird": "^3.5.0",
"chalk": "^2.1.0",
"debug": "^3.0.0",
"generator-ibm-cloud-enablement": "0.6.12",
"generator-ibm-service-enablement": "0.6.4",
"generator-ibm-cloud-enablement": "0.6.13",
"generator-ibm-service-enablement": "0.6.5",
"generator-ibm-usecase-enablement": "3.2.0",
"handlebars": "^4.0.5",
"ibm-openapi-support": "^0.0.9",
"ibm-openapi-support": "0.0.10",
"js-yaml": "^3.9.1",
"request": "^2.81.0",
"rimraf": "^2.5.2",
Expand Down
Loading

0 comments on commit d3a3a7d

Please sign in to comment.