@glyphp/adapter-openapi
v3.1.2
Published
Convert an OpenAPI 3.x document into registerable Glyph Protocol glyphs
Maintainers
Readme
@glyphp/adapter-openapi
Converts an OpenAPI 3.x document into glyphs — one per operation — that you can
register on a GlyphServer.
import { glyphsFromOpenApi } from '@glyphp/adapter-openapi'
import { GlyphServer } from '@glyphp/server'
const doc = await fetch('https://api.example.com/openapi.json').then((r) => r.json())
const glyphs = glyphsFromOpenApi(doc, { baseUrl: 'https://api.example.com' })
const server = new GlyphServer({ port: 3100 })
for (const glyph of glyphs) server.register(glyph)
await server.start()Each generated glyph:
- takes its
namefromoperationId(kebab-cased),intentfromsummary - derives
costfrom the HTTP method — GET issafe, POST/PUT/PATCH arecaution, DELETE isdangerand requires confirmation. An operation may override this with thex-glyph-riskvendor extension (safe|caution|danger) when the method heuristic is wrong — e.g. a safe POST search, or a GET that kicks off an expensive irreversible job. The override sets the risk tier (andrequiresConfirmationfollows it), butsideEffects/reversiblestay factual to the method. An unrecognised value is rejected. - carries the operation's parameter and response JSON Schemas (local
$refs resolved) as the cardinput/output - has a handler that proxies the call to the real REST endpoint: path
parameters are substituted, query parameters appended, and the
bodyinput field sent as a JSON request body
Header and cookie parameters are not mapped in this version.
