Homoiconic [ ... ] data validator, JSON Schema Draft 2020-12 emitter, OpenAPI 3.1 spec builder, and interactive HTML API Explorer.
Pure-Veko homoiconic schema validator (openapi/schema), JSON Schema Draft 2020-12 emitter, OpenAPI 3.1.0 specification generator, and zero-CDN Light-First interactive HTML API Explorer for web/App.
openapi unifies runtime request/response validation and live API documentation from a single declarative source of truth:
openapi/schema: Define schemas using either typed combinators (sc/object, sc/field, sc/opt, sc/str-len, sc/int-range, sc/email, sc/array-of) OR Veko's homoiconic quote [...] dialect (sc/from-quote). Validate arbitrary JSON/Veko payloads with exact dotted/indexed error paths (limits.cpu, tags[1]), and emit standard JSON Schema Draft 2020-12 maps.openapi: Build OpenAPI 3.1.0 specifications (new-api, add-schema, add-endpoint, to-openapi-doc, to-openapi-json) with automatic :param -> {param} route conversion and mount a self-contained, zero-CDN Light-First HTML5 API Explorer (mount-explorer) directly onto any web/App.veko pkg add openapi@1.0.0Import in .vk modules:
use [
oa = openapi
sc = openapi/schema
web
]mount-explorer serves 100% inline HTML, CSS, and JavaScript directly from your Veko binary. No external scripts, fonts, or stylesheets are requested by client browsers, satisfying strict Content-Security-Policy environments.title, version, description) is HTML-escaped via html/escape, and embedded OpenAPI JSON escapes </ sequences (<\/) so schema descriptions containing </script> can never break out of the <script type="application/json"> data island..int_t accepts both native i64 values and whole-number f64 values decoded by json/decode (8443.0), while rejecting fractional numbers (3.14).data-theme="light" (#f8fafc canvas, #ffffff cards) with a persistent localStorage Dark Mode toggle, tag sub-tabs, on-demand JSON Lightbox Modal (Escape to dismiss), and non-blocking toast notifications.openapi/schema| Type / Signature | Description |
|---|---|
Schema, FieldSpec, ValidationError | Core schema AST and validation failure structures. |
str-type = fn [] Schema / str-len = fn [min_n i64, max_n i64] Schema | String schema constructors with optional UTF-8 length bounds. |
email = fn [] Schema / uri-type = fn [] Schema / uuid-type = fn [] Schema | Format-constrained string schemas (email, uri, uuid). |
enum-of = fn [allowed block] Schema | String enum constraint. |
int-type = fn [] Schema / int-range = fn [min_v i64, max_v i64] Schema | Integer schema constructors with inclusive bounds. |
num-type = fn [] Schema / num-range = fn [min_v f64, max_v f64] Schema | Floating-point/numeric schema constructors. |
bool-type = fn [] Schema / any-type = fn [] Schema / nullable = fn [inner Schema] Schema | Boolean, unconstrained, and nullable schema wrappers. |
array-of = fn [items_schema Schema /min min_n i64 = -1 /max max_n i64 = -1] Schema | Array schema with item schema and optional length bounds. |
field = fn [name str, schema Schema] FieldSpec / opt = fn [name str, schema Schema] FieldSpec | Required and optional object property descriptors. |
object = fn [fields block /strict disallow_extra bool = false] Schema | Object schema combinator (/strict sets additionalProperties: false). |
from-quote = fn [dsl block /strict disallow_extra bool = false] Schema | Compiles a homoiconic quote [...] block into an object Schema. |
validate = fn [schema Schema, val any] any | Returns .ok or { ok = false, errors = [ { path = '...', message = '...' } ] }. |
to-json-schema = fn [s Schema /root include_meta bool = false] map | Emits a JSON Schema Draft 2020-12 map. |
openapi| Type / Signature | Description |
|---|---|
ApiSpec, EndpointSpec, QueryParam | OpenAPI 3.1.0 specification and operation descriptors. |
new-api = fn [title str, version str /desc description str = '' /server server_url str = ''] ApiSpec | Initializes an OpenAPI 3.1.0 builder. |
add-schema = fn [mut api ApiSpec, name str, schema sc/Schema] enum | Registers #/components/schemas/<name>. |
add-endpoint = fn [mut api ApiSpec, ep EndpointSpec] enum | Registers an HTTP endpoint operation on api. |
to-openapi-doc = fn [api ApiSpec] map | Emits the structured OpenAPI 3.1.0 document map. |
to-openapi-json = fn [api ApiSpec] str | Serializes the OpenAPI 3.1.0 specification as JSON. |
render-explorer-html = fn [api ApiSpec, spec_json_path str] str | Generates the standalone HTML5 API Explorer page. |
mount-explorer = fn [mut app web/App, prefix str, api ApiSpec] enum | Mounts /openapi.json and the interactive Explorer at prefix on mut app. |
quote [...] Validation & OpenAPI Explorer Mountinguse [oa = openapi, sc = openapi/schema, web]
CreateNodeSchema = sc/from-quote/strict (quote [
hostname str .min 3 .max 64,
admin_email str .email,
port i64 .min 1 .max 65535,
roles block[str] .optional
]) true
mut api = oa/new-api/desc 'Cluster API' '1.0.0' 'Node lifecycle management'
_ = oa/add-endpoint mut api (oa/EndpointSpec {
method = 'POST'
path = '/nodes/:region'
summary = 'Register cluster node'
tags = ['Nodes']
request_schema = CreateNodeSchema
status_code = 201
auth_bearer = true
})
mut app = web/new-app
_ = oa/mount-explorer mut app '/openapi' api
_ = web/post mut app '/nodes/:region' fn [req web/Request] web/Response [
body = web/bind-json/or req [ return (web/bad-request 'invalid JSON') ]
chk = sc/validate CreateNodeSchema body
if chk != .ok [ return (web/json-resp 422 chk) ]
web/json-resp 201 { registered = true, region = (web/param req 'region' '') }
]veko check --strict-types packages/openapi/src/schema.vk
veko check packages/openapi/src/mod.vk
veko check packages/openapi/examples/demo.vk
veko run -C all packages/openapi/examples/demo.vkhttps://veko-lang.org/pkg/openapi/1.0.0.vkpe11ccf0ac55e283be2eee5bb2366126e1c8a5d9470e3cdfbdc6335fac333e2ad6d4e8e9ca7ed7b04b4bdda0345e854587517fee0500c7875bfca67142809d898ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"openapi","version":"1.0.0","tier":1.0,"tier_label":"Tier 1: Backend Essentials","category":"Schemas & OpenAPI 3.1","description":"Homoiconic [ ... ] data validator, JSON Schema Draft 2020-12 emitter, OpenAPI 3.1 spec builder, and interactive HTML API Explorer.","modules":["openapi","openapi/schema"],"homepage":"https://veko-lang.org/packages/openapi"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 6 KB | e47e4d2c0f93410ea9c5755f8b6dc71bec26bf355a158a62ab245120dfcb87c7 |
| examples/demo.vk | 8 KB | e3c89426a5d662f9d84d9adb48610ffe17f9975658a8f2027a1f2bba9dc65f00 |
| mod.vk | 19 KB | 5dae43d085d74502242093bc718af7052d94ce35f8972f5933dc157494ffb923 |
| schema.vk | 17 KB | 7cf07c2261d7dd4cee8f921b7312f4b565f39a9defeb9211ad067cbdfe52f40f |