Skip to content

NormalizedEndpoint

Unified endpoint model for both spec and code.

Type Definition

typescript
interface NormalizedEndpoint {
  method: HttpMethod
  path: string
  operationId?: string
  pathParams: Param[]
  queryParams: Param[]
  requestBody?: Schema
  responses: Response[]
  tags: string[]
  deprecated: boolean
  source: 'spec' | 'code'
  location?: SourceLocation
}

Fields

FieldTypeDescription
methodHttpMethodHTTP method (GET, POST, PUT, DELETE, PATCH)
pathstringNormalized path with {param} format
operationIdstring?Operation identifier (OpenAPI)
pathParamsParam[]Path parameters
queryParamsParam[]Query parameters
requestBodySchema?Request body schema
responsesResponse[]Response schemas by status code
tagsstring[]API grouping tags
deprecatedbooleanDeprecation flag
source'spec' | 'code'Origin of endpoint definition
locationSourceLocation?Source file location

Supporting Types

HttpMethod

typescript
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'

Param

typescript
interface Param {
  name: string
  required: boolean
  type: string
  schema?: Schema
  description?: string
}

Schema

typescript
interface Schema {
  type: 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean'
  properties?: Record<string, Schema>
  items?: Schema
  required?: string[]
  description?: string
}

Response

typescript
interface Response {
  code: number
  description?: string
  schema?: Schema
}

SourceLocation

typescript
interface SourceLocation {
  file: string
  line?: number
  column?: number
}

Example

From Spec

typescript
const specEndpoint: NormalizedEndpoint = {
  method: 'GET',
  path: '/users/{id}',
  operationId: 'getUser',
  pathParams: [{ name: 'id', required: true, type: 'string' }],
  responses: [{ code: 200, schema: { type: 'object', ... } }],
  source: 'spec',
  location: { file: 'openapi.yaml', line: 45 }
}

From Code

typescript
const codeEndpoint: NormalizedEndpoint = {
  method: 'GET',
  path: '/users/{id}',  // Normalized from Express :id
  pathParams: [{ name: 'id', required: true, type: 'string' }],
  source: 'code',
  location: { file: 'src/routes/user.ts', line: 42 }
}

Path Normalization

Both spec and code use {param} format:

typescript
// OpenAPI: /users/{id} → /users/{id}
// Express: /users/:id  → /users/{id}

See Also

MIT License