kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
c034c9eef3
commit
9b49a4be30
|
@ -4,8 +4,8 @@ import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
|||
import type { AuthenticatedEnv } from '@/lib/types'
|
||||
import { db, eq, schema } from '@/db'
|
||||
import { acl } from '@/lib/acl'
|
||||
import { normalizeDeploymentVersion } from '@/lib/deployments/normalize-deployment-version'
|
||||
import { publishDeployment } from '@/lib/deployments/publish-deployment'
|
||||
import { resolveDeploymentVersion } from '@/lib/deployments/resolve-deployment-version'
|
||||
import { validateDeploymentOriginAdapter } from '@/lib/deployments/validate-deployment-origin-adapter'
|
||||
import { ensureAuthUser } from '@/lib/ensure-auth-user'
|
||||
import {
|
||||
|
@ -92,7 +92,7 @@ export function registerV1DeploymentsCreateDeployment(
|
|||
}
|
||||
|
||||
if (version) {
|
||||
version = resolveDeploymentVersion({
|
||||
version = normalizeDeploymentVersion({
|
||||
deploymentId,
|
||||
project,
|
||||
version
|
||||
|
|
|
@ -3,7 +3,7 @@ import semver from 'semver'
|
|||
import type { RawProject } from '@/db/types'
|
||||
import { assert } from '@/lib/utils'
|
||||
|
||||
export function resolveDeploymentVersion({
|
||||
export function normalizeDeploymentVersion({
|
||||
deploymentId,
|
||||
version: rawVersion,
|
||||
project
|
|
@ -3,7 +3,7 @@ import { acl } from '@/lib/acl'
|
|||
import { assert } from '@/lib/utils'
|
||||
|
||||
import type { AuthenticatedContext } from '../types'
|
||||
import { resolveDeploymentVersion } from './resolve-deployment-version'
|
||||
import { normalizeDeploymentVersion } from './normalize-deployment-version'
|
||||
|
||||
export async function publishDeployment(
|
||||
ctx: AuthenticatedContext,
|
||||
|
@ -24,7 +24,7 @@ export async function publishDeployment(
|
|||
assert(project, 404, `Project not found "${deployment.projectId}"`)
|
||||
await acl(ctx, project, { label: 'Project' })
|
||||
|
||||
const version = resolveDeploymentVersion({
|
||||
const version = normalizeDeploymentVersion({
|
||||
deploymentId: deployment.id,
|
||||
project,
|
||||
version: rawVersion
|
||||
|
|
|
@ -13,43 +13,12 @@ import parseJson from 'parse-json'
|
|||
import type { Logger } from './logger'
|
||||
import type { LooseOpenAPI3Spec } from './types'
|
||||
|
||||
function _processProblems(
|
||||
problems: NormalizedProblem[],
|
||||
{
|
||||
logger,
|
||||
silent
|
||||
}: {
|
||||
logger: Logger
|
||||
silent: boolean
|
||||
}
|
||||
) {
|
||||
if (problems.length) {
|
||||
let errorMessage: string | undefined
|
||||
|
||||
for (const problem of problems) {
|
||||
const problemLocation = problem.location?.[0]?.pointer
|
||||
const problemMessage = problemLocation
|
||||
? `${problem.message} at ${problemLocation}`
|
||||
: problem.message
|
||||
|
||||
if (problem.severity === 'error') {
|
||||
errorMessage = problemMessage
|
||||
logger.error('openapi spec error', problemMessage)
|
||||
} else if (!silent) {
|
||||
logger.warn('openapi spec warning', problemMessage)
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage) {
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an OpenAPI spec and bundles it into a single, normalized schema.
|
||||
*
|
||||
* The input `source` should be a JSON stringified OpenAPI spec (3.0 or 3.1).
|
||||
*
|
||||
* Adapted from https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/src/lib/redoc.ts
|
||||
*/
|
||||
export async function validateOpenAPISpec(
|
||||
source: string,
|
||||
|
@ -133,3 +102,36 @@ export async function validateOpenAPISpec(
|
|||
|
||||
return bundled.bundle.parsed
|
||||
}
|
||||
|
||||
function _processProblems(
|
||||
problems: NormalizedProblem[],
|
||||
{
|
||||
logger,
|
||||
silent
|
||||
}: {
|
||||
logger: Logger
|
||||
silent: boolean
|
||||
}
|
||||
) {
|
||||
if (problems.length) {
|
||||
let errorMessage: string | undefined
|
||||
|
||||
for (const problem of problems) {
|
||||
const problemLocation = problem.location?.[0]?.pointer
|
||||
const problemMessage = problemLocation
|
||||
? `${problem.message} at ${problemLocation}`
|
||||
: problem.message
|
||||
|
||||
if (problem.severity === 'error') {
|
||||
errorMessage = problemMessage
|
||||
logger.error('openapi spec error', problemMessage)
|
||||
} else if (!silent) {
|
||||
logger.warn('openapi spec warning', problemMessage)
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage) {
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue