Skip to content

Commit b96334f

Browse files
authored
Add standalone C++ server using cpp-httplib for OpenAPI-based APIs (#21724)
Supports: All OpenAPI 3.x data types: primitives, arrays, enums, nullable/optional fields, nested objects All parameter types: path, query, header, cookie, and combinations Schema composition: allOf (inheritance), oneOf (discriminated unions), anyOf (flexible unions) Security schemes: API key and bearer token authentication Discriminator-based polymorphic deserialization and error handling Provides: Error handling for invalid JSON, type mismatches, missing/unknown discriminator, and parameter validation Build system integration (CMake) for easy compilation and linking with required dependencies Clear build and run instructions for local development and testing Enables comprehensive, real-world validation of generated C++ server code against OpenAPI specifications
1 parent d47ab0f commit b96334f

132 files changed

Lines changed: 18350 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Samples cpp httplib server
2+
3+
on:
4+
push:
5+
paths:
6+
- "samples/server/petstore/cpp-httplib-server/**"
7+
- ".github/workflows/samples-cpp-httplib-server.yaml"
8+
pull_request:
9+
paths:
10+
- "samples/server/petstore/cpp-httplib-server/**"
11+
- ".github/workflows/samples-cpp-httplib-server.yaml"
12+
13+
env:
14+
GRADLE_VERSION: 6.9
15+
16+
jobs:
17+
build:
18+
name: Build cpp httplib server
19+
strategy:
20+
matrix:
21+
sample:
22+
- samples/server/petstore/cpp-httplib-server/petstore
23+
- samples/server/petstore/cpp-httplib-server/feature-test
24+
os:
25+
- ubuntu-latest
26+
- macOS-latest
27+
- windows-latest
28+
runs-on: ${{ matrix.os }}
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Install dependencies (Linux)
33+
if: matrix.os == 'ubuntu-latest'
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y build-essential libssl-dev zlib1g-dev cmake
37+
38+
- name: Install dependencies (macOS)
39+
if: matrix.os == 'macOS-latest'
40+
run: |
41+
brew install openssl zlib cmake
42+
43+
- name: Install dependencies (Windows)
44+
if: matrix.os == 'windows-latest'
45+
run: |
46+
vcpkg install openssl:x64-windows zlib:x64-windows
47+
shell: cmd
48+
timeout-minutes: 20
49+
50+
- name: Build
51+
working-directory: ${{ matrix.sample }}
52+
run: |
53+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
54+
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
55+
else
56+
cmake -S . -B build
57+
fi
58+
cmake --build build --verbose
59+
shell: bash

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
9191
| | Languages/Frameworks |
9292
| -------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
9393
| **API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later, .NET Standard 1.3 - 2.1, .NET Core 3.1, .NET 5.0. Libraries: RestSharp, GenericHost, HttpClient), **C++** (Arduino, cpp-restsdk, Qt5, Tizen, Unreal Engine 4), **Clojure**, **Crystal**, **Dart**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Apache HttpClient 4.x, Apache HttpClient 5.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client, Spring 6 RestClient, MicroProfile Rest Client, Helidon), **Jetbrains HTTP Client**, **Julia**, **k6**, **Kotlin**, **Lua**, **N4JS**, **Nim**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types, Apollo GraphQL DataStore), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (hyper, reqwest, rust-server), **Scala** (akka, http4s, scalaz, sttp, swagger-async-httpclient, pekko), **Swift** (2.x, 3.x, 4.x, 5.x, 6.x), **Typescript** (AngularJS, Angular (9.x - 19.x), Aurelia, Axios, Fetch, Inversify, jQuery, Nestjs, Node, redux-query, Rxjs), **XoJo**, **Zapier** |
94-
| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Oat++, Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) |
94+
| **Server stubs** | **Ada**, **C#** (ASP.NET Core, Azure Functions), **C++** (Httplib, Oat++, Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin, Echo), **Haskell** (Servant, Yesod), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples), [Vert.x](https://vertx.io/), [Apache Camel](https://camel.apache.org/), [Helidon](https://helidon.io/)), **Julia**, **Kotlin** (Spring Boot, [Ktor](https://github.com/ktorio/ktor), [Vert.x](https://vertx.io/)), **PHP** ([Flight](https://docs.flightphp.com/), Laravel, Lumen, [Mezzio (fka Zend Expressive)](https://github.com/mezzio/mezzio), Slim, Silex, [Symfony](https://symfony.com/)), **Python** (FastAPI, Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** ([rust-server](https://openapi-generator.tech/docs/generators/rust-server/)), **Scala** (Akka, [Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), [Cask](https://github.com/com-lihaoyi/cask), Scalatra) |
9595
| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** |
9696
| **Configuration files** | [**Apache2**](https://httpd.apache.org/) |
9797
| **Others** | **GraphQL**, **JMeter**, **Ktorm**, **MySQL Schema**, **Postman Collection**, **Protocol Buffer**, **WSDL** |
@@ -1025,6 +1025,7 @@ Here is a list of template creators:
10251025
* Apex: @asnelling
10261026
* Bash: @bkryza
10271027
* C: @PowerOfCreation @zhemant [:heart:](https://www.patreon.com/zhemant)
1028+
* C++ Httplib: @rajvesh
10281029
* C++ Oat++: @Kraust
10291030
* C++ REST: @Danielku15
10301031
* C++ Tiny: @AndersSpringborg @kaareHH @michelealbano @mkakbas
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: cpp-httplib-server
2+
outputDir: samples/server/petstore/cpp-httplib-server/feature-test
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/feature-test.json
4+
templateDir: modules/openapi-generator/src/main/resources/cpp-httplib-server
5+
additionalProperties:
6+
apiNamespace: "api"
7+
modelNamespace: "models"
8+
projectName: "cpp-httplib-server-feature-test"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: cpp-httplib-server
2+
outputDir: samples/server/petstore/cpp-httplib-server/petstore
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/petstore.json
4+
templateDir: modules/openapi-generator/src/main/resources/cpp-httplib-server
5+
additionalProperties:
6+
apiNamespace: "api"
7+
modelNamespace: "models"
8+
projectName: "cpp-httplib-server-petstore"

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The following generators are available:
8989
* [ada-server](generators/ada-server.md)
9090
* [aspnet-fastendpoints](generators/aspnet-fastendpoints.md)
9191
* [aspnetcore](generators/aspnetcore.md)
92+
* [cpp-httplib-server](generators/cpp-httplib-server.md)
9293
* [cpp-oatpp-server](generators/cpp-oatpp-server.md)
9394
* [cpp-pistache-server](generators/cpp-pistache-server.md)
9495
* [cpp-qt-qhttpengine-server](generators/cpp-qt-qhttpengine-server.md)

docs/generators/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The following generators are available:
6565
## SERVER generators
6666
* [ada-server](ada-server.md)
6767
* [aspnetcore](aspnetcore.md)
68+
* [cpp-httplib-server](cpp-httplib-server.md)
6869
* [cpp-oatpp-server](cpp-oatpp-server.md)
6970
* [cpp-pistache-server](cpp-pistache-server.md)
7071
* [cpp-qt5-qhttpengine-server](cpp-qt5-qhttpengine-server.md)

0 commit comments

Comments
 (0)