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

Release 2.8.0 #292

Merged
merged 28 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
810ba5e
feat: improve swagger basepath handling (#269)
Jul 25, 2017
64a5919
Merge remote-tracking branch 'origin/master' into develop
Jul 27, 2017
b6a259c
feat: intial kubernetes support
Aug 10, 2017
e0bb80d
fix: default toolchain type clone
Aug 10, 2017
601ead1
chart dir convention
Aug 13, 2017
4f8b681
fix: override default toolchain type
Aug 18, 2017
dabdd3a
Added support for deploying and running image in kubernetes.
rolivieri Aug 19, 2017
4b85367
Added support for deploying and running image in kubernetes.
rolivieri Aug 20, 2017
692ed5f
feat: kubernetes helm support
Aug 21, 2017
f69c572
Merge pull request #280 from IBM-Swift/typeClone
Aug 21, 2017
1a33749
Added support for deploying and running image in kubernetes.
rolivieri Aug 21, 2017
35ae466
Added support for deploying and running image in kubernetes.
rolivieri Aug 21, 2017
cc6cd89
Merge branch 'develop' into kube-deploy
rolivieri Aug 21, 2017
6a6b0be
Merge pull request #282 from IBM-Swift/kube-deploy
Aug 24, 2017
349cec4
feat: decouple path reformatting from swaggerize
Aug 24, 2017
694a263
feat: kubernetes support
Aug 25, 2017
8df16e6
feat: intial kubernetes support
Aug 10, 2017
5926fce
chart dir convention
Aug 13, 2017
d1ab81a
feat: kubernetes helm support
Aug 21, 2017
d1b7b49
feat: kubernetes support
Aug 25, 2017
02a8991
Merge branch 'develop' into kubernetes
Aug 25, 2017
0396c56
Merge branch 'kubernetes' of github.com:IBM-Swift/generator-swiftserv…
Aug 25, 2017
4227a7a
feat: kubernetes support
Aug 28, 2017
25341ea
feat: kubernetes support
Aug 28, 2017
c3f9681
Merge pull request #283 from IBM-Swift/kubernetes
Aug 28, 2017
fb308fc
fix(package): update generator-ibm-cloud-enablement to version 0.0.57…
greenkeeper[bot] Aug 29, 2017
2bc67c5
chore(package): update nyc to version 11.1.0 (#272)
greenkeeper[bot] Aug 30, 2017
8e19961
chore(release): 2.8.0
Aug 30, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

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="2.8.0"></a>
# [2.8.0](https://github.com/IBM-Swift/generator-swiftserver/compare/2.7.0...2.8.0) (2017-08-30)


### Bug Fixes

* default toolchain type clone ([e0bb80d](https://github.com/IBM-Swift/generator-swiftserver/commit/e0bb80d))
* override default toolchain type ([4f8b681](https://github.com/IBM-Swift/generator-swiftserver/commit/4f8b681))
* **package:** update generator-ibm-cloud-enablement to version 0.0.57 ([#284](https://github.com/IBM-Swift/generator-swiftserver/issues/284)) ([fb308fc](https://github.com/IBM-Swift/generator-swiftserver/commit/fb308fc))


### Features

* decouple path reformatting from swaggerize ([349cec4](https://github.com/IBM-Swift/generator-swiftserver/commit/349cec4))
* improve swagger basepath handling ([#269](https://github.com/IBM-Swift/generator-swiftserver/issues/269)) ([810ba5e](https://github.com/IBM-Swift/generator-swiftserver/commit/810ba5e))
* intial kubernetes support ([8df16e6](https://github.com/IBM-Swift/generator-swiftserver/commit/8df16e6))
* intial kubernetes support ([b6a259c](https://github.com/IBM-Swift/generator-swiftserver/commit/b6a259c))
* kubernetes helm support ([d1ab81a](https://github.com/IBM-Swift/generator-swiftserver/commit/d1ab81a))
* kubernetes helm support ([692ed5f](https://github.com/IBM-Swift/generator-swiftserver/commit/692ed5f))
* kubernetes support ([25341ea](https://github.com/IBM-Swift/generator-swiftserver/commit/25341ea))
* kubernetes support ([4227a7a](https://github.com/IBM-Swift/generator-swiftserver/commit/4227a7a))
* kubernetes support ([d1b7b49](https://github.com/IBM-Swift/generator-swiftserver/commit/d1b7b49))
* kubernetes support ([694a263](https://github.com/IBM-Swift/generator-swiftserver/commit/694a263))



<a name="2.7.0"></a>
# [2.7.0](https://github.com/IBM-Swift/generator-swiftserver/compare/2.6.0...2.7.0) (2017-07-24)

Expand Down
7 changes: 7 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,10 @@ exports.loadAsync = function (path, memfs) {
return (isHttp ? loadHttpAsync(path) : loadFileAsync(path, memfs))
.then(data => isYaml ? JSON.stringify(YAML.load(data)) : data)
}

exports.reformatPathToSwift = function (thepath) {
// take a swagger path and convert the parameters to swift format.
// i.e. convert "/path/to/{param1}/{param2}" to "/path/to/:param1/:param2"
var newPath = thepath.replace(/{/g, ':')
return newPath.replace(/}/g, '')
}
8 changes: 7 additions & 1 deletion lib/sdkGenHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ exports.performSDKGenerationAsync = function (sdkName, sdkType, fileContent) {
url: startGenURL,
body: fileContent
})
.then(response => JSON.parse(response.body).job.id)
.then(function (response) {
var body = JSON.parse(response.body)
if (body.job && body.job.id) {
return body.job.id
}
throw new Error(chalk.red('SDK generation error:', response.statusCode, response.statusMessage, body.message))
})
.tap(generatedID => debug(`SDK generation job for ${sdkName} started with id ${generatedID}`))
.then(generatedID => checkUntilFinished(generatedID))

Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-swiftserver",
"version": "2.7.0",
"version": "2.8.0",
"description": "Generator for Kitura REST webservice servers",
"main": "app/index.js",
"scripts": {
Expand All @@ -22,28 +22,29 @@
"generator"
],
"dependencies": {
"generator-ibm-cloud-enablement": "0.0.57",
"bluebird": "^3.5.0",
"chalk": "^1.1.0",
"debug": "^2.2.0",
"js-yaml": "^3.4.2",
"yeoman-generator": "^1.1.1",
"handlebars": "^4.0.5",
"bluebird": "^3.5.0",
"js-yaml": "^3.9.1",
"request": "^2.81.0",
"swagger-parser": "^3.4.1",
"swagger-schema-official": "^2.0.0-",
"swaggerize-routes": "^1.0.0",
"rimraf": "^2.5.2",
"unzip2": "^0.2.5"
"swagger-parser": "^3.4.2",
"swagger-schema-official": "^2.0.0-d79c205",
"swaggerize-routes": "^1.0.0",
"unzip2": "^0.2.5",
"yeoman-generator": "^1.1.1"
},
"devDependencies": {
"codecov": "^2.1.0",
"codecov": "^2.3.0",
"istanbul": "^0.4.5",
"mem-fs": "^1.1.3",
"mem-fs-editor": "^3.0.2",
"mocha": "^3.2.0",
"mocha": "^3.5.0",
"nock": "^9.0.13",
"nyc": "^10.1.2",
"standard": "^10.0.2",
"nyc": "^11.1.0",
"standard": "^10.0.3",
"standard-version": "^4.2.0",
"yeoman-assert": "^3.0.0",
"yeoman-test": "^1.6.0"
Expand Down
8 changes: 0 additions & 8 deletions refresh/fromswagger/generatorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ function baseName (thepath) {
return path.basename(thepath).split('.')[0]
}

function convertToSwiftParameterFormat (thepath) {
// take a swagger path and convert the parameters to swift 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 capitalized.
var resource = thepath.match(/^\/*([^/]+)/)[1]
Expand All @@ -39,6 +32,5 @@ function getRefName (ref) {
}

module.exports = {baseName,
convertToSwiftParameterFormat,
resourceNameFromPath,
getRefName}
11 changes: 6 additions & 5 deletions refresh/fromswagger/swaggerize.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ function ensureValidAsync (loadedSwagger) {
})
}

function parseSwagger (api) {
function parseSwagger (api, pathFormatter) {
debug('in parseSwagger')
// walk the api, extract the schemas from the definitions, the parameters and the responses.
var resources = {}
var refs = []
var basePath = api.basePath || undefined
pathFormatter = pathFormatter || function (path) { return path }

Object.keys(api.paths).forEach(function (path) {
var resource = genUtils.resourceNameFromPath(path)

debug('path:', path, 'becomes resource:', resource)
debug('path:', path, 'becomes resource: "' + resource + '" with route: "' + pathFormatter(path) + '"')
// for each path, walk the method verbs
builderUtils.verbs.forEach(function (verb) {
if (api.paths[path][verb]) {
Expand All @@ -49,7 +50,7 @@ function parseSwagger (api) {

debug('parsing verb:', verb)
// save the method and the path in the resources list.
resources[resource].push({method: verb, route: genUtils.convertToSwiftParameterFormat(path)})
resources[resource].push({method: verb, route: pathFormatter(path)})
// process the parameters
if (api.paths[path][verb].parameters) {
var parameters = api.paths[path][verb].parameters
Expand Down Expand Up @@ -135,14 +136,14 @@ function parseSwagger (api) {
return parsed
}

exports.parse = function (swaggerStr) {
exports.parse = function (swaggerStr, pathFormatter) {
debug('in parse')
var loaded = JSON.parse(swaggerStr)
return ensureValidAsync(loaded)
.then(function () {
debug('successfully validated against schema')
// restore the original swagger as the call to ensureValidAsync modifies the original loaded object.
loaded = JSON.parse(swaggerStr)
return { loaded: loaded, parsed: parseSwagger(loaded) }
return { loaded: loaded, parsed: parseSwagger(loaded, pathFormatter) }
})
}
40 changes: 31 additions & 9 deletions refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ module.exports = Generator.extend({
this.env.error(chalk.red(`Property appType is invalid: ${this.spec.appType}`))
}
this.appType = this.spec.appType
this.repoType = this.spec.repoType || 'link'

// App name
if (this.spec.appName) {
Expand Down Expand Up @@ -185,6 +186,9 @@ module.exports = Generator.extend({
if (typeof (this.spec.bluemix.instances) === 'number') {
this.bluemix.instances = this.spec.bluemix.instances
}
if (typeof (this.spec.bluemix.namespace) === 'string') {
this.bluemix.namespace = this.spec.bluemix.namespace
}
}

// Clean app name (for containers and other uses)
Expand Down Expand Up @@ -667,7 +671,7 @@ module.exports = Generator.extend({
if (!this.fromSwagger) return

return helpers.loadAsync(this.fromSwagger, this.fs)
.then(loaded => swaggerize.parse(loaded))
.then(loaded => swaggerize.parse(loaded, helpers.reformatPathToSwift))
.then(response => {
this.loadedApi = response.loaded
this.parsedSwagger = response.parsed
Expand Down Expand Up @@ -704,7 +708,7 @@ module.exports = Generator.extend({
return Promise.map(this.serverSwaggerFiles, file => {
return helpers.loadAsync(file, this.fs)
.then(loaded => {
return swaggerize.parse(loaded)
return swaggerize.parse(loaded, helpers.reformatPathToSwift)
.then(response => {
if (response.loaded.info.title === undefined) {
this.env.error(chalk.red('Could not extract title from Swagger API.'))
Expand Down Expand Up @@ -786,9 +790,15 @@ module.exports = Generator.extend({
})

this._ifNotExistsInProject(['Sources', this.applicationModule, 'Application.swift'], (filepath) => {
var basepath
var resources
if (this.parsedSwagger && this.parsedSwagger.resources) {
resources = Object.keys(this.parsedSwagger.resources)
if (this.parsedSwagger) {
if (this.parsedSwagger.basepath) {
basepath = this.parsedSwagger.basepath
}
if (this.parsedSwagger.resources) {
resources = Object.keys(this.parsedSwagger.resources)
}
}
this.fs.copyTpl(
this.templatePath('common', 'Application.swift'),
Expand All @@ -802,7 +812,8 @@ module.exports = Generator.extend({
capabilities: this.capabilities,
web: this.web,
hostSwagger: this.hostSwagger,
resources: resources
resources: resources,
basepath: basepath
}
)
})
Expand Down Expand Up @@ -1219,8 +1230,10 @@ module.exports = Generator.extend({
filepath)
})
this._ifNotExistsInProject('Dockerfile', (filepath) => {
this.fs.copy(this.templatePath('docker', 'Dockerfile'),
filepath)
this.fs.copyTpl(this.templatePath('docker', 'Dockerfile'),
filepath,
{ executableName: this.executableModule }
)
})
this._ifNotExistsInProject('cli-config.yml', (filepath) => {
this.fs.copyTpl(
Expand Down Expand Up @@ -1250,7 +1263,8 @@ module.exports = Generator.extend({
services: this.services,
capabilities: this.capabilities,
hostSwagger: this.hostSwagger,
bluemix: this.bluemix }
bluemix: this.bluemix
}
)
})

Expand All @@ -1269,7 +1283,8 @@ module.exports = Generator.extend({
this.fs.copyTpl(
this.templatePath('bluemix', 'toolchain.yml'),
filepath,
{ appName: this.projectName }
{ appName: this.projectName,
repoType: this.repoType }
)
})

Expand All @@ -1279,6 +1294,13 @@ module.exports = Generator.extend({
})
},

writeKubernetesFiles: function () {
if (!this.docker) return

var server = (this.bluemix && this.bluemix.domain && this.bluemix.namespace) ? { domain: this.bluemix.domain, namespace: this.bluemix.namespace } : undefined
this.composeWith(require.resolve('generator-ibm-cloud-enablement/generators/kubernetes'), {force: this.force, bluemix: { backendPlatform: 'SWIFT', name: this.cleanAppName, server: server }})
},

writePackageSwift: function () {
// Check if there is a Package.swift, create one if there isn't
this._ifNotExistsInProject('Package.swift', (filepath) => {
Expand Down
2 changes: 1 addition & 1 deletion refresh/templates/bluemix/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repo:
service_id: githubpublic
parameters:
repo_url: "{{repository}}"
type: link
type: <%-repoType%>
has_issues: true

# Pipelines
Expand Down
3 changes: 3 additions & 0 deletions refresh/templates/common/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import CloudFoundryConfig
public let router = Router()
public let manager = ConfigurationManager()
public var port: Int = 8080
<% if (basepath) { -%>
public var basePath = "<%- basepath %>"
<% } -%>

<% if (Object.keys(services).length > 0) { -%>
<% Object.keys(services).forEach(function(serviceType) { -%>
Expand Down
6 changes: 6 additions & 0 deletions refresh/templates/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ RUN chmod -R 555 /swift-utils

# Create user if not root
RUN if [ $bx_dev_user != "root" ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

# Bundle application source & binaries
COPY . /swift-project

# Command to start Swift application
CMD [ "sh", "-c", "cd /swift-project && .build-ubuntu/release/<%- executableName %>" ]
3 changes: 2 additions & 1 deletion refresh/templates/docker/cli-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ dockerfile-run: "Dockerfile"
build-cmd-debug : "/swift-utils/tools-utils.sh build debug"
debug-cmd : "/swift-utils/tools-utils.sh debug <%- executableName %> 1024"
build-cmd-run : "/swift-utils/tools-utils.sh build release"
run-cmd : "/swift-utils/run-utils.sh run <%- executableName %>"
run-cmd : ""
test-cmd : "/swift-utils/tools-utils.sh test"
container-path-run : "/swift-project"
container-path-tools : "/swift-project"
container-port-map : "8080:8080"
container-port-map-debug : "2048:1024,2049:1025"
chart-path : "chart/<%- cleanAppName.toLowerCase() %>"
2 changes: 1 addition & 1 deletion refresh/templates/fromswagger/Routes.swift.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SwiftyJSON

func initialize{{resource}}Routes() {
{{#each routes}}
router.{{this.method}}("{{../basepath}}{{this.route}}") { request, response, next in
router.{{this.method}}("{{#if ../basepath}}\(basePath){{/if}}{{this.route}}") { request, response, next in
response.send(json: [:])
next()
}
Expand Down
15 changes: 15 additions & 0 deletions test/integration/app/prompted_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var appGeneratorPath = path.join(__dirname, '../../../app')
var testResourcesPath = path.join(__dirname, '../../../test/resources')
var buildTimeout = 300000

// Require config to alter sdkgen delay between
// status checks to speed up unit tests
var config = require('../../../config')
var sdkGenCheckDelaySaved

describe('Prompt and build integration tests for app generator', function () {
describe('Basic application', function () {
// Swift build is slow so we need to set a longer timeout for the test
Expand Down Expand Up @@ -100,6 +105,10 @@ describe('Prompt and build integration tests for app generator', function () {
var runContext
var appName = 'notes'
before(function () {
// alter delay between status checks to speed up unit tests
sdkGenCheckDelaySaved = config.sdkGenCheckDelay
config.sdkGenCheckDelay = 10000

// Swift build is slow so we need to set a longer timeout for the test
this.timeout(buildTimeout)
runContext = helpers.run(appGeneratorPath)
Expand All @@ -120,6 +129,12 @@ describe('Prompt and build integration tests for app generator', function () {
return runContext.toPromise() // Get a Promise back when the generator finishes
})

after('restore sdkgen status check delay', function () {
// restore delay between status checks so integration tests
// remain resilient
config.sdkGenCheckDelay = sdkGenCheckDelaySaved
})

it('compiles the application', function () {
assert.file(process.cwd() + '/.build/debug/' + appName)
})
Expand Down
Loading