Skip to content

swaggercppModern C++23 toolkit for Swagger / OpenAPI.

Parse, validate, traverse, write and serve OpenAPI documents — with a typed document model and zero surprises.

Why swaggercpp?

Most C++ OpenAPI libraries stop at "parse to a JSON tree". swaggercpp goes further: it exposes OpenAPI nodes as regular C++23 structures, so tooling authors can inspect and manipulate specifications with normal field access and standard containers.

cpp
#include "swaggercpp/swaggercpp.hpp"

auto result = swaggercpp::DocumentReader::read_file("openapi.yaml");
if (!result) return 1;

swaggercpp::DocumentValidator validator;
const auto report = validator.validate(result.value());

for (const auto& op : result.value().paths) {
    for (const auto& [method, operation] : op.second.operations) {
        std::println("{} {} → {}", swaggercpp::to_string(method), op.first,
                     operation.operation_id.value_or("(anonymous)"));
    }
}

What's in the box

  • DocumentReader — format-detecting parser for JSON and YAML
  • DocumentWriter — serialiser with pretty-printing and round-trip helpers
  • DocumentValidator — semantic checks independent of syntax
  • DocumentWalker — deterministic visitor traversal
  • SwaggerUiServer — embedded HTTP server with Swagger UI shell
  • Result<T> — non-throwing return type with issues attached

License

Released under the MIT License.

Released under the MIT License.