New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.11.1 to 0.11.2

51

dist/generate.js

@@ -179,19 +179,42 @@ "use strict";

else if (fnName === 'handler') {
const handlerFn = expr.arguments[0];
if (!handlerFn ||
(!ts.isArrowFunction(handlerFn) &&
!ts.isFunctionExpression(handlerFn))) {
ctx.log('warn', 'Handler is not a function');
// routeConstructor: {
// handler: (routeHandler: (req) => ...)
// }
//
// We want to dig out the type of `req`.
//
const routeConstructor = lhs.expression;
const routeConstructorType = ctx.checker.getTypeAtLocation(routeConstructor);
const handlerSymbol = routeConstructorType.getProperty('handler');
if (!handlerSymbol) {
ctx.log('warn', 'Could not get the type of handler()');
return;
}
const req = handlerFn.parameters[0];
if (req) {
const type = ctx.checker.getTypeAtLocation(req);
body = utils_1.getPropertyType(ctx.checker, req, type, 'body');
query = utils_1.getPropertyType(ctx.checker, req, type, 'query');
headers = utils_1.getPropertyType(ctx.checker, req, type, 'headers');
routeParams = utils_1.getPropertyType(ctx.checker, req, type, 'routeParams');
cookies = utils_1.getPropertyType(ctx.checker, req, type, 'cookies');
requestNode = req;
const handlerType = ctx.checker.getTypeOfSymbolAtLocation(handlerSymbol, routeConstructor);
const handlerParamTypes = handlerType
.getCallSignatures()
.flatMap((sig) => sig.getParameters())
.flatMap((param) => ctx.checker.getTypeOfSymbolAtLocation(param, routeConstructor));
if (handlerParamTypes.length !== 1) {
ctx.log('warn', 'handler() should have one parameter');
return;
}
const routeHandler = handlerParamTypes[0];
const routeHandlerParamTypes = routeHandler
.getCallSignatures()
.flatMap((c) => c.getParameters())
.flatMap((param) => ctx.checker.getTypeOfSymbolAtLocation(param, routeConstructor));
if (routeHandlerParamTypes.length !== 1) {
ctx.log('warn', 'Route handler should have one parameter');
return;
}
const reqType = routeHandlerParamTypes[0];
[body, query, headers, routeParams, cookies] = [
'body',
'query',
'headers',
'routeParams',
'cookies',
].map((property) => utils_1.getPropertyType(ctx.checker, routeConstructor, reqType, property));
requestNode = routeConstructor;
}

@@ -198,0 +221,0 @@ expr = lhs.expression;

{
"name": "typera-openapi",
"version": "0.11.1",
"version": "0.11.2",
"description": "Generate OpenAPI spec from typera routes",

@@ -28,3 +28,3 @@ "repository": "https://github.com/akheron/typera-openapi",

"typescript": "^4.1.3",
"yargs": "^16.2.0"
"yargs": "^17.0.0"
},

@@ -31,0 +31,0 @@ "devDependencies": {

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