swaggerhub-cli 0.12.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +239 -126
  2. package/oclif.manifest.json +372 -175
  3. package/package.json +8 -5
  4. package/src/commands/api/clone.js +65 -0
  5. package/src/commands/api/create.js +2 -2
  6. package/src/commands/api/delete.js +1 -1
  7. package/src/commands/api/get.js +2 -2
  8. package/src/commands/api/publish.js +1 -1
  9. package/src/commands/api/setdefault.js +1 -1
  10. package/src/commands/api/update.js +3 -3
  11. package/src/commands/api/validate/download-rules.js +5 -5
  12. package/src/commands/api/validate/index.js +2 -2
  13. package/src/commands/api/validate/local.js +3 -3
  14. package/src/commands/configure.js +2 -2
  15. package/src/commands/domain/clone.js +65 -0
  16. package/src/commands/domain/create.js +6 -6
  17. package/src/commands/domain/delete.js +1 -1
  18. package/src/commands/domain/get.js +1 -1
  19. package/src/commands/domain/publish.js +13 -6
  20. package/src/commands/domain/rename.js +77 -0
  21. package/src/commands/domain/setdefault.js +1 -1
  22. package/src/commands/domain/unpublish.js +1 -1
  23. package/src/commands/domain/update.js +3 -3
  24. package/src/commands/integration/create.js +2 -2
  25. package/src/commands/integration/delete.js +1 -1
  26. package/src/commands/integration/execute.js +1 -1
  27. package/src/commands/integration/get.js +2 -2
  28. package/src/commands/integration/list.js +1 -1
  29. package/src/commands/integration/update.js +1 -1
  30. package/src/commands/project/api/add.js +2 -2
  31. package/src/commands/project/api/remove.js +3 -3
  32. package/src/commands/project/create.js +4 -4
  33. package/src/commands/project/delete.js +2 -2
  34. package/src/commands/project/domain/add.js +2 -2
  35. package/src/commands/project/domain/remove.js +3 -3
  36. package/src/commands/project/get.js +1 -1
  37. package/src/commands/project/list.js +27 -8
  38. package/src/commands/project/member/list.js +2 -2
  39. package/src/commands/spectral/download.js +1 -1
  40. package/src/commands/spectral/upload.js +1 -1
  41. package/src/support/command/base-command.js +1 -1
  42. package/src/support/command/update-command.js +20 -4
  43. package/src/support/http/index.js +2 -1
  44. package/src/support/http/proxy-agent.js +25 -0
  45. package/src/support/inquirer/prompt-templates.js +1 -1
  46. package/src/support/isOnPrem.js +2 -2
  47. package/src/template-strings/errors.js +4 -4
  48. package/src/template-strings/info.js +8 -2
@@ -35,11 +35,11 @@ ProjectApiAddCommand.examples = [
35
35
  ProjectApiAddCommand.args = {
36
36
  'OWNER/PROJECT_NAME': Args.string({
37
37
  required: true,
38
- description: 'The project to add the API to on Swaggerhub'
38
+ description: 'The project to add the API to on Swagger'
39
39
  }),
40
40
  'API': Args.string({
41
41
  required: true,
42
- description: 'The name of the API on Swaggerhub to add'
42
+ description: 'The name of the API on Swagger to add'
43
43
  })
44
44
  }
45
45
 
@@ -48,7 +48,7 @@ class ProjectApiRemoveCommand extends BaseCommand {
48
48
  }
49
49
  }
50
50
 
51
- ProjectApiRemoveCommand.description = 'Removes an API from a project in SwaggerHub.'
51
+ ProjectApiRemoveCommand.description = 'Removes an API from a project in Swagger.'
52
52
 
53
53
  ProjectApiRemoveCommand.examples = [
54
54
  'swaggerhub project:api:remove organization/project_name my_api',
@@ -57,11 +57,11 @@ ProjectApiRemoveCommand.examples = [
57
57
  ProjectApiRemoveCommand.args = {
58
58
  'OWNER/PROJECT_NAME': Args.string({
59
59
  required: true,
60
- description: 'The project to remove the API from on Swaggerhub'
60
+ description: 'The project to remove the API from on Swagger'
61
61
  }),
62
62
  'API': Args.string({
63
63
  required: true,
64
- description: 'The name of the API on Swaggerhub to remove'
64
+ description: 'The name of the API on Swagger to remove'
65
65
  })
66
66
  }
67
67
 
@@ -39,7 +39,7 @@ class CreateProjectCommand extends BaseCommand {
39
39
  }
40
40
  }
41
41
 
42
- CreateProjectCommand.description = 'Creates a new project in SwaggerHub.'
42
+ CreateProjectCommand.description = 'Creates a new project in Swagger.'
43
43
 
44
44
  CreateProjectCommand.examples = [
45
45
  'swaggerhub project:create organization/new_project_name --description "project description"',
@@ -53,7 +53,7 @@ CreateProjectCommand.examples = [
53
53
  CreateProjectCommand.args = {
54
54
  'OWNER/PROJECT_NAME': Args.string({
55
55
  required: true,
56
- description: 'The new project to create on Swaggerhub'
56
+ description: 'The new project to create on Swagger'
57
57
  })
58
58
  }
59
59
 
@@ -64,12 +64,12 @@ CreateProjectCommand.flags = {
64
64
  }),
65
65
  apis: Flags.string({
66
66
  char: 'a',
67
- description: 'Comma separated list of api names to include in project',
67
+ description: 'Comma-separated list of API names to include in project',
68
68
  required: false
69
69
  }),
70
70
  domains: Flags.string({
71
71
  char: 'd',
72
- description: 'Comma separated list of domain names to include in project',
72
+ description: 'Comma-separated list of domain names to include in project',
73
73
  required: false
74
74
  }),
75
75
  ...BaseCommand.flags
@@ -26,7 +26,7 @@ class DeleteProjectCommand extends BaseCommand {
26
26
  }
27
27
  }
28
28
 
29
- DeleteProjectCommand.description = 'Deletes a project from SwaggerHub.'
29
+ DeleteProjectCommand.description = 'Deletes a project from Swagger.'
30
30
 
31
31
  DeleteProjectCommand.examples = [
32
32
  'swaggerhub project:delete organization/project_name'
@@ -35,7 +35,7 @@ DeleteProjectCommand.examples = [
35
35
  DeleteProjectCommand.args = {
36
36
  'OWNER/PROJECT_NAME': Args.string({
37
37
  required: true,
38
- description: 'The project to delete on Swaggerhub'
38
+ description: 'The project to delete on Swagger'
39
39
  })
40
40
  }
41
41
 
@@ -35,11 +35,11 @@ ProjectDomainAddCommand.examples = [
35
35
  ProjectDomainAddCommand.args = {
36
36
  'OWNER/PROJECT_NAME': Args.string({
37
37
  required: true,
38
- description: 'The project to add the domain to on Swaggerhub'
38
+ description: 'The project to add the domain to on Swagger'
39
39
  }),
40
40
  'DOMAIN': Args.string({
41
41
  required: true,
42
- description: 'The name of the domain on Swaggerhub to add'
42
+ description: 'The name of the domain on Swagger to add'
43
43
  })
44
44
  }
45
45
 
@@ -48,7 +48,7 @@ class ProjectDomainRemoveCommand extends BaseCommand {
48
48
  }
49
49
  }
50
50
 
51
- ProjectDomainRemoveCommand.description = 'Removes a domain from a project in SwaggerHub.'
51
+ ProjectDomainRemoveCommand.description = 'Removes a domain from a project in Swagger.'
52
52
 
53
53
  ProjectDomainRemoveCommand.examples = [
54
54
  'swaggerhub project:domain:remove organization/project_name my_domain',
@@ -57,11 +57,11 @@ ProjectDomainRemoveCommand.examples = [
57
57
  ProjectDomainRemoveCommand.args = {
58
58
  'OWNER/PROJECT_NAME': Args.string({
59
59
  required: true,
60
- description: 'The project to remove the domain from on Swaggerhub'
60
+ description: 'The project to remove the domain from on Swagger'
61
61
  }),
62
62
  'DOMAIN': Args.string({
63
63
  required: true,
64
- description: 'The name of the domain on Swaggerhub to remove'
64
+ description: 'The name of the domain on Swagger to remove'
65
65
  })
66
66
  }
67
67
 
@@ -42,7 +42,7 @@ GetProjectCommand.examples = [
42
42
  GetProjectCommand.args = {
43
43
  'OWNER/PROJECT_NAME': Args.string({
44
44
  required: true,
45
- description: 'The project to get details for on Swaggerhub'
45
+ description: 'The project to get details for on Swagger'
46
46
  })
47
47
  }
48
48
 
@@ -1,4 +1,4 @@
1
- const { ux, Args } = require('@oclif/core')
1
+ const { ux, Args, Flags } = require('@oclif/core')
2
2
  const { getProject } = require('../../requests/project')
3
3
  const { getResponseContent } = require('../../support/command/handle-response')
4
4
  const BaseCommand = require('../../support/command/base-command')
@@ -10,8 +10,8 @@ class ListProjectCommand extends BaseCommand {
10
10
  }
11
11
 
12
12
  async run() {
13
- const { args } = await this.parse(ListProjectCommand)
14
- await this.listProjects(args['OWNER'])
13
+ const { args, flags } = await this.parse(ListProjectCommand)
14
+ await this.listProjects(args['OWNER'], flags)
15
15
  }
16
16
 
17
17
  async logProject(response) {
@@ -33,9 +33,12 @@ class ListProjectCommand extends BaseCommand {
33
33
  }
34
34
  }
35
35
 
36
- async listProjects(args) {
36
+ async listProjects(owner, { limit, page, order }) {
37
+ const queryParams = Object.fromEntries(
38
+ Object.entries({ limit, page, order }).filter(([, value]) => value !== undefined)
39
+ )
37
40
  return this.executeHttp({
38
- execute: () => getProject([args]),
41
+ execute: () => getProject([owner], Object.keys(queryParams).length ? queryParams : undefined),
39
42
  onResolve: this.logProject,
40
43
  options: {}
41
44
  })
@@ -46,18 +49,34 @@ ListProjectCommand.description = 'list projects'
46
49
 
47
50
  ListProjectCommand.examples = [
48
51
  'swaggerhub project:list',
49
- 'swaggerhub project:list organization'
52
+ 'swaggerhub project:list organization',
53
+ 'swaggerhub project:list organization --limit 20 --order DESC',
54
+ 'swaggerhub project:list organization --page 2 --limit 20'
50
55
  ]
51
56
 
52
57
  ListProjectCommand.args = {
53
58
  'OWNER': Args.string({
54
59
  required: false,
55
- description: 'The organization to list projects for on Swaggerhub'
60
+ description: 'The organization to list projects for on Swagger'
56
61
  })
57
62
  }
58
63
 
59
64
  ListProjectCommand.flags = {
60
- ...BaseCommand.flags
65
+ ...BaseCommand.flags,
66
+ limit: Flags.integer({
67
+ char: 'l',
68
+ min: 1,
69
+ max: 100,
70
+ description: 'number of projects per page (1-100)'
71
+ }),
72
+ page: Flags.integer({
73
+ min: 0,
74
+ description: 'zero-based page of projects to return'
75
+ }),
76
+ order: Flags.string({
77
+ options: ['ASC', 'DESC'],
78
+ description: 'sort order of the projects'
79
+ })
61
80
  }
62
81
 
63
82
  module.exports = ListProjectCommand
@@ -44,13 +44,13 @@ class ListProjectMembersCommand extends BaseCommand {
44
44
  ListProjectMembersCommand.description = 'list members of a project'
45
45
 
46
46
  ListProjectMembersCommand.examples = [
47
- 'swaggerhub project:member:list organisation/project_name',
47
+ 'swaggerhub project:member:list organization/project_name',
48
48
  ]
49
49
 
50
50
  ListProjectMembersCommand.args = {
51
51
  'OWNER/PROJECT_NAME': Args.string({
52
52
  required: true,
53
- description: 'Project to list members of on Swaggerhub'
53
+ description: 'Project to list members of'
54
54
  })
55
55
  }
56
56
 
@@ -54,7 +54,7 @@ DownloadSpectralRulesetCommand.examples = [
54
54
  DownloadSpectralRulesetCommand.args = {
55
55
  'OWNER/RULESET_NAME': Args.string({
56
56
  required: true,
57
- description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
57
+ description: 'Organization\'s Spectral ruleset to create or update on Swagger'
58
58
  }),
59
59
  'directory': Args.string({
60
60
  required: true,
@@ -44,7 +44,7 @@ UploadSpectralRulesetCommand.examples = [
44
44
  UploadSpectralRulesetCommand.args = {
45
45
  'OWNER/RULESET_NAME': Args.string({
46
46
  required: true,
47
- description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
47
+ description: 'Organization\'s Spectral ruleset to create or update on Swagger'
48
48
  }),
49
49
  'directory': Args.string({
50
50
  required: true,
@@ -72,7 +72,7 @@ class BaseCommand extends Command {
72
72
  executeHttp({ execute, onResolve, onReject = handleErrors, options: { resolveStatus = [] } }) {
73
73
 
74
74
  if (!config.isURLValid()) {
75
- this.error('Please verify that the configured SwaggerHub URL is correct.')
75
+ this.error('Please verify that the configured Swagger URL is correct.')
76
76
  }
77
77
 
78
78
  return execute()
@@ -1,6 +1,7 @@
1
1
  const BaseCommand = require('./base-command')
2
2
  const { putSpec } = require('../../requests/spec')
3
3
  const { handleErrors } = require('./handle-response')
4
+ const inquirer = require('inquirer')
4
5
 
5
6
  class UpdateCommand extends BaseCommand {
6
7
 
@@ -8,20 +9,21 @@ class UpdateCommand extends BaseCommand {
8
9
  const pathParams = [owner, name, version, 'settings', 'lifecycle']
9
10
  const body = JSON.stringify({ published: isPublished })
10
11
  const successMessage = isPublished ? 'published' : 'unpublished'
12
+ const typeLabel = type === 'apis' ? 'API' : 'domain'
11
13
 
12
14
  await this.executeHttp({
13
15
  execute: () => flags.force ? putSpec(type, pathParams, body, flags) : putSpec(type, pathParams, body),
14
16
  onResolve: this.setSuccessMessage(successMessage)({
15
- type: type === 'apis' ? 'API' : 'domain',
17
+ type: typeLabel,
16
18
  path: `${owner}/${name}/${version}`
17
19
  }),
18
20
  onReject: async err => {
19
- if (err.status === 424 && type === 'apis') {
21
+ if (err.status === 424) {
20
22
  if (await this.confirmPublish() === true) {
21
- this.executeHttp({
23
+ await this.executeHttp({
22
24
  execute: () => putSpec(type, pathParams, body, { 'force': 'true' }),
23
25
  onResolve: this.setSuccessMessage(successMessage)({
24
- type: 'API',
26
+ type: typeLabel,
25
27
  path: `${owner}/${name}/${version}`
26
28
  }),
27
29
  options: { resolveStatus: [403] }
@@ -35,6 +37,20 @@ class UpdateCommand extends BaseCommand {
35
37
  })
36
38
  }
37
39
 
40
+ async confirmPublish() {
41
+ const confirm = await inquirer.prompt([
42
+ {
43
+ type: 'confirm',
44
+ name: 'answer',
45
+ message: `A conflict was detected with other resources referencing or referenced by this definition.
46
+ Forcing the change may affect them.
47
+ Do you wish to continue?`,
48
+ default: false
49
+ }
50
+ ])
51
+ return confirm.answer
52
+ }
53
+
38
54
  async updateDefault(type, owner, name, version) {
39
55
  const pathParams = [owner, name, 'settings', 'default']
40
56
  const body = JSON.stringify({ version })
@@ -2,6 +2,7 @@ const fetch = require('node-fetch')
2
2
  const qs = require('querystring')
3
3
  const headerTemplates = require('./header-templates')
4
4
  const defaultHeaders = require('./default-headers')
5
+ const { agentFor } = require('./proxy-agent')
5
6
 
6
7
  const { pipe, pick, omit } = require('../../utils/general')
7
8
 
@@ -34,7 +35,7 @@ const parseHeaders = options => {
34
35
  }
35
36
  }
36
37
 
37
- const request = ({ url, ...options }) => fetch(url, options)
38
+ const request = ({ url, ...options }) => fetch(url, { agent: agentFor, ...options })
38
39
 
39
40
  module.exports = options => (
40
41
  pipe(parseQuery, parseUrl, parseHeaders, request)(options)
@@ -0,0 +1,25 @@
1
+ const { getProxyForUrl } = require('proxy-from-env')
2
+ const { HttpsProxyAgent } = require('https-proxy-agent')
3
+ const { HttpProxyAgent } = require('http-proxy-agent')
4
+
5
+ const normalizeProxy = proxy => {
6
+ try {
7
+ return new URL(proxy).href
8
+ } catch {
9
+ throw new Error('Invalid proxy URL in HTTP_PROXY/HTTPS_PROXY environment variable')
10
+ }
11
+ }
12
+
13
+ const agentFor = parsedUrl => {
14
+ const proxy = getProxyForUrl(parsedUrl.href)
15
+ if (!proxy) {
16
+ return undefined
17
+ }
18
+
19
+ const proxyUrl = normalizeProxy(proxy)
20
+ return parsedUrl.protocol === 'https:' ?
21
+ new HttpsProxyAgent(proxyUrl) :
22
+ new HttpProxyAgent(proxyUrl)
23
+ }
24
+
25
+ module.exports = { agentFor }
@@ -2,7 +2,7 @@ const { wrapTemplates } = require('../../utils/general')
2
2
 
3
3
  const swaggerHubUrl = {
4
4
  name: 'SWAGGERHUB_URL',
5
- message: 'SwaggerHub URL:',
5
+ message: 'Swagger URL:',
6
6
  default: '{{SWAGGERHUB_URL}}'
7
7
  }
8
8
 
@@ -1,7 +1,7 @@
1
- const { getConfig } = require('../config')
1
+ const config = require('../config')
2
2
 
3
3
  const isOnPrem = () => {
4
- const { SWAGGERHUB_URL } = getConfig()
4
+ const { SWAGGERHUB_URL } = config.getConfig()
5
5
  return !SWAGGERHUB_URL.endsWith('swaggerhub.com')
6
6
  }
7
7
 
@@ -1,15 +1,15 @@
1
1
  const { wrapTemplates } = require('../utils/general')
2
2
 
3
3
  const errorMsg = {
4
- ApiCreate: 'API version \'{{owner}}/{{name}}/{{version}}\' already exists in SwaggerHub',
4
+ ApiCreate: 'API version \'{{owner}}/{{name}}/{{version}}\' already exists in Swagger',
5
5
 
6
- DomainCreate: 'Domain version \'{{owner}}/{{name}}/{{version}}\' already exists in SwaggerHub',
6
+ DomainCreate: 'Domain version \'{{owner}}/{{name}}/{{version}}\' already exists in Swagger',
7
7
 
8
8
  Configure: 'Failed to write config to {{configFilePath}}',
9
9
 
10
10
  argsMustMatchFormat: 'Argument must match {{format}} format',
11
11
 
12
- cannotParseDefinition: 'There was a problem with parsing {{filename}}. \nReason: {{e}}',
12
+ cannotParseDefinition: 'There was a problem parsing {{filename}}. \nReason: {{e}}',
13
13
 
14
14
  cannotParseSpecification: 'Cannot determine specification from file',
15
15
 
@@ -25,7 +25,7 @@ const errorMsg = {
25
25
 
26
26
  directoryExists: 'Directory already exists: \'{{directory}}\'',
27
27
 
28
- unknown: 'Unknown Error',
28
+ unknown: 'Unknown error',
29
29
  }
30
30
 
31
31
  module.exports = wrapTemplates({
@@ -7,6 +7,12 @@ const infoMsg = {
7
7
 
8
8
  ApiRename: 'Renamed API \'{{apiPath}}\' to \'{{newName}}\'',
9
9
 
10
+ ApiClone: 'Cloned API \'{{apiPath}}\' as version {{newVersion}}',
11
+
12
+ DomainClone: 'Cloned domain \'{{domainPath}}\' as version {{newVersion}}',
13
+
14
+ DomainRename: 'Renamed domain \'{{domainPath}}\' to \'{{newName}}\'',
15
+
10
16
  DomainCreate: 'Created domain \'{{owner}}/{{name}}\'',
11
17
 
12
18
  DomainDelete: 'Deleted domain \'{{owner}}/{{name}}\'',
@@ -51,9 +57,9 @@ const infoMsg = {
51
57
 
52
58
  ProjectUpdate: 'Updated project \'{{owner}}/{{projectName}}\'',
53
59
 
54
- ProjectApiAdd: 'Added api \'{{apiName}}\' to project \'{{projectPath}}\'',
60
+ ProjectApiAdd: 'Added API \'{{apiName}}\' to project \'{{projectPath}}\'',
55
61
 
56
- ProjectApiRemove: 'Removed api \'{{apiName}}\' from project \'{{projectPath}}\'',
62
+ ProjectApiRemove: 'Removed API \'{{apiName}}\' from project \'{{projectPath}}\'',
57
63
 
58
64
  ProjectDomainAdd: 'Added domain \'{{domainName}}\' to project \'{{projectPath}}\'',
59
65