Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apidoc2ts

Package Overview
Dependencies
Maintainers
10
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apidoc2ts - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

dist/core/endpoint-converter/ApiDocToInterfaceConverter.js

32

dist/cli/index.js

@@ -14,3 +14,3 @@ "use strict";

const ApiDoc2InterfaceBuilder_1 = require("../core/ApiDoc2InterfaceBuilder");
const ApiDocToInterfaceConverter_1 = require("../core/converter/ApiDocToInterfaceConverter");
const ApiDocToInterfaceConverter_1 = require("../core/endpoint-converter/ApiDocToInterfaceConverter");
const InputParser_1 = require("./InputParser");

@@ -20,3 +20,3 @@ class Convert extends command_1.Command {

return __awaiter(this, void 0, void 0, function* () {
const { args, flags: passedFlags } = this.parse(Convert);
const { flags: passedFlags } = this.parse(Convert);
return this.parseInput(passedFlags)

@@ -43,3 +43,3 @@ .then(({ builderOptions, runParameters }) => __awaiter(this, void 0, void 0, function* () {

parseInput(passedFlags) {
const configParser = new InputParser_1.InputParser();
const configParser = new InputParser_1.default();
return configParser.parse(passedFlags);

@@ -59,3 +59,3 @@ }

getApiDoc2Interface(builderOptions) {
const apiDoc2InterfaceBuilder = new ApiDoc2InterfaceBuilder_1.ApiDoc2InterfaceBuilder();
const apiDoc2InterfaceBuilder = new ApiDoc2InterfaceBuilder_1.default();
return apiDoc2InterfaceBuilder.build(builderOptions);

@@ -73,3 +73,3 @@ }

char: "s",
description: "Path to the api_data.json",
description: "Path to the apidoc folder",
exclusive: ["config"],

@@ -107,3 +107,3 @@ }),

}),
["parse-examples"]: command_1.flags.boolean({
"parse-examples": command_1.flags.boolean({
char: "e",

@@ -114,3 +114,3 @@ default: false,

}),
["custom-types"]: command_1.flags.string({
"custom-types": command_1.flags.string({
char: "t",

@@ -122,3 +122,3 @@ multiple: true,

}),
["static-prefix"]: command_1.flags.string({
"static-prefix": command_1.flags.string({
required: false,

@@ -128,3 +128,3 @@ description: "Prefix for all interfaces names",

}),
["static-postfix"]: command_1.flags.string({
"static-postfix": command_1.flags.string({
required: false,

@@ -134,23 +134,23 @@ description: "Postfix for all interfaces names",

}),
["request-prefix"]: command_1.flags.string({
"request-prefix": command_1.flags.string({
description: "Prefix for a request interface name",
exclusive: ["config"],
}),
["request-postfix"]: command_1.flags.string({
"request-postfix": command_1.flags.string({
description: "Postfix for a request interface name",
exclusive: ["config"],
}),
["response-prefix"]: command_1.flags.string({
"response-prefix": command_1.flags.string({
description: "Prefix for a response interface name",
exclusive: ["config"],
}),
["response-postfix"]: command_1.flags.string({
"response-postfix": command_1.flags.string({
description: "Postfix for a response interface name",
exclusive: ["config"],
}),
["error-prefix"]: command_1.flags.string({
"error-prefix": command_1.flags.string({
description: "Prefix for a error interface name",
exclusive: ["config"],
}),
["error-postfix"]: command_1.flags.string({
"error-postfix": command_1.flags.string({
description: "Postfix for a error interface name",

@@ -161,2 +161,2 @@ exclusive: ["config"],

module.exports = Convert;
//# sourceMappingURL=index.js.map
//# sourceMappingURL=Index.js.map

@@ -12,3 +12,3 @@ "use strict";

const fs = require("fs");
const _ = require("lodash");
const lodash_1 = require("lodash");
const path = require("path");

@@ -22,7 +22,17 @@ const ApiDoc2Interface_1 = require("../core/ApiDoc2Interface");

: yield this.combineDefaultConfigAndCliFlags(cliFlags);
flags.output = flags.output || "./";
this.validateInput(flags);
if (!flags.source) {
throw new Error("Missing required flag 'source'");
}
if (!flags.name && flags.grouping === ApiDoc2Interface_1.ApiDoc2InterfaceGroupingMode.SINGLE) {
throw new Error("Missing required flag 'name'");
}
const runParameters = {
source: flags.source,
output: flags.output || "./",
name: flags.name || "",
grouping: flags.grouping || ApiDoc2Interface_1.ApiDoc2InterfaceGroupingMode.URL,
};
return {
runParameters,
builderOptions: flags,
runParameters: flags,
};

@@ -35,8 +45,4 @@ });

return this.readConfigFlags(InputParser.defaultConfigFileName)
.then(defaultConfigFlags => {
return _.defaults(mappedCliFlags, defaultConfigFlags);
})
.catch(err => {
return mappedCliFlags;
});
.then(defaultConfigFlags => lodash_1.defaults(mappedCliFlags, defaultConfigFlags))
.catch(() => mappedCliFlags);
});

@@ -49,15 +55,5 @@ }

}
// eslint-disable-next-line global-require, import/no-dynamic-require
return Promise.resolve(require(configPath));
}
validateInput(flags) {
InputParser.requiredFlagsKeys.forEach(key => {
if (flags[key]) {
return;
}
if (key === "name" && flags.grouping === ApiDoc2Interface_1.ApiDoc2InterfaceGroupingMode.URL) {
return;
}
throw new Error(`Missing required flag '${key}'`);
});
}
mapInputFlags(flags) {

@@ -84,5 +80,4 @@ return {

}
InputParser.requiredFlagsKeys = ["source", "output", "name"];
InputParser.defaultConfigFileName = "apidoc2ts.config.js";
exports.InputParser = InputParser;
exports.default = InputParser;
//# sourceMappingURL=InputParser.js.map

@@ -41,3 +41,3 @@ "use strict";

describe("CLI InputParser", () => {
const inputParser = new InputParser_1.InputParser();
const inputParser = new InputParser_1.default();
const existsSpy = jest.spyOn(fs, "existsSync");

@@ -70,10 +70,17 @@ beforeEach(() => {

source: "source",
name: "name",
});
expect(result.runParameters.output).toBe("./");
}));
it("should replace missing 'grouping' flag with default value 'url'", () => __awaiter(this, void 0, void 0, function* () {
existsSpy.mockReturnValue(false);
const result = yield inputParser.parse({
source: "source",
});
expect(result.runParameters.grouping).toBe("url");
}));
it("should not throw an error if 'name' is not specified and grouping is set to 'url'", () => __awaiter(this, void 0, void 0, function* () {
existsSpy.mockReturnValue(false);
yield expect(inputParser.parse({
source: "source", output: "output", grouping: "url",
source: "source",
grouping: "url",
})).resolves.not.toThrow();

@@ -80,0 +87,0 @@ }));

@@ -12,7 +12,8 @@ "use strict";

const fs = require("fs");
const path = require("path");
const util_1 = require("util");
const ApiDocToInterfaceConverter_1 = require("./converter/ApiDocToInterfaceConverter");
const InterfaceGenerator_1 = require("./generator/InterfaceGenerator");
const ApiDocEndpointParser_1 = require("./parser/ApiDocEndpointParser");
const InterfacesWriter_1 = require("./writer/InterfacesWriter");
const ApiDocToInterfaceConverter_1 = require("./endpoint-converter/ApiDocToInterfaceConverter");
const ApiDocFieldsParser_1 = require("./endpoint-parser/ApiDocFieldsParser");
const InterfaceGenerator_1 = require("./interface-generator/InterfaceGenerator");
const InterfacesWriter_1 = require("./interfaces-writer/InterfacesWriter");
const readFile = util_1.promisify(fs.readFile);

@@ -30,3 +31,3 @@ var ApiDoc2InterfaceExitCode;

class ApiDoc2Interface {
constructor(converter, writerFactory = InterfacesWriter_1.getInterfaceWriter) {
constructor(converter, writerFactory = InterfacesWriter_1.default) {
this.converter = converter;

@@ -36,4 +37,4 @@ this.writerFactory = writerFactory;

static simple() {
const generator = new InterfaceGenerator_1.InterfaceGenerator();
const parser = new ApiDocEndpointParser_1.ApiDocEndpointParser();
const generator = new InterfaceGenerator_1.default();
const parser = new ApiDocFieldsParser_1.default();
const converter = new ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter(generator, parser);

@@ -45,3 +46,3 @@ return new ApiDoc2Interface(converter);

const warnings = [];
return readFile(args.source, "utf-8")
return readFile(path.join(args.source, "api_data.json"), "utf-8")
.then((fileData) => {

@@ -56,16 +57,12 @@ const apiDocEndpoints = JSON.parse(fileData);

})
.then(() => {
return {
warnings,
message: "Successfully generated interfaces",
code: ApiDoc2InterfaceExitCode.SUCCESS,
};
})
.catch((err) => {
return {
message: `${err}`,
code: ApiDoc2InterfaceExitCode.FAIL,
warnings: [],
};
});
.then(() => ({
warnings,
message: "Successfully generated interfaces",
code: ApiDoc2InterfaceExitCode.SUCCESS,
}))
.catch((err) => ({
message: `${err}`,
code: ApiDoc2InterfaceExitCode.FAIL,
warnings: [],
}));
});

@@ -72,0 +69,0 @@ }

@@ -12,5 +12,6 @@ "use strict";

const fs = require("fs");
const path = require("path");
const ApiDoc2Interface_1 = require("./ApiDoc2Interface");
jest.mock("fs");
jest.mock("./converter/ApiDocToInterfaceConverter");
jest.mock("./endpoint-converter/ApiDocToInterfaceConverter");
describe("ApiDoc2Interface wrapper", () => {

@@ -30,4 +31,4 @@ const requestInterface = "interface Request";

};
const writeInterfacesMock = jest.fn((a, b) => Promise.resolve());
const interfaceWriterFactoryMock = jest.fn((grouping) => ({
const writeInterfacesMock = jest.fn(() => Promise.resolve());
const interfaceWriterFactoryMock = jest.fn(() => ({
writeInterfaces: writeInterfacesMock,

@@ -37,3 +38,3 @@ }));

const args = {
source: "path/to/the/file",
source: "path/to/apidoc",
output: "path/to/the/output",

@@ -51,5 +52,5 @@ name: "interfaces.ts",

});
it("should call readFile with given path", () => __awaiter(this, void 0, void 0, function* () {
it("should call readFile for api_data.json file in provided apidoc source", () => __awaiter(this, void 0, void 0, function* () {
yield apiDoc2Interface.run(args);
expect(readFileSpy).toBeCalledWith(args.source, "utf-8", expect.anything());
expect(readFileSpy).toBeCalledWith(path.join(args.source, "api_data.json"), "utf-8", expect.anything());
}));

@@ -56,0 +57,0 @@ it("should throw an error when readFile failed", () => __awaiter(this, void 0, void 0, function* () {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const lodash_1 = require("lodash");
const ApiDoc2Interface_1 = require("./ApiDoc2Interface");
const ApiDocToInterfaceConverter_1 = require("./converter/ApiDocToInterfaceConverter");
const InterfaceGenerator_1 = require("./generator/InterfaceGenerator");
const ApiDocEndpointParser_1 = require("./parser/ApiDocEndpointParser");
const ApiDocExamplesParser_1 = require("./parser/ApiDocExamplesParser");
const ApiDocToInterfaceConverter_1 = require("./endpoint-converter/ApiDocToInterfaceConverter");
const ApiDocExamplesParser_1 = require("./endpoint-parser/ApiDocExamplesParser");
const ApiDocFieldsParser_1 = require("./endpoint-parser/ApiDocFieldsParser");
const InterfaceGenerator_1 = require("./interface-generator/InterfaceGenerator");
class ApiDoc2InterfaceBuilder {
build(parameters) {
const generatorOptions = parameters.customTypes || [];
const converterOptions = _.defaults(parameters, ApiDocToInterfaceConverter_1.converterDefaultOptions);
const generator = new InterfaceGenerator_1.InterfaceGenerator(generatorOptions);
const parser = new ApiDocEndpointParser_1.ApiDocEndpointParser();
const examplesParser = new ApiDocExamplesParser_1.ApiDocExamplesParser();
const converterOptions = lodash_1.defaults(parameters, ApiDocToInterfaceConverter_1.converterDefaultOptions);
const generator = new InterfaceGenerator_1.default(generatorOptions);
const parser = new ApiDocFieldsParser_1.default();
const examplesParser = new ApiDocExamplesParser_1.default();
const converter = new ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter(generator, parser, converterOptions, examplesParser);

@@ -20,3 +20,3 @@ return new ApiDoc2Interface_1.ApiDoc2Interface(converter);

}
exports.ApiDoc2InterfaceBuilder = ApiDoc2InterfaceBuilder;
exports.default = ApiDoc2InterfaceBuilder;
//# sourceMappingURL=ApiDoc2InterfaceBuilder.js.map

@@ -5,13 +5,13 @@ "use strict";

const ApiDoc2InterfaceBuilder_1 = require("./ApiDoc2InterfaceBuilder");
const ApiDocToInterfaceConverter_1 = require("./converter/ApiDocToInterfaceConverter");
const InterfaceGenerator_1 = require("./generator/InterfaceGenerator");
const ApiDocEndpointParser_1 = require("./parser/ApiDocEndpointParser");
const ApiDocExamplesParser_1 = require("./parser/ApiDocExamplesParser");
jest.mock("./generator/InterfaceGenerator");
jest.mock("./parser/ApiDocEndpointParser");
jest.mock("./parser/ApiDocExamplesParser");
jest.mock("./converter/ApiDocToInterfaceConverter");
const ApiDocToInterfaceConverter_1 = require("./endpoint-converter/ApiDocToInterfaceConverter");
const ApiDocExamplesParser_1 = require("./endpoint-parser/ApiDocExamplesParser");
const ApiDocFieldsParser_1 = require("./endpoint-parser/ApiDocFieldsParser");
const InterfaceGenerator_1 = require("./interface-generator/InterfaceGenerator");
jest.mock("./interface-generator/InterfaceGenerator");
jest.mock("./endpoint-parser/ApiDocFieldsParser");
jest.mock("./endpoint-parser/ApiDocExamplesParser");
jest.mock("./endpoint-converter/ApiDocToInterfaceConverter");
jest.mock("./ApiDoc2Interface");
describe("ApiDoc2InterfaceBuilder", () => {
const builder = new ApiDoc2InterfaceBuilder_1.ApiDoc2InterfaceBuilder();
const builder = new ApiDoc2InterfaceBuilder_1.default();
const parameters = {

@@ -29,15 +29,15 @@ customTypes: ["File", "URL"],

builder.build(parameters);
expect(ApiDocEndpointParser_1.ApiDocEndpointParser).toBeCalled();
expect(ApiDocFieldsParser_1.default).toBeCalled();
});
it("should create generator with passed custom types", () => {
builder.build(parameters);
expect(InterfaceGenerator_1.InterfaceGenerator).toBeCalledWith(parameters.customTypes);
expect(InterfaceGenerator_1.default).toBeCalledWith(parameters.customTypes);
});
it("should create generator with empty array if no custom types specified", () => {
builder.build({});
expect(InterfaceGenerator_1.InterfaceGenerator).toBeCalledWith([]);
expect(InterfaceGenerator_1.default).toBeCalledWith([]);
});
it("should create converter with previously created parser/generator", () => {
builder.build(parameters);
expect(ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter).toBeCalledWith(InterfaceGenerator_1.InterfaceGenerator.mock.instances[0], ApiDocEndpointParser_1.ApiDocEndpointParser.mock.instances[0], expect.anything(), expect.anything());
expect(ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter).toBeCalledWith(InterfaceGenerator_1.default.mock.instances[0], ApiDocFieldsParser_1.default.mock.instances[0], expect.anything(), expect.anything());
});

@@ -54,3 +54,3 @@ it("should create converter with passed in parameters", () => {

builder.build(parameters);
expect(ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter).toBeCalledWith(expect.anything(), expect.anything(), expect.anything(), ApiDocExamplesParser_1.ApiDocExamplesParser.mock.instances[0]);
expect(ApiDocToInterfaceConverter_1.ApiDocToInterfaceConverter).toBeCalledWith(expect.anything(), expect.anything(), expect.anything(), ApiDocExamplesParser_1.default.mock.instances[0]);
});

@@ -57,0 +57,0 @@ it("should create apiDoc2Interface wrapper with created converter", () => {

@@ -140,5 +140,5 @@ "use strict";

};
jest.mock("../parser/ApiDocEndpointParser");
jest.mock("../parser/ApiDocExamplesParser");
jest.mock("../generator/InterfaceGenerator");
jest.mock("../endpoint-parser/ApiDocFieldsParser");
jest.mock("../endpoint-parser/ApiDocExamplesParser");
jest.mock("../interface-generator/InterfaceGenerator");
const threeEndpoints = [requestVersion1, requestVersion2, requestVersion3];

@@ -294,2 +294,2 @@ const parserResultMock = {

});
//# sourceMappingURL=ApiDocToInterfaceConverter.test.js.map
//# sourceMappingURL=ApiDocToInterfaceConverter.test.js.map

@@ -31,3 +31,3 @@ "use strict";

}
if (!this.isMatchingBracket(bracket, char)) {
if (bracket && !this.isMatchingBracket(bracket, char)) {
throw new Error("Close bracket does not match the open bracket");

@@ -52,3 +52,3 @@ }

}
exports.MatchingBracketsStringExtractor = MatchingBracketsStringExtractor;
exports.default = MatchingBracketsStringExtractor;
//# sourceMappingURL=MatchingBracketsStringExtractor.js.map

@@ -11,3 +11,3 @@ "use strict";

describe("Matching brackets parser", () => {
const stringExtractor = new MatchingBracketsStringExtractor_1.MatchingBracketsStringExtractor();
const stringExtractor = new MatchingBracketsStringExtractor_1.default();
it("should return empty string if no brackets are present in input", () => {

@@ -14,0 +14,0 @@ expect(stringExtractor.getString("")).toBe("");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
exports.jsonSchemaDefaultTypes = ["null", "boolean", "object", "array", "number", "string", "integer"];
const lodash_1 = require("lodash");
exports.jsonSchemaDefaultTypes = [
"null",
"boolean",
"object",
"array",
"number",
"string",
"integer",
];
function traverseSchemaRecursively(schema, callback) {
callback(schema);
_.values(schema.properties).forEach((property) => {
lodash_1.values(schema.properties).forEach((property) => {
callback(property);
traverseSchemaRecursively(property, callback);
});
_.values(schema.definitions).forEach((definition) => {
lodash_1.values(schema.definitions).forEach((definition) => {
callback(definition);

@@ -13,0 +21,0 @@ traverseSchemaRecursively(definition, callback);

@@ -98,2 +98,2 @@ "use strict";

exports.ApiDocEndpointParser = ApiDocEndpointParser;
//# sourceMappingURL=ApiDocEndpointParser.js.map
//# sourceMappingURL=ApiDocFieldsParser.js.map

@@ -234,2 +234,2 @@ "use strict";

});
//# sourceMappingURL=ApiDocEndpointParser.test.js.map
//# sourceMappingURL=ApiDocFieldsParser.test.js.map
{
"name": "apidoc2ts",
"version": "0.2.1",
"version": "0.3.0",
"description": "Typescript interface generator based on ApiDoc",

@@ -8,3 +8,3 @@ "bin": {

},
"main": "src/cli/index.ts",
"main": "src/cli/Index.ts",
"scripts": {

@@ -15,4 +15,5 @@ "start": "npm run lint && npm test && npm run build && npm run main",

"test": "jest --verbose --passWithNoTests",
"lint": "tslint --force -t stylish -c tslint.json 'src/**/*.ts'",
"lint-strict": "tslint -t stylish -c tslint.json 'src/**/*.ts'"
"lint": "eslint -c .eslintrc.js --cache 'src/**/*.ts'",
"lint:fix": "eslint -c .eslintrc.js --fix 'src/**/*.ts'",
"lint:strict": "eslint -c .eslintrc.js 'src/**/*.ts'"
},

@@ -25,3 +26,3 @@ "jest": {

"hooks": {
"pre-commit": "node .git-scripts/check-branch-name.js && npm run lint-strict && npm test"
"pre-commit": "node .git-scripts/check-branch-name.js && npm run lint:strict && npm test"
}

@@ -31,10 +32,13 @@ },

"type": "git",
"url": "git+https://github.com/fluix/web-apidoc2ts.git"
"url": "git+https://github.com/fluix/apidoc2ts.git"
},
"author": "Artem Velkov",
"author": {
"name": "Artem Velkov",
"email": "velkov.artem@gmail.com"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/fluix/web-apidoc2ts/issues"
"url": "https://github.com/fluix/apidoc2ts/issues"
},
"homepage": "https://github.com/fluix/web-apidoc2ts#readme",
"homepage": "https://fluix.github.io/apidoc2ts/",
"files": [

@@ -48,2 +52,3 @@ "/bin",

"@oclif/plugin-help": "^2.2.0",
"@types/lodash": "^4.14.138",
"chalk": "^2.4.2",

@@ -57,15 +62,27 @@ "lodash": "^4.17.14",

"@oclif/tslint": "^3.1.1",
"@types/jest": "^24.0.15",
"@types/node": "^10.14.13",
"@types/jest": "^24.0.15",
"ts-node": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^2.3.2",
"@typescript-eslint/eslint-plugin-tslint": "^2.3.2",
"@typescript-eslint/parser": "^2.3.2",
"eslint": "^6.5.1",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.15.1",
"eslint-plugin-react-hooks": "^1.7.0",
"husky": "^3.0.0",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"tslint": "^5.18.0",
"tslint-config-airbnb": "5.11.1",
"ts-node": "^8.3.0",
"tslint": "^5.20.0",
"typescript": "^3.5.3"
},
"keywords": [
"apidoc2ts"
"apidoc2ts",
"apidoc",
"interface",
"interface generator",
"code generator"
]
}

@@ -62,5 +62,3 @@ # apiDoc to Interfaces

The tool will look for a default config file called `apidoc2ts.config.js` in a current folder and combine
flags from the file with a flags specified in command line. Note that command line flags override config
file flags and all flags in config file should be in a camelCase.
The tool will look for a default config file called `apidoc2ts.config.js` in a current folder and combine flags from the file with a flags specified in command line. Note that command line flags override config file flags and all flags in config file should be in a camelCase.

@@ -82,4 +80,8 @@ Also you can specify a path to the config file which **must** contain all required flags:

## Contributing
We appreciate any contribution to this project whether it is a bug report, feature request or some improvement and have a small [guide](CONTRIBUTING.md) for that.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc