New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

trpc-to-openapi

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trpc-to-openapi - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0-alpha.0

6

dist/cjs/generator/paths.js

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

}
const { method, protect, summary, description, tags, requestHeaders, responseHeaders, successDescription, errorResponses, } = openapi;
const { method, summary, description, tags, requestHeaders, responseHeaders, successDescription, errorResponses, protect = true, } = openapi;
const path = (0, path_1.normalizePath)(openapi.path);

@@ -76,3 +76,3 @@ const pathParameters = (0, path_1.getPathParameters)(path);

const isInputRequired = !inputParser.isOptional();
const o = (_c = inputParser === null || inputParser === void 0 ? void 0 : inputParser._def) === null || _c === void 0 ? void 0 : _c.openapi;
const o = (_c = inputParser === null || inputParser === void 0 ? void 0 : inputParser._def.zodOpenApi) === null || _c === void 0 ? void 0 : _c.openapi;
const inputSchema = (0, zod_2.unwrapZodType)(inputParser, true).openapi(Object.assign(Object.assign({}, ((o === null || o === void 0 ? void 0 : o.title) ? { title: o === null || o === void 0 ? void 0 : o.title } : {})), ((o === null || o === void 0 ? void 0 : o.description) ? { description: o === null || o === void 0 ? void 0 : o.description } : {})));

@@ -97,3 +97,3 @@ const requestData = {};

}
const responses = (0, schema_1.getResponsesObject)(outputParser, httpMethod, responseHeaders, protect !== null && protect !== void 0 ? protect : false, (0, schema_1.hasInputs)(inputParser), successDescription, errorResponses);
const responses = (0, schema_1.getResponsesObject)(outputParser, httpMethod, responseHeaders, protect, (0, schema_1.hasInputs)(inputParser), successDescription, errorResponses);
const security = protect ? securitySchemeNames.map((name) => ({ [name]: [] })) : undefined;

@@ -100,0 +100,0 @@ pathsObject[path] = Object.assign(Object.assign({}, pathsObject[path]), { [httpMethod]: Object.assign(Object.assign(Object.assign({ operationId: procedurePath.replace(/\./g, '-'), summary,

@@ -0,1 +1,2 @@

import { TRPCError } from '@trpc/server';
import { AnyZodObject, ZodTypeAny, z } from 'zod';

@@ -8,3 +9,3 @@ import { ZodOpenApiParameters, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject } from 'zod-openapi';

export declare const hasInputs: (schema: unknown) => boolean;
export declare const errorResponseObject: (code?: string, message?: string, issues?: {
export declare const errorResponseObject: (code?: TRPCError["code"], message?: string, issues?: {
message: string;

@@ -11,0 +12,0 @@ }[]) => ZodOpenApiResponseObject;

@@ -76,2 +76,3 @@ "use strict";

const getRequestBodyObject = (schema, required, pathParameters, contentTypes) => {
var _a;
// remove path parameters

@@ -82,3 +83,3 @@ const mask = {};

});
const o = schema._def.openapi;
const o = (_a = schema._def.zodOpenApi) === null || _a === void 0 ? void 0 : _a.openapi;
const dedupedSchema = schema.omit(mask).openapi(Object.assign(Object.assign({}, ((o === null || o === void 0 ? void 0 : o.title) ? { title: o === null || o === void 0 ? void 0 : o.title } : {})), ((o === null || o === void 0 ? void 0 : o.description) ? { description: o === null || o === void 0 ? void 0 : o.description } : {})));

@@ -105,2 +106,3 @@ // if all keys are path parameters

const errorResponseObject = (code = 'INTERNAL_SERVER_ERROR', message, issues) => {
var _a;
if (!errorResponseObjectByCode[code]) {

@@ -130,3 +132,3 @@ errorResponseObjectByCode[code] = {

.openapi({
title: 'Error',
title: `${message !== null && message !== void 0 ? message : 'Internal server'} error (${(_a = errors_1.TRPC_ERROR_CODE_HTTP_STATUS[code]) !== null && _a !== void 0 ? _a : 500})`,
description: 'The error information',

@@ -150,6 +152,6 @@ example: {

const message = code && errors_1.TRPC_ERROR_CODE_MESSAGE[code];
return (0, exports.errorResponseObject)(code !== null && code !== void 0 ? code : 'UNKNOWN_ERROR', message !== null && message !== void 0 ? message : 'Unknown error');
return (0, exports.errorResponseObject)(code, message !== null && message !== void 0 ? message : 'Unknown error');
};
exports.errorResponseFromStatusCode = errorResponseFromStatusCode;
const errorResponseFromMessage = (status, message) => { var _a; return (0, exports.errorResponseObject)((_a = errors_1.HTTP_STATUS_TRPC_ERROR_CODE[status]) !== null && _a !== void 0 ? _a : 'UNKNOWN_ERROR', message); };
const errorResponseFromMessage = (status, message) => (0, exports.errorResponseObject)(errors_1.HTTP_STATUS_TRPC_ERROR_CODE[status], message);
exports.errorResponseFromMessage = errorResponseFromMessage;

@@ -156,0 +158,0 @@ const getResponsesObject = (schema, httpMethod, headers, isProtected, hasInputs, successDescription, errorResponses) => (Object.assign({ 200: {

@@ -0,1 +1,2 @@

import { TRPCError } from '@trpc/server';
import { AnyZodObject, ZodTypeAny, z } from 'zod';

@@ -8,3 +9,3 @@ import { ZodOpenApiParameters, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject } from 'zod-openapi';

export declare const hasInputs: (schema: unknown) => boolean;
export declare const errorResponseObject: (code?: string, message?: string, issues?: {
export declare const errorResponseObject: (code?: TRPCError["code"], message?: string, issues?: {
message: string;

@@ -11,0 +12,0 @@ }[]) => ZodOpenApiResponseObject;

{
"name": "trpc-to-openapi",
"version": "2.0.4",
"version": "2.1.0-alpha.0",
"description": "tRPC OpenAPI",

@@ -53,3 +53,4 @@ "author": "mcampa",

"@trpc/server": "^11.0.0-rc.648",
"zod": "^3.23.8"
"zod": "^3.23.8",
"zod-openapi": "^4.1.0"
},

@@ -60,4 +61,3 @@ "dependencies": {

"lodash.clonedeep": "^4.5.0",
"openapi3-ts": "4.3.3",
"zod-openapi": "^2.19.0"
"openapi3-ts": "4.3.3"
},

@@ -84,2 +84,3 @@ "devDependencies": {

"prettier": "^3.4.1",
"formatter-for-jest-snapshots": "npm:prettier@^2",
"rimraf": "^6.0.1",

@@ -86,0 +87,0 @@ "superjson": "^1.12.3",

@@ -23,5 +23,16 @@ <p align="center">

- 2.0.4 Upgrade to tRPC 11.0.0-rc.648
- 2.0.3 Added support for array inputs for GET requests
- v2.1.0 (alpha)
- Updated the minimum version of `zod-openapi` to 4.1.0.
- Changed `zod-openapi` to a peer dependency.
- The `protect` option now defaults to `true`.
- Improved Error schema titles
- v2.0.4
- Upgraded to tRPC 11.0.0-rc.648.
- v2.0.3
- Added support for array inputs in GET requests.
## Usage

@@ -367,3 +378,3 @@

| `path` | `string` | Pathname this endpoint is exposed on. Value must start with `/`, specify path parameters using `{}`. | `true` | `undefined` |
| `protect` | `boolean` | Requires this endpoint to use a security scheme. | `false` | `false` |
| `protect` | `boolean` | Requires this endpoint to use a security scheme. | `false` | `true` |
| `summary` | `string` | A short summary of the endpoint included in the OpenAPI document. | `false` | `undefined` |

@@ -370,0 +381,0 @@ | `description` | `string` | A verbose description of the endpoint included in the OpenAPI document. | `false` | `undefined` |

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