Socket
Socket
Sign inDemoInstall

@tsed/swagger

Package Overview
Dependencies
Maintainers
5
Versions
1101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsed/swagger - npm Package Compare versions

Comparing version 4.0.7 to 4.1.0

6

lib/class/OpenApiEndpointBuilder.d.ts

@@ -0,3 +1,4 @@

import { EndpointMetadata } from "@tsed/common";
import { Path } from "swagger-schema-official";
import { EndpointMetadata } from "@tsed/common";
import { ExpressPathMethod } from "../../common/mvc/interfaces/ExpressPathMethod";
import { OpenApiModelSchemaBuilder } from "./OpenApiModelSchemaBuilder";

@@ -7,4 +8,5 @@ export declare class OpenApiEndpointBuilder extends OpenApiModelSchemaBuilder {

private endpointUrl;
private pathMethod;
private _paths;
constructor(endpoint: EndpointMetadata, endpointUrl: string);
constructor(endpoint: EndpointMetadata, endpointUrl: string, pathMethod: ExpressPathMethod);
build(): this;

@@ -11,0 +13,0 @@ /**

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

const utils_1 = require("../utils");
const OpenApiModelSchemaBuilder_1 = require("./OpenApiModelSchemaBuilder");
const OpenApiParamsBuilder_1 = require("./OpenApiParamsBuilder");
const OpenApiModelSchemaBuilder_1 = require("./OpenApiModelSchemaBuilder");
/** */

@@ -21,10 +21,11 @@ const OPERATION_IDS = {};

class OpenApiEndpointBuilder extends OpenApiModelSchemaBuilder_1.OpenApiModelSchemaBuilder {
constructor(endpoint, endpointUrl) {
constructor(endpoint, endpointUrl, pathMethod) {
super(endpoint.target);
this.endpoint = endpoint;
this.endpointUrl = endpointUrl;
this.pathMethod = pathMethod;
this._paths = {};
}
build() {
const openAPIPath = ("" + utils_1.toSwaggerPath(`${this.endpointUrl}${this.endpoint.path || ""}`)).trim();
const openAPIPath = utils_1.toSwaggerPath(this.endpointUrl, this.pathMethod.path);
const produces = this.endpoint.get("produces") || [];

@@ -53,3 +54,3 @@ const consumes = this.endpoint.get("consumes") || [];

core_1.deepExtends(operation, this.endpoint.get("operation") || {});
path[this.endpoint.httpMethod] = operation;
path[this.pathMethod.method] = operation;
responses[this.endpoint.get("statusCode") || "200"] = { description: "Success" };

@@ -56,0 +57,0 @@ Object.keys(responses).forEach(code => {

/// <reference types="express" />
import { ControllerService, ServerSettingsService } from "@tsed/common";
import * as Express from "express";
import { Spec } from "swagger-schema-official";
import { ServerSettingsService, ControllerService } from "@tsed/common";
export declare class SwaggerService {

@@ -6,0 +6,0 @@ private controllerService;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const common_1 = require("@tsed/common");
const core_1 = require("@tsed/core");

@@ -9,3 +10,2 @@ const Express = require("express");

const ts_log_debug_1 = require("ts-log-debug");
const common_1 = require("@tsed/common");
const OpenApiEndpointBuilder_1 = require("../class/OpenApiEndpointBuilder");

@@ -131,8 +131,11 @@ const utils_1 = require("../utils");

ctrl.endpoints.forEach((endpoint) => {
/* istanbul ignore else */
if (endpoint.hasHttpMethod()) {
const builder = new OpenApiEndpointBuilder_1.OpenApiEndpointBuilder(endpoint, endpointUrl).build();
core_1.deepExtends(paths, builder.paths);
core_1.deepExtends(definitions, builder.definitions);
}
endpoint.pathsMethods.forEach((pathMethod) => {
/* istanbul ignore else */
if (!!pathMethod.method) {
const builder = new OpenApiEndpointBuilder_1.OpenApiEndpointBuilder(endpoint, endpointUrl, pathMethod)
.build();
core_1.deepExtends(paths, builder.paths);
core_1.deepExtends(definitions, builder.definitions);
}
});
});

@@ -139,0 +142,0 @@ }

import { PathParamsType } from "@tsed/common";
/** */
export declare function toSwaggerPath(expressPath: PathParamsType): PathParamsType;
export declare function toSwaggerPath(base: string, path?: PathParamsType): string;
export declare function swaggerType(type: any): string;

@@ -5,0 +5,0 @@ export declare function getReducers(): {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@tsed/common");
const core_1 = require("@tsed/core");
const common_1 = require("@tsed/common");
/** */
function toSwaggerPath(expressPath) {
if (typeof expressPath === "string") {
let params = expressPath.match(/:[\w]+/g);
let openAPIPath = expressPath;
if (params) {
let swagerParams = params.map(x => {
return "{" + x.replace(":", "") + "}";
});
openAPIPath = params.reduce((acc, el, ix) => {
return acc.replace(el, swagerParams[ix]);
}, expressPath);
}
return openAPIPath;
function toSwaggerPath(base, path = "") {
if (path instanceof RegExp) {
path = path.toString()
.replace(/^\//, "")
.replace(/\/$/, "")
.replace(/\\/, "");
}
else {
return expressPath;
const completePath = "" + base + path;
// if (typeof expressPath === "string") {
let params = completePath.match(/:[\w]+/g);
let openAPIPath = completePath;
if (params) {
let swaggerParams = params.map(x => {
return "{" + x.replace(":", "") + "}";
});
openAPIPath = params.reduce((acc, el, ix) => {
return acc.replace(el, swaggerParams[ix]);
}, completePath);
}
return ("" + openAPIPath)
.replace(/\/\//gi, "/")
.trim();
}

@@ -24,0 +29,0 @@ exports.toSwaggerPath = toSwaggerPath;

{
"name": "@tsed/swagger",
"version": "4.0.7",
"version": "4.1.0",
"description": "Swagger package for Ts.ED framework",

@@ -11,3 +11,3 @@ "main": "./lib/index.js",

"peerDependencies": {
"@tsed/common": "4.0.7",
"@tsed/common": "4.1.0",
"@types/swagger-schema-official": "^2.0.7",

@@ -56,3 +56,3 @@ "swagger-ui-express": "^2.0.15"

"license": "MIT",
"gitHead": "0b01c16de39e2d01fc94ab6b88b212840990d6a4"
"gitHead": "b02444b7f61c116d030ffdd839a38225af7fd3f0"
}

@@ -0,7 +1,8 @@

import {EndpointMetadata} from "@tsed/common";
import {deepExtends, Store} from "@tsed/core";
import {Operation, Path, Response} from "swagger-schema-official";
import {EndpointMetadata} from "@tsed/common";
import {ExpressPathMethod} from "../../common/mvc/interfaces/ExpressPathMethod";
import {toSwaggerPath} from "../utils";
import {OpenApiModelSchemaBuilder} from "./OpenApiModelSchemaBuilder";
import {OpenApiParamsBuilder} from "./OpenApiParamsBuilder";
import {OpenApiModelSchemaBuilder} from "./OpenApiModelSchemaBuilder";

@@ -25,3 +26,3 @@ /** */

constructor(private endpoint: EndpointMetadata, private endpointUrl: string) {
constructor(private endpoint: EndpointMetadata, private endpointUrl: string, private pathMethod: ExpressPathMethod) {
super(endpoint.target);

@@ -32,3 +33,3 @@ }

const openAPIPath = ("" + toSwaggerPath(`${this.endpointUrl}${this.endpoint.path || ""}`)).trim();
const openAPIPath = toSwaggerPath(this.endpointUrl, this.pathMethod.path);
const produces = this.endpoint.get("produces") || [];

@@ -62,3 +63,3 @@ const consumes = this.endpoint.get("consumes") || [];

path[this.endpoint.httpMethod] = operation;
path[this.pathMethod.method!] = operation;

@@ -65,0 +66,0 @@ responses[this.endpoint.get("statusCode") || "200"] = {description: "Success"};

@@ -0,1 +1,9 @@

import {
ControllerProvider,
ControllerService,
EndpointMetadata,
ExpressApplication,
ServerSettingsService,
Service
} from "@tsed/common";
import {deepExtends, nameOf, Store} from "@tsed/core";

@@ -7,5 +15,2 @@ import * as Express from "express";

import {$log} from "ts-log-debug";
import {
ServerSettingsService, Service, ControllerProvider, EndpointMetadata, ExpressApplication, ControllerService
} from "@tsed/common";
import {OpenApiEndpointBuilder} from "../class/OpenApiEndpointBuilder";

@@ -176,10 +181,12 @@ import {ISwaggerPaths, ISwaggerSettings} from "../interfaces";

ctrl.endpoints.forEach((endpoint: EndpointMetadata) => {
endpoint.pathsMethods.forEach((pathMethod) => {
/* istanbul ignore else */
if (!!pathMethod.method) {
const builder = new OpenApiEndpointBuilder(endpoint, endpointUrl, pathMethod)
.build();
/* istanbul ignore else */
if (endpoint.hasHttpMethod()) {
const builder = new OpenApiEndpointBuilder(endpoint, endpointUrl).build();
deepExtends(paths, builder.paths);
deepExtends(definitions, builder.definitions);
}
deepExtends(paths, builder.paths);
deepExtends(definitions, builder.definitions);
}
});
});

@@ -186,0 +193,0 @@ }

@@ -0,24 +1,34 @@

import {JsonSchema, PathParamsType} from "@tsed/common";
import {deepExtends} from "@tsed/core";
import {JsonSchema, PathParamsType} from "@tsed/common";
/** */
export function toSwaggerPath(expressPath: PathParamsType): PathParamsType {
if (typeof expressPath === "string") {
let params = expressPath.match(/:[\w]+/g);
export function toSwaggerPath(base: string, path: PathParamsType = ""): string {
let openAPIPath = expressPath;
if (params) {
let swagerParams = params.map(x => {
return "{" + x.replace(":", "") + "}";
});
if (path instanceof RegExp) {
path = path.toString()
.replace(/^\//, "")
.replace(/\/$/, "")
.replace(/\\/, "");
}
openAPIPath = params.reduce((acc, el, ix) => {
return acc.replace(el, swagerParams[ix]);
}, expressPath);
}
return openAPIPath;
} else {
return expressPath;
const completePath = "" + base + path;
// if (typeof expressPath === "string") {
let params = completePath.match(/:[\w]+/g);
let openAPIPath = completePath;
if (params) {
let swaggerParams = params.map(x => {
return "{" + x.replace(":", "") + "}";
});
openAPIPath = params.reduce((acc, el, ix) => {
return acc.replace(el, swaggerParams[ix]);
}, completePath);
}
return ("" + openAPIPath)
.replace(/\/\//gi, "/")
.trim();
}

@@ -25,0 +35,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