@airtasker/spot
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -99,3 +99,3 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
formatter: (obj) => js_yaml_1.default.safeDump(obj, { skipInvalid: true /* for undefined */ }), | ||
formatter: (obj) => js_yaml_1.default.dump(obj, { skipInvalid: true /* for undefined */ }), | ||
extension: "yml" | ||
@@ -102,0 +102,0 @@ }; |
@@ -13,2 +13,3 @@ import { Type, TypeDef } from "./types"; | ||
endpoints: Endpoint[]; | ||
oa3servers?: Oa3Server[]; | ||
} | ||
@@ -78,2 +79,13 @@ export interface Config { | ||
} | ||
export interface Oa3Server { | ||
url: string; | ||
description?: string; | ||
oa3ServerVariables: Oa3ServerVariable[]; | ||
} | ||
export interface Oa3ServerVariable { | ||
type: Type; | ||
description?: string; | ||
defaultValue: string; | ||
parameterName: string; | ||
} | ||
/** | ||
@@ -80,0 +92,0 @@ * Supported serialization strategies for arrays in query parameters |
@@ -28,3 +28,4 @@ "use strict"; | ||
} | ||
] | ||
], | ||
servers: contract.oa3servers && contractToOa3ServerObject(contract) | ||
}; | ||
@@ -215,1 +216,38 @@ return openapi; | ||
} | ||
function contractToOa3ServerObject(contract) { | ||
var _a; | ||
if (((_a = contract.oa3servers) === null || _a === void 0 ? void 0 : _a.length) === 0) { | ||
return undefined; | ||
} | ||
const servers = contract.oa3servers; | ||
const serversObject = []; | ||
servers === null || servers === void 0 ? void 0 : servers.map(server => { | ||
const serverVariables = server.oa3ServerVariables.length > 0 | ||
? server.oa3ServerVariables.reduce((acc, serverVariable) => { | ||
acc[serverVariable.parameterName] = oa3ServerVariableToServerVariableObject(serverVariable); | ||
return acc; | ||
}, {}) | ||
: undefined; | ||
serversObject.push({ | ||
url: server.url, | ||
description: server.description, | ||
variables: serverVariables | ||
}); | ||
}); | ||
return serversObject; | ||
} | ||
function oa3ServerVariableToServerVariableObject(oa3ServerVariable) { | ||
if (types_1.isUnionType(oa3ServerVariable.type)) { | ||
const nonNullTypes = oa3ServerVariable.type.types.filter(types_1.isNotNullType); | ||
if (types_1.areStringLiteralTypes(nonNullTypes)) { | ||
const enums = nonNullTypes.map(t => t.value); | ||
return { | ||
default: oa3ServerVariable.defaultValue, | ||
enum: enums | ||
}; | ||
} | ||
} | ||
return { | ||
default: oa3ServerVariable.defaultValue | ||
}; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
const security_header_parser_1 = require("./security-header-parser"); | ||
const oa3server_parser_1 = require("./oa3server-parser"); | ||
/** | ||
@@ -77,2 +78,7 @@ * Parse a root source file to return a contract. | ||
const types = typeTable.toArray(); | ||
// Handle Servers | ||
const serversResult = oa3server_parser_1.parseOa3Servers(klass, typeTable, lociTable); | ||
if (serversResult.isErr()) | ||
return serversResult; | ||
const oa3servers = serversResult.unwrap(); | ||
const contract = { | ||
@@ -85,3 +91,4 @@ name, | ||
endpoints, | ||
version | ||
version, | ||
oa3servers | ||
}; | ||
@@ -88,0 +95,0 @@ return util_1.ok({ contract, lociTable }); |
@@ -1,1 +0,1 @@ | ||
{"version":"1.4.0","commands":{"checksum":{"id":"checksum","description":"Generate a checksum for a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot checksum api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"docs":{"id":"docs","description":"Preview Spot contract as OpenAPI3 documentation. The documentation server will start on http://localhost:8080.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot docs api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"Documentation server port","default":8080}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"generate":{"id":"generate","description":"Runs a generator on an API. Used to produce client libraries, server boilerplates and well-known API contract formats such as OpenAPI.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot generate --contract api.ts --language yaml --generator openapi3 --out output/"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"contract":{"name":"contract","type":"option","char":"c","description":"Path to a TypeScript Contract definition","required":true},"language":{"name":"language","type":"option","char":"l","description":"Language to generate"},"generator":{"name":"generator","type":"option","char":"g","description":"Generator to run"},"out":{"name":"out","type":"option","char":"o","description":"Directory in which to output generated files"}},"args":[]},"init":{"id":"init","description":"Generates the boilerplate for an API.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot init\nGenerated the following files:\n- api.ts\n- tsconfig.json\n- package.json\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"lint":{"id":"lint","description":"Lint a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot lint api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"mock":{"id":"mock","description":"Run a mock server based on a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot mock api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"proxyBaseUrl":{"name":"proxyBaseUrl","type":"option","description":"If set, the server will act as a proxy and fetch data from the given remote server instead of mocking it"},"port":{"name":"port","type":"option","char":"p","description":"Port on which to run the mock server","required":true,"default":3010},"pathPrefix":{"name":"pathPrefix","type":"option","description":"Prefix to prepend to each endpoint path"}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"validate":{"id":"validate","description":"Validate a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot validate api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"validation-server":{"id":"validation-server","description":"Start the spot contract validation server","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot validation-server api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"The port where application will be available","default":5907}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]}}} | ||
{"version":"1.5.0","commands":{"checksum":{"id":"checksum","description":"Generate a checksum for a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot checksum api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"docs":{"id":"docs","description":"Preview Spot contract as OpenAPI3 documentation. The documentation server will start on http://localhost:8080.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot docs api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"Documentation server port","default":8080}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"generate":{"id":"generate","description":"Runs a generator on an API. Used to produce client libraries, server boilerplates and well-known API contract formats such as OpenAPI.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot generate --contract api.ts --language yaml --generator openapi3 --out output/"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"contract":{"name":"contract","type":"option","char":"c","description":"Path to a TypeScript Contract definition","required":true},"language":{"name":"language","type":"option","char":"l","description":"Language to generate"},"generator":{"name":"generator","type":"option","char":"g","description":"Generator to run"},"out":{"name":"out","type":"option","char":"o","description":"Directory in which to output generated files"}},"args":[]},"init":{"id":"init","description":"Generates the boilerplate for an API.","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot init\nGenerated the following files:\n- api.ts\n- tsconfig.json\n- package.json\n"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"lint":{"id":"lint","description":"Lint a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot lint api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"mock":{"id":"mock","description":"Run a mock server based on a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot mock api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"proxyBaseUrl":{"name":"proxyBaseUrl","type":"option","description":"If set, the server will act as a proxy and fetch data from the given remote server instead of mocking it"},"port":{"name":"port","type":"option","char":"p","description":"Port on which to run the mock server","required":true,"default":3010},"pathPrefix":{"name":"pathPrefix","type":"option","description":"Prefix to prepend to each endpoint path"}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"validate":{"id":"validate","description":"Validate a Spot contract","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot validate api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]},"validation-server":{"id":"validation-server","description":"Start the spot contract validation server","pluginName":"@airtasker/spot","pluginType":"core","aliases":[],"examples":["$ spot validation-server api.ts"],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"The port where application will be available","default":5907}},"args":[{"name":"spot_contract","description":"path to Spot contract","required":true,"hidden":false}]}}} |
{ | ||
"name": "@airtasker/spot", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Francois Wouts, Leslie Fung", | ||
@@ -12,3 +12,3 @@ "bin": { | ||
"@oclif/config": "^1.17.0", | ||
"@oclif/plugin-help": "^3.2.1", | ||
"@oclif/plugin-help": "^3.2.2", | ||
"ajv": "^6.12.6", | ||
@@ -18,9 +18,9 @@ "assert-never": "^1.2.1", | ||
"express": "^4.17.1", | ||
"fs-extra": "^9.0.1", | ||
"fs-extra": "^9.1.0", | ||
"inquirer": "^7.3.3", | ||
"js-yaml": "^3.14.1", | ||
"qs": "^6.9.4", | ||
"js-yaml": "^4.0.0", | ||
"qs": "^6.9.6", | ||
"randomstring": "^1.1.5", | ||
"ts-morph": "^8.2.0", | ||
"typescript": "^4.1.3", | ||
"typescript": "^4.1.5", | ||
"validator": "^13.5.2" | ||
@@ -30,38 +30,38 @@ }, | ||
"@oclif/dev-cli": "^1.26.0", | ||
"@stoplight/spectral": "^5.7.2", | ||
"@types/cors": "^2.8.9", | ||
"@types/express": "^4.17.8", | ||
"@types/fs-extra": "^9.0.6", | ||
"@stoplight/spectral": "^5.8.1", | ||
"@types/cors": "^2.8.10", | ||
"@types/express": "^4.17.11", | ||
"@types/fs-extra": "^9.0.7", | ||
"@types/inquirer": "^7.3.1", | ||
"@types/jest": "^26.0.19", | ||
"@types/js-yaml": "^3.12.5", | ||
"@types/moxios": "^0.4.8", | ||
"@types/jest": "^26.0.20", | ||
"@types/js-yaml": "^4.0.0", | ||
"@types/moxios": "^0.4.10", | ||
"@types/qs": "^6.9.5", | ||
"@types/randomstring": "^1.1.6", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/react": "^17.0.2", | ||
"@types/react-dom": "^17.0.1", | ||
"@types/supertest": "^2.0.10", | ||
"@types/validator": "^13.1.2", | ||
"@typescript-eslint/eslint-plugin": "^4.11.1", | ||
"@typescript-eslint/parser": "^4.11.0", | ||
"core-js": "^3.8.1", | ||
"@types/validator": "^13.1.3", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"core-js": "^3.9.0", | ||
"css-loader": "^4.3.0", | ||
"eslint": "^7.16.0", | ||
"eslint-plugin-jest": "^24.1.0", | ||
"html-webpack-plugin": "^4.5.0", | ||
"eslint": "^7.20.0", | ||
"eslint-plugin-jest": "^24.1.5", | ||
"html-webpack-plugin": "^4.5.2", | ||
"jest": "^26.6.3", | ||
"jest-junit": "^12.0.0", | ||
"mini-css-extract-plugin": "^1.3.3", | ||
"mini-css-extract-plugin": "^1.3.8", | ||
"mobx": "^6.0.4", | ||
"nock": "^13.0.4", | ||
"nock": "^13.0.7", | ||
"prettier": "^2.2.1", | ||
"react": "^16.14.0", | ||
"react-dom": "^16.14.0", | ||
"redoc": "^2.0.0-rc.41", | ||
"redoc": "^2.0.0-rc.48", | ||
"styled-components": "^4.4.1", | ||
"supertest": "^6.0.1", | ||
"ts-jest": "^26.4.4", | ||
"ts-loader": "^8.0.12", | ||
"supertest": "^6.1.3", | ||
"ts-jest": "^26.5.1", | ||
"ts-loader": "^8.0.17", | ||
"webpack": "^4.44.2", | ||
"webpack-cli": "^4.3.0" | ||
"webpack-cli": "^4.5.0" | ||
}, | ||
@@ -68,0 +68,0 @@ "engines": { |
@@ -172,3 +172,3 @@ # Spot | ||
_See code: [build/cli/src/commands/checksum.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/checksum.js)_ | ||
_See code: [build/cli/src/commands/checksum.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/checksum.js)_ | ||
@@ -194,3 +194,3 @@ ## `spot docs SPOT_CONTRACT` | ||
_See code: [build/cli/src/commands/docs.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/docs.js)_ | ||
_See code: [build/cli/src/commands/docs.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/docs.js)_ | ||
@@ -216,3 +216,3 @@ ## `spot generate` | ||
_See code: [build/cli/src/commands/generate.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/generate.js)_ | ||
_See code: [build/cli/src/commands/generate.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/generate.js)_ | ||
@@ -234,3 +234,3 @@ ## `spot help [COMMAND]` | ||
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.1/src/commands/help.ts)_ | ||
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_ | ||
@@ -256,3 +256,3 @@ ## `spot init` | ||
_See code: [build/cli/src/commands/init.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/init.js)_ | ||
_See code: [build/cli/src/commands/init.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/init.js)_ | ||
@@ -277,3 +277,3 @@ ## `spot lint SPOT_CONTRACT` | ||
_See code: [build/cli/src/commands/lint.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/lint.js)_ | ||
_See code: [build/cli/src/commands/lint.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/lint.js)_ | ||
@@ -303,3 +303,3 @@ ## `spot mock SPOT_CONTRACT` | ||
_See code: [build/cli/src/commands/mock.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/mock.js)_ | ||
_See code: [build/cli/src/commands/mock.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/mock.js)_ | ||
@@ -324,3 +324,3 @@ ## `spot validate SPOT_CONTRACT` | ||
_See code: [build/cli/src/commands/validate.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/validate.js)_ | ||
_See code: [build/cli/src/commands/validate.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/validate.js)_ | ||
@@ -346,3 +346,3 @@ ## `spot validation-server SPOT_CONTRACT` | ||
_See code: [build/cli/src/commands/validation-server.js](https://github.com/airtasker/spot/blob/v1.4.0/build/cli/src/commands/validation-server.js)_ | ||
_See code: [build/cli/src/commands/validation-server.js](https://github.com/airtasker/spot/blob/v1.5.0/build/cli/src/commands/validation-server.js)_ | ||
<!-- commandsstop --> |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1709453
203
14082
+ Addedargparse@2.0.1(transitive)
+ Addedjs-yaml@4.1.0(transitive)
- Removedargparse@1.0.10(transitive)
- Removedesprima@4.0.1(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
Updated@oclif/plugin-help@^3.2.2
Updatedfs-extra@^9.1.0
Updatedjs-yaml@^4.0.0
Updatedqs@^6.9.6
Updatedtypescript@^4.1.5