package openapi-opium
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=f96c9e50fbc5f09a66a6c5044dadc786
sha512=6419b8c5ec28d1a74c25607e69b2fa2a9eae5ff40b6a31674181e6d09cbcba71f97f925ac6cc69a9f9fc1eacd4f22b6499b7c6a7dd29919f6e8123140b4157e0
Description
Shim layer around Opium.App (https://github.com/rgrinberg/opium/) for producing Openapi documentation pages
Added to opam-repository:
README
Openapi for Ocaml
This library provides basic types for parsing/serializing openapi specifications and a nearly drop-in replacement for Opium.App that registers endpoints in a specification and serves openapi.json and docs pages based on the fastapi implementation.
As of version 1.0.0, the Opium shim layer has been split out into a separate package (openapi-opium) from the core modules for creating Openapi compatible specifications (openapi). And a PPX has been introduced to (hopefully) accelerate JSON schema specification.
Usage
Basic usage should work equivalently to Opium.App. So instead of
let open Opium in
App.empty
|> App.get "/path/:foo" (fun h -> Response.of_plain_text "hello world")
|> App.run_commandJust do:
let open Opium in
let module App = Openapi_opium.App in
App.empty
|> App.get "/path/:foo" (fun h -> Response.of_plain_text "hello world")
|> App.run_commandThe endpoint creation methods provided by Openapi_opium.App accept additional optional arguments to provide specification information for to document the endpoint. Check the type signatures of these methods for more information.
Demo App
This library includes a demo app in bin/demo (that won't be installed by opam). To see the generated spec/documentation in action, run:
$ dune build
$ ./_build/default/bin/demo.exeThen browse to http://localhost:8888/docs
Ppx Deriving Json Schema
The openapi-ocaml repo also defines a ppx deriving plugin for generating JSON Schema values from OCaml type definitions. It supports record, polymorphic variant, tuple, and union datatypes.
Parameterized types are not properly handled.
The types 'a list and 'a option are handled specially using the JSON schema array type and oneOf [null; 'a_schema] respectively.
Installation
$ opam install ppx_deriving_json_schemaUsage
In your ocaml file:
type some_type = {int_field : int; string_field : string}
[@@deriving yojson, json_schema]Will generate a value some_type_schema defining a JSON schema compatible with JSON serialization produced by the ppx_json_conv deriver.
Subschemas
By default, references to other types within the type definition are reflected as JSON schema references in the generated schema (see Attributes) below. The reference will take the form #/$defs/type_name_schema for a reference to type type_name.
The prefix (#/$defs/) can be overriden using defs argument to the deriver, as in:
type my_type { x : some_type }
[@@deriving yojson, json_schema {defs = "#/components/schemas"}]Attributes
The JSON schema generator respects the @key, @yojson.option, @default, @yojson.drop_* and @name attributes used by ppx_yojson_conv to direct serialization/deserialization.
Additionally, the attribute @inline_schema can be used to direct schema generation to inline the schema for a type reference (by inlining the result of type_name_schema for a reference to the type type_name) rather than using a schema reference
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building openapi-opium with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 1.0.1 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure