OpenAPI type information for Rust structs and enums
  • Rust 97.5%
  • Jinja 1.9%
  • Shell 0.6%
Find a file
Dominic feed223fde
All checks were successful
Rust / readme (push) Successful in 15s
Rust / rustfmt (push) Successful in 1m50s
Rust / Test (Rust Nightly) (push) Successful in 1m25s
Rust / Test (Rust MSRV) (push) Successful in 2m59s
Rust / test-trybuild (push) Successful in 1m27s
Rust / Test (Rust Stable) (push) Successful in 1m27s
Rust / Clippy (Rust Nightly) (push) Successful in 1m38s
Rust / Clippy (Rust 1.95) (push) Successful in 1m39s
Add support for hashbrown 0.17
2026-05-10 14:12:16 +02:00
.forgejo/workflows CI: fix clippy 2026-05-10 14:07:08 +02:00
derive Move lints from Rust code to Cargo.toml 2026-05-10 13:48:13 +02:00
src Add support for hashbrown 0.17 2026-05-10 14:12:16 +02:00
tests Add support for hashbrown 0.17 2026-05-10 14:12:16 +02:00
.gitignore add GitHub Actions 2021-03-09 23:01:46 +01:00
Cargo.toml Add support for hashbrown 0.17 2026-05-10 14:12:16 +02:00
crates-io.j2 bump MSRV to 1.76 for dependency of trybuild 2026-02-12 11:10:44 +01:00
crates-io.md Add support for hashbrown 0.17 2026-05-10 14:12:16 +02:00
doc2readme.toml Use config file for cargo doc2readme 2026-03-08 15:54:11 +01:00
LICENSE import code from https://gitlab.com/msrd0/gotham-restful 2021-03-09 22:44:00 +01:00
README.j2 bump MSRV to 1.76 for dependency of trybuild 2026-02-12 11:10:44 +01:00
README.md Add support for hashbrown 0.17 2026-05-10 14:12:16 +02:00
rustfmt.toml update code format 2026-02-12 10:55:54 +01:00

This repository contains the following crates:

  • openapi_type openapi_type on crates.io openapi_type on docs.rs Rust Version: 1.87.0 License Apache-2.0
  • openapi_type_derive openapi_type_derive on crates.io openapi_type_derive on docs.rs Rust Version: 1.87.0 License Apache-2.0

openapi_type

This crate gives static type information for primitives and commonly used types from the standard library and other commonly used libraries (See #features) when the according feature is enabled. Please refer to the Cargo.toml for a list of all available feature flags and optional dependencies. Also, it provides a derive macro for structs and enums to gain access to their static type information at runtime.

The core of this crate is the OpenapiType trait. It has one static function, schema, which returns an OpenapiSchema. This assembles the static type information in a way that is convenient to use for a generated OpenAPI specification, but can also be utilized in other use cases as well.

Custom Types

To gain access to the static type information of your custom types at runtime, the easiest way is to use the derive macro:

#[derive(OpenapiType)]
struct FooBar {
	foo: String,
	bar: u64
}

OpenAPI specification

Using above type, running FooBar::schema().into_schema() yields

properties:
  foo:
    type: string
  bar:
    type: integer
    format: int64
    minimum: 0
type: object
required:
  - foo
  - bar
title: FooBar

Note, however, that this is not sufficient for more complex types. If one of your structs fields is a type that has a name (that is, Type::schema().name is not None), above schema will contain a reference to that schema. Therefore, always remember to put the dependencies into the specification alongside the type you are interested in.

Features

  • chrono: Enable all of the below:
  • hashbrown: Enable all of the below:
  • jiff: Enable all of the below:
    • jiff02: Enable implementations for jiff 0.2
  • linked-hash-map: Enable all of the below:
  • time: Enable all of the below:
    • time03: Enable implementations for time 0.3
  • url: Enable all of the below:
    • url2: Enable implementations for url 2.x
  • uuid: Enable all of the below:
    • uuid1: Enable implementations for uuid 1.x

Note that support for indexmap 2.x is enabled by default.

Versioning

Like all rust crates, this crate will follow semantic versioning guidelines. However, changing the MSRV (minimum supported rust version) is not considered a breaking change.

License

Copyright (C) 2021-2026 Dominic Meiser and contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.