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

typera-openapi

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typera-openapi - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

dist/prettify.d.ts

48

dist/cli.js
#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,30 +16,41 @@ const fs = require("fs");

const _1 = require(".");
const prettify_1 = require("./prettify");
const yargs = require("yargs");
const log = (location, level, ...args) => console.log(`${location}: ${level}:`, ...args);
const parseArgs = () => yargs.usage('Usage: $0 [options] FILE...').option('format', {
const parseArgs = () => yargs
.usage('Usage: $0 [options] FILE...')
.option('format', {
description: 'Output file format',
choices: ['ts', 'json'],
default: 'ts',
})
.option('prettify', {
alias: 'p',
description: 'Apply prettier to output TypeScript files',
type: 'boolean',
default: false,
}).argv;
const outputFileName = (sourceFileName, ext) => sourceFileName.slice(0, -path.extname(sourceFileName).length) + ext;
const main = () => {
const main = () => __awaiter(void 0, void 0, void 0, function* () {
const args = parseArgs();
const sourceFiles = args._.map((x) => x.toString());
const ext = args.format === 'ts' ? '.openapi.ts' : '.json';
const ext = `.openapi.${args.format}`;
const results = _1.generate(sourceFiles, { strict: true }, { log }).map((result) => (Object.assign(Object.assign({}, result), { outputFileName: outputFileName(result.fileName, ext) })));
results.forEach(({ outputFileName, paths }) => {
const resultObject = JSON.stringify({ paths });
const content = args.format === 'ts'
? `\
for (const { outputFileName, paths } of results) {
let content = args.format === 'ts' ? tsString(paths) : jsonString(paths);
if (args.prettify) {
content = yield prettify_1.runPrettier(outputFileName, content);
}
console.log('Writing', outputFileName);
fs.writeFileSync(outputFileName, content);
}
});
const tsString = (paths) => `\
import { OpenAPIV3 } from 'openapi-types'
const spec: { paths: OpenAPIV3.PathsObject } = ${resultObject};
const spec: { paths: OpenAPIV3.PathsObject } = ${JSON.stringify({ paths })};
export default spec;
`
: resultObject;
console.log('Writing', outputFileName);
fs.writeFileSync(outputFileName, content);
});
};
`;
const jsonString = (paths) => JSON.stringify({ paths });
main();

@@ -334,2 +334,13 @@ "use strict";

}
if (utils_1.isArrayType(type)) {
const elemType = type.getNumberIndexType();
if (!elemType) {
ctx.log('warn', 'Could not get array element type');
return;
}
const elemSchema = typeToSchema(ctx, elemType);
if (!elemSchema)
return;
return Object.assign({ type: 'array', items: elemSchema }, nullable);
}
if (utils_1.isObjectType(type) ||

@@ -336,0 +347,0 @@ (type.isIntersection() && type.types.every((part) => utils_1.isObjectType(part)))) {

import * as ts from 'typescript';
export declare const isDefined: <T>(value: T | undefined) => value is T;
export declare const isOptional: (symbol: ts.Symbol) => boolean;
export declare const isArrayType: (type: ts.Type) => boolean;
export declare const isObjectType: (type: ts.Type) => boolean;

@@ -5,0 +6,0 @@ export declare const isStringType: (type: ts.Type) => boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPackageSymbol = exports.getPropertyType = exports.isNullType = exports.isUndefinedType = exports.isStringLiteralType = exports.isNumberLiteralType = exports.isBooleanLiteralType = exports.isBooleanType = exports.isNumberType = exports.isStringType = exports.isObjectType = exports.isOptional = exports.isDefined = void 0;
exports.isPackageSymbol = exports.getPropertyType = exports.isNullType = exports.isUndefinedType = exports.isStringLiteralType = exports.isNumberLiteralType = exports.isBooleanLiteralType = exports.isBooleanType = exports.isNumberType = exports.isStringType = exports.isObjectType = exports.isArrayType = exports.isOptional = exports.isDefined = void 0;
const ts = require("typescript");

@@ -9,2 +9,4 @@ const isDefined = (value) => value !== undefined;

exports.isOptional = isOptional;
const isArrayType = (type) => { var _a; return ((_a = type.symbol) === null || _a === void 0 ? void 0 : _a.escapedName) === 'Array'; };
exports.isArrayType = isArrayType;
const isObjectType = (type) => !!(type.flags & ts.TypeFlags.Object);

@@ -11,0 +13,0 @@ exports.isObjectType = isObjectType;

{
"name": "typera-openapi",
"version": "0.3.0",
"version": "0.4.0",
"description": "Generate OpenAPI spec from typera routes",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -49,3 +49,3 @@ # typera-openapi - typera to OpenAPI generator

This cerates `src/routes/foo.openapi.ts` and `src/routes/bar.openapi.ts` which
This creates `src/routes/foo.openapi.ts` and `src/routes/bar.openapi.ts` which
contain the OpenAPI definitions.

@@ -52,0 +52,0 @@

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