swaggerhub-cli 0.3.0 → 0.6.1
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 +396 -68
- package/oclif.manifest.json +1 -1
- package/package.json +23 -20
- package/src/commands/api/create.js +7 -6
- package/src/commands/api/delete.js +63 -0
- package/src/commands/api/publish.js +1 -1
- package/src/commands/api/unpublish.js +5 -13
- package/src/commands/api/update.js +21 -41
- package/src/commands/domain/create.js +5 -4
- package/src/commands/domain/delete.js +63 -0
- package/src/commands/domain/publish.js +1 -1
- package/src/commands/domain/setdefault.js +30 -0
- package/src/commands/domain/unpublish.js +4 -12
- package/src/commands/domain/update.js +109 -0
- package/src/commands/project/api/add.js +48 -0
- package/src/commands/project/api/remove.js +69 -0
- package/src/commands/project/create.js +77 -0
- package/src/commands/project/delete.js +44 -0
- package/src/commands/project/domain/add.js +48 -0
- package/src/commands/project/domain/remove.js +69 -0
- package/src/commands/project/get.js +51 -0
- package/src/commands/project/list.js +62 -0
- package/src/commands/project/member/list.js +60 -0
- package/src/config/index.js +2 -1
- package/src/format-readme.js +38 -0
- package/src/help.js +1 -1
- package/src/requests/domain.js +4 -4
- package/src/requests/project.js +20 -0
- package/src/requests/spec.js +3 -2
- package/src/support/command/parse-input.js +14 -0
- package/src/support/command/update-command.js +21 -3
- package/src/template-strings/errors.js +1 -1
- package/src/template-strings/info.js +32 -3
- package/src/utils/oas.js +3 -3
package/src/help.js
CHANGED
package/src/requests/domain.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
const { getSpec,
|
|
1
|
+
const { getSpec, postSpec, deleteSpec } = require('./spec')
|
|
2
2
|
|
|
3
3
|
const getDomain = (pathParams, queryParams, accept = 'json') =>
|
|
4
4
|
getSpec('domains', pathParams, queryParams, accept)
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const deleteDomain = (pathParams, queryParams) =>
|
|
7
|
+
deleteSpec('domains', pathParams, queryParams)
|
|
8
8
|
|
|
9
9
|
const postDomain = ({ pathParams, queryParams, body }) =>
|
|
10
10
|
postSpec('domains', pathParams, queryParams, body)
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
|
13
13
|
getDomain,
|
|
14
|
-
|
|
14
|
+
deleteDomain,
|
|
15
15
|
postDomain
|
|
16
16
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { getSpec, postSpec, deleteSpec, putSpec } = require('./spec')
|
|
2
|
+
|
|
3
|
+
const getProject = (pathParams, queryParams, accept = 'json') =>
|
|
4
|
+
getSpec('projects', pathParams, queryParams, accept)
|
|
5
|
+
|
|
6
|
+
const postProject = ({ pathParams, queryParams, body }) =>
|
|
7
|
+
postSpec('projects', pathParams, queryParams, body)
|
|
8
|
+
|
|
9
|
+
const putProject = ({ pathParams, body }) =>
|
|
10
|
+
putSpec('projects', pathParams, body)
|
|
11
|
+
|
|
12
|
+
const deleteProject = pathParams =>
|
|
13
|
+
deleteSpec('projects', pathParams)
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
getProject,
|
|
17
|
+
postProject,
|
|
18
|
+
putProject,
|
|
19
|
+
deleteProject
|
|
20
|
+
}
|
package/src/requests/spec.js
CHANGED
|
@@ -12,13 +12,14 @@ const getSpec = (specType, pathParams, queryParams, accept) => {
|
|
|
12
12
|
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const deleteSpec = (specType, pathParams) => {
|
|
15
|
+
const deleteSpec = (specType, pathParams, queryParams) => {
|
|
16
16
|
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
17
17
|
return http({
|
|
18
18
|
url: [SWAGGERHUB_URL, specType, ...pathParams],
|
|
19
19
|
auth: SWAGGERHUB_API_KEY,
|
|
20
20
|
contentType: 'json',
|
|
21
|
-
method: 'DELETE'
|
|
21
|
+
method: 'DELETE',
|
|
22
|
+
query: queryParams
|
|
22
23
|
})
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -6,6 +6,7 @@ const { errorMsg } = require('../../template-strings')
|
|
|
6
6
|
const optionalVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+(\/[\w\-.]+)?(\/?)$/)
|
|
7
7
|
const requiredVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
8
8
|
const integrationIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
9
|
+
const projectIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
|
|
9
10
|
|
|
10
11
|
const isValidIdentifier = (id, isVersionRequired) => isVersionRequired
|
|
11
12
|
? requiredVersionRegex.test(id)
|
|
@@ -42,6 +43,15 @@ const getIntegrationIdentifierArg = args => {
|
|
|
42
43
|
return identifier
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const getProjectIdentifierArg = args => {
|
|
47
|
+
const format = 'OWNER/PROJECT_NAME'
|
|
48
|
+
const identifier = args[format]
|
|
49
|
+
if (!projectIdentifierRegex.test(identifier)) {
|
|
50
|
+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
|
|
51
|
+
}
|
|
52
|
+
return identifier
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
const readConfigFile = filename => {
|
|
46
56
|
if (!existsSync(filename)) {
|
|
47
57
|
throw new CLIError(errorMsg.fileNotFound({ filename }))
|
|
@@ -60,6 +70,8 @@ const readConfigFile = filename => {
|
|
|
60
70
|
|
|
61
71
|
const splitPathParams = path => path.split('/').filter(Boolean)
|
|
62
72
|
|
|
73
|
+
const splitFlagParams = flag => flag.split(',').map(param => param.trim()).filter(Boolean)
|
|
74
|
+
|
|
63
75
|
const reqType = ({ json }) => json ? 'json' : 'yaml'
|
|
64
76
|
|
|
65
77
|
const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
|
|
@@ -68,8 +80,10 @@ module.exports = {
|
|
|
68
80
|
getApiIdentifierArg,
|
|
69
81
|
getDomainIdentifierArg,
|
|
70
82
|
getIntegrationIdentifierArg,
|
|
83
|
+
getProjectIdentifierArg,
|
|
71
84
|
readConfigFile,
|
|
72
85
|
splitPathParams,
|
|
86
|
+
splitFlagParams,
|
|
73
87
|
reqType,
|
|
74
88
|
resolvedParam,
|
|
75
89
|
isValidIdentifier
|
|
@@ -3,13 +3,14 @@ const { putSpec } = require('../../requests/spec')
|
|
|
3
3
|
|
|
4
4
|
class UpdateCommand extends BaseCommand {
|
|
5
5
|
|
|
6
|
-
async updatePublish(type, owner, name, version) {
|
|
6
|
+
async updatePublish(type, owner, name, version, isPublished) {
|
|
7
7
|
const pathParams = [owner, name, version, 'settings', 'lifecycle']
|
|
8
|
-
const body = JSON.stringify({ published:
|
|
8
|
+
const body = JSON.stringify({ published: isPublished })
|
|
9
|
+
const successMessage = isPublished ? 'published' : 'unpublished'
|
|
9
10
|
|
|
10
11
|
await this.executeHttp({
|
|
11
12
|
execute: () => putSpec(type, pathParams, body),
|
|
12
|
-
onResolve: this.setSuccessMessage(
|
|
13
|
+
onResolve: this.setSuccessMessage(successMessage)({
|
|
13
14
|
type: type === 'apis' ? 'API' : 'domain',
|
|
14
15
|
path: `${owner}/${name}/${version}`
|
|
15
16
|
}),
|
|
@@ -31,6 +32,23 @@ class UpdateCommand extends BaseCommand {
|
|
|
31
32
|
options: { resolveStatus: [403] }
|
|
32
33
|
})
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
async updateVisibility(type, owner, name, version, isPrivate) {
|
|
37
|
+
const visibility = isPrivate ? 'private' : 'public'
|
|
38
|
+
const pathParams = [owner, name, version, 'settings', 'private']
|
|
39
|
+
const body = JSON.stringify({ private: isPrivate })
|
|
40
|
+
|
|
41
|
+
await this.executeHttp({
|
|
42
|
+
execute: () => putSpec(type, pathParams, body),
|
|
43
|
+
onResolve: this.setSuccessMessage('visibilityUpdate')({
|
|
44
|
+
owner,
|
|
45
|
+
name,
|
|
46
|
+
version: version,
|
|
47
|
+
visibility
|
|
48
|
+
}),
|
|
49
|
+
options: { resolveStatus: [403] }
|
|
50
|
+
})
|
|
51
|
+
}
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
module.exports = UpdateCommand
|
|
@@ -9,7 +9,7 @@ const errorMsg = {
|
|
|
9
9
|
|
|
10
10
|
argsMustMatchFormat: 'Argument must match {{format}} format',
|
|
11
11
|
|
|
12
|
-
cannotParseDefinition: 'There was a problem with parsing {{filename}}.
|
|
12
|
+
cannotParseDefinition: 'There was a problem with parsing {{filename}}. \nReason: {{e}}',
|
|
13
13
|
|
|
14
14
|
cannotParseOasVersion: 'Cannot determine OAS version from file',
|
|
15
15
|
|
|
@@ -3,19 +3,33 @@ const { wrapTemplates } = require('../utils/general')
|
|
|
3
3
|
const infoMsg = {
|
|
4
4
|
ApiCreate: 'Created API \'{{owner}}/{{name}}\'',
|
|
5
5
|
|
|
6
|
+
ApiDelete: 'Deleted API \'{{owner}}/{{name}}\'',
|
|
7
|
+
|
|
6
8
|
DomainCreate: 'Created domain \'{{owner}}/{{name}}\'',
|
|
7
9
|
|
|
10
|
+
DomainDelete: 'Deleted domain \'{{owner}}/{{name}}\'',
|
|
11
|
+
|
|
8
12
|
createdApiVersion: 'Created version {{version}} of API \'{{owner}}/{{name}}\'',
|
|
9
13
|
|
|
10
14
|
createdDomainVersion: 'Created version {{version}} of domain \'{{owner}}/{{name}}\'',
|
|
11
15
|
|
|
16
|
+
deletedVersion: 'Deleted version {{version}} of {{type}} \'{{owner}}/{{name}}\'',
|
|
17
|
+
|
|
12
18
|
published: 'Published {{type}} {{path}}',
|
|
13
19
|
|
|
20
|
+
unpublished: 'Unpublished {{type}} {{path}}',
|
|
21
|
+
|
|
14
22
|
setDefault: 'Default version of {{owner}}/{{name}} set to {{version}}',
|
|
15
23
|
|
|
16
|
-
ApiUpdate: 'Updated API {{owner}}/{{name}}/{{version}}
|
|
24
|
+
ApiUpdate: 'Updated API {{owner}}/{{name}}/{{version}}',
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
DomainUpdate: 'Updated domain {{owner}}/{{name}}/{{version}}',
|
|
27
|
+
|
|
28
|
+
ApiUpdateVisibility: 'Updated API {{owner}}/{{name}}/{{version}} and visibility is set to {{visibility}}',
|
|
29
|
+
|
|
30
|
+
DomainUpdateVisibility: 'Updated domain {{owner}}/{{name}}/{{version}} and visibility is set to {{visibility}}',
|
|
31
|
+
|
|
32
|
+
visibilityUpdate: 'Updated visibility of {{owner}}/{{name}}/{{version}} to {{visibility}}',
|
|
19
33
|
|
|
20
34
|
ApiUnpublish: 'Unpublished API {{apiPath}}',
|
|
21
35
|
|
|
@@ -29,7 +43,22 @@ const infoMsg = {
|
|
|
29
43
|
|
|
30
44
|
IntegrationUpdate: 'Updated integration \'{{integrationId}}\' on API \'{{apiPath}}\'',
|
|
31
45
|
|
|
32
|
-
Configure: 'Saved config to {{configFilePath}}'
|
|
46
|
+
Configure: 'Saved config to {{configFilePath}}',
|
|
47
|
+
|
|
48
|
+
ProjectCreate: 'Created project \'{{owner}}/{{projectName}}\'',
|
|
49
|
+
|
|
50
|
+
ProjectUpdate: 'Updated project \'{{owner}}/{{projectName}}\'',
|
|
51
|
+
|
|
52
|
+
ProjectApiAdd: 'Added api \'{{apiName}}\' to project \'{{projectPath}}\'',
|
|
53
|
+
|
|
54
|
+
ProjectApiRemove: 'Removed api \'{{apiName}}\' from project \'{{projectPath}}\'',
|
|
55
|
+
|
|
56
|
+
ProjectDomainAdd: 'Added domain \'{{domainName}}\' to project \'{{projectPath}}\'',
|
|
57
|
+
|
|
58
|
+
ProjectDomainRemove: 'Removed domain \'{{domainName}}\' from project \'{{projectPath}}\'',
|
|
59
|
+
|
|
60
|
+
ProjectDelete: 'Deleted project \'{{projectPath}}\''
|
|
61
|
+
|
|
33
62
|
}
|
|
34
63
|
|
|
35
64
|
module.exports = wrapTemplates({
|
package/src/utils/oas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { CLIError } = require('@oclif/errors')
|
|
2
2
|
const { hasJsonStructure } = require('./general')
|
|
3
|
-
const
|
|
3
|
+
const yaml = require('js-yaml')
|
|
4
4
|
const { existsSync, readFileSync } = require('fs-extra')
|
|
5
5
|
const { errorMsg } = require('../template-strings')
|
|
6
6
|
|
|
@@ -27,9 +27,9 @@ const parseDefinition = filename => {
|
|
|
27
27
|
throw new CLIError(errorMsg.fileIsEmpty({ filename }))
|
|
28
28
|
}
|
|
29
29
|
try {
|
|
30
|
-
return hasJsonStructure(file) ? JSON.parse(file) :
|
|
30
|
+
return hasJsonStructure(file) ? JSON.parse(file) : yaml.load(file)
|
|
31
31
|
} catch (e) {
|
|
32
|
-
throw new CLIError(errorMsg.cannotParseDefinition({ filename, e: JSON.stringify(e) }))
|
|
32
|
+
throw new CLIError(errorMsg.cannotParseDefinition({ filename, e: JSON.stringify(e.message).replace(/\\n/g, '\n') }))
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|