@platformatic/client
Advanced tools
Comparing version 0.37.3 to 0.37.4
@@ -59,3 +59,3 @@ import { FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify' | ||
export function generateOperationId(path: string, method: string, methodMeta: MethodMetaInterface): string | ||
export function generateOperationId(path: string, method: string, methodMeta: MethodMetaInterface, all: string[]): string | ||
export function buildOpenAPIClient<T>(options: BuildOpenAPIClientOptions, openTelemetry: OpenTelemetry): Promise<T> | ||
@@ -62,0 +62,0 @@ export function buildGraphQLClient(options: BuildGraphQLClientOptions, openTelemetry: OpenTelemetry, logger: AbstractLogger): Promise<BuildGraphQLClientOutput> |
20
index.js
@@ -11,3 +11,3 @@ 'use strict' | ||
function generateOperationId (path, method, methodMeta) { | ||
function generateOperationId (path, method, methodMeta, all) { | ||
let operationId = methodMeta.operationId | ||
@@ -21,3 +21,17 @@ if (!operationId) { | ||
operationId = method.toLowerCase() + stringToUpdate.split(/[/-]+/).map(capitalize).join('') | ||
} else { | ||
let count = 0 | ||
let candidate = operationId | ||
while (all.includes(candidate)) { | ||
if (count === 0) { | ||
// first try with method name | ||
candidate = `${method}${capitalize(operationId)}` | ||
} else { | ||
candidate = `${method}${capitalize(operationId)}${count}` | ||
} | ||
count++ | ||
} | ||
operationId = candidate | ||
} | ||
all.push(operationId) | ||
return operationId | ||
@@ -46,3 +60,3 @@ } | ||
let { fullResponse, throwOnError } = options | ||
const generatedOperationIds = [] | ||
for (const path of Object.keys(spec.paths)) { | ||
@@ -53,3 +67,3 @@ const pathMeta = spec.paths[path] | ||
const methodMeta = pathMeta[method] | ||
const operationId = generateOperationId(path, method, methodMeta) | ||
const operationId = generateOperationId(path, method, methodMeta, generatedOperationIds) | ||
const responses = pathMeta[method].responses | ||
@@ -56,0 +70,0 @@ const successResponses = Object.entries(responses).filter(([s]) => s.startsWith('2')) |
{ | ||
"name": "@platformatic/client", | ||
"version": "0.37.3", | ||
"version": "0.37.4", | ||
"description": "A client for all platformatic backends", | ||
@@ -26,3 +26,3 @@ "main": "index.js", | ||
"tsd": "^0.28.1", | ||
"@platformatic/telemetry": "0.37.3" | ||
"@platformatic/telemetry": "0.37.4" | ||
}, | ||
@@ -29,0 +29,0 @@ "dependencies": { |
@@ -392,3 +392,3 @@ 'use strict' | ||
const updatedMovie = await client.updateMovie({ | ||
const updatedMovie = await client.putUpdateMovie({ | ||
id: 1, | ||
@@ -395,0 +395,0 @@ title: 'The Matrix Reloaded' |
136349
42
4945