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

typescript-rest-swagger-plural

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-rest-swagger-plural - npm Package Compare versions

Comparing version 0.0.33 to 0.0.34

5

dist/decorators.d.ts

@@ -71,2 +71,7 @@ /**

/**
* Builds path name from template string using the first generic argument of the decorated type.
* e.x. '/{type}'
*/
export declare function PathFromGenericArg(path: string): any;
/**
* Documentation-only: Allow specifying path-parameter without 'typescript-rest' library

@@ -73,0 +78,0 @@ */

@@ -95,2 +95,10 @@ 'use strict';

/**
* Builds path name from template string using the first generic argument of the decorated type.
* e.x. '/{type}'
*/
function PathFromGenericArg(path) {
return function () { return; };
}
exports.PathFromGenericArg = PathFromGenericArg;
/**
* Documentation-only: Allow specifying path-parameter without 'typescript-rest' library

@@ -97,0 +105,0 @@ */

2

dist/metadata/controllerGenerator.d.ts

@@ -15,3 +15,5 @@ import * as ts from 'typescript';

private getDecoratorValues;
private getPathForClass;
private getInheritedDecoratorTextValue;
private getMethodSecurity;
}

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

this.genMethods = new Set();
this.pathValue = pathUtils_1.normalizePath(decoratorUtils_1.getDecoratorTextValue(node, function (decorator) { return decorator.text === 'Path'; }));
this.pathValue = pathUtils_1.normalizePath(this.getPathForClass(node));
}

@@ -82,2 +82,39 @@ ControllerGenerator.prototype.isValid = function () {

};
ControllerGenerator.prototype.getPathForClass = function (node) {
var path = decoratorUtils_1.getDecoratorTextValue(node, function (decorator) { return decorator.text === 'Path'; });
if (path)
return path;
this.getInheritedDecoratorTextValue(node, function (decorator) { return decorator.text == 'PathFromGenericArg'; }, function (pFoundText, typeArguments) {
//path is a template string that uses the Classes first generic arg type as 'type' parameter
if (typeArguments.length > 0) {
pFoundText = pFoundText.replace('{type}', typeArguments[0].getText());
//we only care about this tag IF there is a generic arg on a superclass
path = pFoundText;
}
return pFoundText;
});
return path;
};
//look at this node and all parent nodes for matching decorator, then extract its text value
ControllerGenerator.prototype.getInheritedDecoratorTextValue = function (node, isMatching, optionalNodeOperation) {
if (!node || !node.name)
return undefined;
var textValue = decoratorUtils_1.getDecoratorTextValue(node, isMatching);
if (!textValue) {
var parentType = resolveType_1.getSuperClass(node);
if (parentType) {
textValue = this.getInheritedDecoratorTextValue(parentType.type, isMatching);
if (textValue && optionalNodeOperation) {
var typeArgs_1 = [];
if (parentType.typeArguments) {
parentType.typeArguments.forEach(function (k) {
typeArgs_1.push(k);
});
}
textValue = optionalNodeOperation(textValue, typeArgs_1);
}
}
}
return textValue;
};
ControllerGenerator.prototype.getMethodSecurity = function () {

@@ -84,0 +121,0 @@ if (!this.node.parent) {

10

dist/metadata/resolveType.js

@@ -569,6 +569,8 @@ "use strict";

var type = metadataGenerator_1.MetadataGenerator.current.getClassDeclaration(clause.types[0].expression.getText());
return {
type: type,
typeArguments: resolveTypeArguments(type, clause.types[0].typeArguments, typeArguments)
};
if (type) {
return {
type: type,
typeArguments: resolveTypeArguments(type, clause.types[0].typeArguments, typeArguments)
};
}
}

@@ -575,0 +577,0 @@ }

{
"name": "typescript-rest-swagger-plural",
"version": "0.0.33",
"version": "0.0.34",
"description": "Generate Swagger files from a typescript-rest project",

@@ -27,3 +27,3 @@ "keywords": [

"swagger-gen": "node ./dist/cli.js -c ./test/data/swagger.json",
"pretest": "cross-env NODE_ENV=test npm build && npm run lint",
"pretest": "cross-env NODE_ENV=test npm build",
"test": "cross-env NODE_ENV=test mocha",

@@ -30,0 +30,0 @@ "test:coverage": "nyc npm test",

@@ -91,2 +91,10 @@ 'use strict';

/**
* Builds path name from template string using the first generic argument of the decorated type.
* e.x. '/{type}'
*/
export function PathFromGenericArg(path: string): any {
return () => { return; };
}
/**
* Documentation-only: Allow specifying path-parameter without 'typescript-rest' library

@@ -93,0 +101,0 @@ */

@@ -6,3 +6,3 @@ import * as ts from 'typescript';

import { MethodGenerator } from './methodGenerator';
import { getDecorators, getDecoratorTextValue } from '../utils/decoratorUtils';
import { getDecorators, getDecoratorTextValue, DecoratorData } from '../utils/decoratorUtils';
import {normalizePath} from '../utils/pathUtils';

@@ -16,3 +16,3 @@ import * as _ from 'lodash';

constructor(private readonly config: SwaggerConfig, private readonly node: ts.ClassDeclaration) {
this.pathValue = normalizePath(getDecoratorTextValue(node, decorator => decorator.text === 'Path'));
this.pathValue = normalizePath(this.getPathForClass(node));
}

@@ -84,2 +84,52 @@

private getPathForClass(node: ts.ClassDeclaration): string | undefined
{
let path = getDecoratorTextValue(node, decorator => decorator.text === 'Path');
if (path)
return path;
this.getInheritedDecoratorTextValue(node, decorator => decorator.text == 'PathFromGenericArg', (pFoundText, typeArguments)=>
{
//path is a template string that uses the Classes first generic arg type as 'type' parameter
if (typeArguments.length>0)
{
pFoundText = pFoundText.replace('{type}', typeArguments[0].getText());
//we only care about this tag IF there is a generic arg on a superclass
path = pFoundText;
}
return pFoundText;
});
return path;
}
//look at this node and all parent nodes for matching decorator, then extract its text value
private getInheritedDecoratorTextValue(node: ts.ClassDeclaration, isMatching: (identifier: DecoratorData) => boolean, optionalNodeOperation?: (foundText: string, typeArguments: ts.TypeNode[]) => string): string | undefined {
if (!node || !node.name) return undefined;
let textValue = getDecoratorTextValue(node, isMatching);
if (!textValue) {
var parentType = getSuperClass(node);
if (parentType)
{
textValue = this.getInheritedDecoratorTextValue(parentType.type, isMatching);
if (textValue && optionalNodeOperation)
{
let typeArgs: ts.TypeNode[] = [];
if (parentType.typeArguments)
{
parentType.typeArguments.forEach(k=>
{
typeArgs.push(k);
});
}
textValue = optionalNodeOperation(textValue, typeArgs);
}
}
}
return textValue;
}
private getMethodSecurity() {

@@ -86,0 +136,0 @@ if (!this.node.parent) { throw new Error('Controller node doesn\'t have a valid parent source file.'); }

@@ -625,6 +625,9 @@ import * as ts from 'typescript';

const type: any = MetadataGenerator.current.getClassDeclaration(clause.types[0].expression.getText());
return {
type: type,
typeArguments: resolveTypeArguments(type, clause.types[0].typeArguments, typeArguments)
};
if (type)
{
return {
type: type,
typeArguments: resolveTypeArguments(type, clause.types[0].typeArguments, typeArguments)
};
}
}

@@ -631,0 +634,0 @@ }

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