Skip to content

Commit 5fa32aa

Browse files
committed
Add standalone C++ server using cpp-httplib for OpenAPI-based APIs
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 bdfbb32 commit 5fa32aa

132 files changed

Lines changed: 19640 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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Samples cpp httplib server
2+
# This workflow tests the C++ httplib server code generator across multiple platforms.
3+
# Dependencies installed per OS:
4+
# - nlohmann/json: Auto-fetched via CMake FetchContent
5+
# - cpp-httplib: Auto-fetched via CMake FetchContent
6+
# - OpenSSL: System package (libssl-dev on Linux, openssl on macOS, vcpkg on Windows)
7+
# - ZLIB: System package (zlib1g-dev on Linux, zlib on macOS, vcpkg on Windows)
8+
# - CMake: Build tool (apt on Linux, brew on macOS, pre-installed on Windows)
9+
10+
on:
11+
push:
12+
paths:
13+
- "samples/server/petstore/cpp-httplib-server/**"
14+
- "modules/openapi-generator/src/main/resources/cpp-httplib-server/**"
15+
- "modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppHttplibServerCodegen.java"
16+
- "modules/openapi-generator/src/test/java/org/openapitools/codegen/cpphttplibserver/**"
17+
- "modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/**"
18+
- "bin/configs/cpp-httplib-server*.yaml"
19+
- ".github/workflows/samples-cpp-httplib-server.yaml"
20+
pull_request:
21+
paths:
22+
- "samples/server/petstore/cpp-httplib-server/**"
23+
- "modules/openapi-generator/src/main/resources/cpp-httplib-server/**"
24+
- "modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppHttplibServerCodegen.java"
25+
- "modules/openapi-generator/src/test/java/org/openapitools/codegen/cpphttplibserver/**"
26+
- "modules/openapi-generator/src/test/resources/3_0/cpp-httplib-server/**"
27+
- "bin/configs/cpp-httplib-server*.yaml"
28+
- ".github/workflows/samples-cpp-httplib-server.yaml"
29+
30+
jobs:
31+
build:
32+
name: Build cpp httplib server
33+
strategy:
34+
matrix:
35+
sample:
36+
- samples/server/petstore/cpp-httplib-server/petstore
37+
- samples/server/petstore/cpp-httplib-server/feature-test
38+
os:
39+
- ubuntu-latest
40+
- macOS-latest
41+
- windows-latest
42+
runs-on: ${{ matrix.os }}
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up JDK 11
46+
uses: actions/setup-java@v4
47+
with:
48+
java-version: '11'
49+
distribution: 'temurin'
50+
- name: Cache Maven packages
51+
uses: actions/cache@v4
52+
with:
53+
path: ~/.m2
54+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
55+
restore-keys: ${{ runner.os }}-m2
56+
- name: Build OpenAPI Generator
57+
run: ./mvnw clean package -DskipTests -pl modules/openapi-generator-cli -am
58+
- name: Run unit tests for CppHttplibServerCodegen
59+
run: ./mvnw -pl modules/openapi-generator test -Dtest=CppHttplibServerCodegenTest,CppHttplibServerCodegenModelTest
60+
- name: Generate C++ httplib server samples (petstore + feature-test)
61+
run: |
62+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar batch bin/configs/cpp-httplib-server-petstore.yaml
63+
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar batch bin/configs/cpp-httplib-server-feature-test.yaml
64+
- name: Install dependencies (Linux)
65+
if: matrix.os == 'ubuntu-latest'
66+
run: |
67+
sudo apt-get update
68+
sudo apt-get install -y build-essential libssl-dev zlib1g-dev cmake
69+
- name: Install dependencies (macOS)
70+
if: matrix.os == 'macOS-latest'
71+
run: |
72+
brew install openssl zlib cmake
73+
- name: Install dependencies (Windows)
74+
if: matrix.os == 'windows-latest'
75+
run: |
76+
vcpkg install openssl:x64-windows zlib:x64-windows --recurse
77+
shell: pwsh
78+
timeout-minutes: 10
79+
- name: Set vcpkg toolchain (Windows)
80+
if: matrix.os == 'windows-latest'
81+
run: echo "CMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" >> $GITHUB_ENV
82+
shell: bash
83+
- name: Build generated C++ code
84+
working-directory: ${{ matrix.sample }}
85+
run: |
86+
if [ "${{ matrix.os }}" = "windows-latest" ]; then
87+
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE
88+
else
89+
cmake -S . -B build
90+
fi
91+
cmake --build build --verbose
92+
shell: bash

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
9292
| | Languages/Frameworks |
9393
| -------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
9494
| **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** |
95-
| **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) |
95+
| **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) |
9696
| **API documentation generators** | **HTML**, **Confluence Wiki**, **Asciidoc**, **Markdown**, **PlantUML** |
9797
| **Configuration files** | [**Apache2**](https://httpd.apache.org/) |
9898
| **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+
templateDi: 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)