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

Commit

Permalink
feat: use public ibm-openapi-support instead of internal swaggerize f…
Browse files Browse the repository at this point in the history
…unction (#317)
  • Loading branch information
nhardman authored Sep 27, 2017
1 parent b328ed8 commit cb6e809
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 231 deletions.
13 changes: 8 additions & 5 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,12 @@ exports.loadAsync = function (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, '')
// 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.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)
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
"js-yaml": "^3.9.1",
"request": "^2.81.0",
"rimraf": "^2.5.2",
"swagger-parser": "^3.4.2",
"swagger-schema-official": "^2.0.0-d79c205",
"swaggerize-routes": "^1.0.0",
"ibm-openapi-support": "^0.0.4",
"unzip2": "^0.2.5",
"yeoman-generator": "^1.1.1"
},
Expand Down
36 changes: 0 additions & 36 deletions refresh/fromswagger/generatorUtils.js

This file was deleted.

149 changes: 0 additions & 149 deletions refresh/fromswagger/swaggerize.js

This file was deleted.

10 changes: 8 additions & 2 deletions refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var fs = require('fs')

var actions = require('../lib/actions')
var helpers = require('../lib/helpers')
var swaggerize = require('./fromswagger/swaggerize')
var swaggerize = require('ibm-openapi-support')
var sdkHelper = require('../lib/sdkGenHelper')
var performSDKGenerationAsync = sdkHelper.performSDKGenerationAsync
var getClientSDKAsync = sdkHelper.getClientSDKAsync
Expand Down Expand Up @@ -799,8 +799,13 @@ module.exports = Generator.extend({
},

parseOpenApiDocument: function () {
let formatters = {
'pathFormatter': helpers.reformatPathToSwiftKitura,
'resourceFormatter': helpers.resourceNameFromPath
}

if (this.openApiDocumentBytes) {
return swaggerize.parse(this.openApiDocumentBytes, helpers.reformatPathToSwift)
return swaggerize.parse(this.openApiDocumentBytes, formatters)
.then(response => {
this.loadedApi = response.loaded
this.parsedSwagger = response.parsed
Expand Down Expand Up @@ -1058,6 +1063,7 @@ module.exports = Generator.extend({
createFromSwagger: function () {
if (this.parsedSwagger) {
Object.keys(this.parsedSwagger.resources).forEach(resource => {
debug(resource)
this.fs.copyHbs(
this.templatePath('fromswagger', 'Routes.swift.hbs'),
this.destinationPath('Sources', this.applicationModule, 'Routes', `${resource}Routes.swift`),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ describe('Unit tests for helpers', function () {

describe('swagger path formatter', function () {
it('convert swagger path parameters to swift format', function () {
assert(helpers.reformatPathToSwift('/helper/ff/test/{p1}/{p2}') === '/helper/ff/test/:p1/:p2')
assert(helpers.reformatPathToSwiftKitura('/helper/ff/test/{p1}/{p2}') === '/helper/ff/test/:p1/:p2')
})
})
})
35 changes: 0 additions & 35 deletions test/unit/swaggerize.js

This file was deleted.

0 comments on commit cb6e809

Please sign in to comment.