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.
- package/README.md +239 -126
- package/oclif.manifest.json +372 -175
- package/package.json +8 -5
- package/src/commands/api/clone.js +65 -0
- package/src/commands/api/create.js +2 -2
- package/src/commands/api/delete.js +1 -1
- package/src/commands/api/get.js +2 -2
- package/src/commands/api/publish.js +1 -1
- package/src/commands/api/setdefault.js +1 -1
- package/src/commands/api/update.js +3 -3
- package/src/commands/api/validate/download-rules.js +5 -5
- package/src/commands/api/validate/index.js +2 -2
- package/src/commands/api/validate/local.js +3 -3
- package/src/commands/configure.js +2 -2
- package/src/commands/domain/clone.js +65 -0
- package/src/commands/domain/create.js +6 -6
- package/src/commands/domain/delete.js +1 -1
- package/src/commands/domain/get.js +1 -1
- package/src/commands/domain/publish.js +13 -6
- package/src/commands/domain/rename.js +77 -0
- package/src/commands/domain/setdefault.js +1 -1
- package/src/commands/domain/unpublish.js +1 -1
- package/src/commands/domain/update.js +3 -3
- package/src/commands/integration/create.js +2 -2
- package/src/commands/integration/delete.js +1 -1
- package/src/commands/integration/execute.js +1 -1
- package/src/commands/integration/get.js +2 -2
- package/src/commands/integration/list.js +1 -1
- package/src/commands/integration/update.js +1 -1
- package/src/commands/project/api/add.js +2 -2
- package/src/commands/project/api/remove.js +3 -3
- package/src/commands/project/create.js +4 -4
- package/src/commands/project/delete.js +2 -2
- package/src/commands/project/domain/add.js +2 -2
- package/src/commands/project/domain/remove.js +3 -3
- package/src/commands/project/get.js +1 -1
- package/src/commands/project/list.js +27 -8
- package/src/commands/project/member/list.js +2 -2
- package/src/commands/spectral/download.js +1 -1
- package/src/commands/spectral/upload.js +1 -1
- package/src/support/command/base-command.js +1 -1
- package/src/support/command/update-command.js +20 -4
- package/src/support/http/index.js +2 -1
- package/src/support/http/proxy-agent.js +25 -0
- package/src/support/inquirer/prompt-templates.js +1 -1
- package/src/support/isOnPrem.js +2 -2
- package/src/template-strings/errors.js +4 -4
- 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
64
|
+
description: 'The name of the domain on Swagger to remove'
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -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(
|
|
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([
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
17
|
+
type: typeLabel,
|
|
16
18
|
path: `${owner}/${name}/${version}`
|
|
17
19
|
}),
|
|
18
20
|
onReject: async err => {
|
|
19
|
-
if (err.status === 424
|
|
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:
|
|
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 }
|
package/src/support/isOnPrem.js
CHANGED
|
@@ -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
|
|
4
|
+
ApiCreate: 'API version \'{{owner}}/{{name}}/{{version}}\' already exists in Swagger',
|
|
5
5
|
|
|
6
|
-
DomainCreate: 'Domain version \'{{owner}}/{{name}}/{{version}}\' already exists in
|
|
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
|
|
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
|
|
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
|
|
60
|
+
ProjectApiAdd: 'Added API \'{{apiName}}\' to project \'{{projectPath}}\'',
|
|
55
61
|
|
|
56
|
-
ProjectApiRemove: 'Removed
|
|
62
|
+
ProjectApiRemove: 'Removed API \'{{apiName}}\' from project \'{{projectPath}}\'',
|
|
57
63
|
|
|
58
64
|
ProjectDomainAdd: 'Added domain \'{{domainName}}\' to project \'{{projectPath}}\'',
|
|
59
65
|
|