GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode/packages/protocol/script/openapi-parameters.ts at dev · erickwill/opencode

Expand file tree

/

openapi-parameters.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
30 lines (27 loc) · 1.8 KB
/

openapi-parameters.ts

Copy path

File metadata and controls

30 lines (27 loc) · 1.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
type Schema = { description?: string; allOf?: Array<Record<string, unknown>>; [key: string]: unknown }
type Parameter = { description?: string; schema?: Schema; [key: string]: unknown }
type Document = { paths?: Record<string, Record<string, { parameters?: Array<Parameter> }>> }
// Effect writes a parameter's description into its schema: `.annotate` sets `schema.description`, and `.annotateKey`
// (used where annotating would rename a shared component) adds a `{ description }` member to `schema.allOf`. OpenAPI
// documents parameters by `parameters[].description`, so move it there.
export function liftParameterDescriptions<T extends object>(document: T): T {
for (const operations of Object.values((document as Document).paths ?? {}))
for (const operation of Object.values(operations))
operation.parameters = operation.parameters?.map((parameter) => {
if (parameter.schema === undefined || parameter.description !== undefined) return parameter
const description = parameter.schema.allOf?.find(isDescription)?.description ?? parameter.schema.description
if (description === undefined) return parameter
return { ...parameter, description, schema: withoutDescription(parameter.schema) }
})
return document
}
function isDescription(member: Record<string, unknown>): member is { description: string } {
return Object.keys(member).length === 1 && typeof member.description === "string"
}
function withoutDescription(schema: Schema): Schema {
const rest = Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "description" && key !== "allOf"))
const allOf = schema.allOf?.filter((member) => !isDescription(member)) ?? []
if (allOf.length === 0) return rest
if (allOf.length === 1 && Object.keys(rest).length === 0) return allOf[0]
return { ...rest, allOf }
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.