From c261130b17e4ff19e3e2a8f204fa3922068008d1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 14 Oct 2026 11:19:52 +0800 Subject: [PATCH] add inline, better code indentation --- .../cpp-httplib-server/model-header.mustache | 64 +++++------ .../feature-test/models/Address.h | 44 +++---- .../feature-test/models/Animal.h | 26 ++--- .../feature-test/models/ArrayTypes.h | 66 +++++------ .../feature-test/models/BankAccount.h | 30 ++--- .../feature-test/models/Company.h | 50 ++++---- .../feature-test/models/CreatedResponse.h | 34 +++--- .../feature-test/models/CreditCard.h | 30 ++--- .../feature-test/models/Department.h | 34 +++--- .../feature-test/models/Dog.h | 36 +++--- .../feature-test/models/Employee.h | 48 ++++---- .../feature-test/models/EnumTypes.h | 46 ++++---- .../feature-test/models/ErrorResponse.h | 40 +++---- .../feature-test/models/NotFoundResponse.h | 30 ++--- .../models/NullableOptionalTypes.h | 60 +++++----- .../feature-test/models/PrimitiveTypes.h | 108 +++++++++--------- .../feature-test/models/SimpleObject.h | 34 +++--- .../feature-test/models/SuccessResponse.h | 26 ++--- .../models/TestAllParameterTypes200Response.h | 56 ++++----- .../models/TestApiKeySecurity200Response.h | 26 ++--- .../models/TestBasicSecurity200Response.h | 26 ++--- .../models/TestBearerSecurity200Response.h | 26 ++--- .../models/TestCookieParameters200Response.h | 26 ++--- .../models/TestHeaderParameters200Response.h | 26 ++--- .../models/TestHeaderParameters401Response.h | 26 ++--- .../models/TestOAuth2Security200Response.h | 26 ++--- .../models/TestQueryParameters200Response.h | 26 ++--- .../TestQueryParametersDeepObjectParameter.h | 36 +++--- .../petstore/models/ApiResponse.h | 46 ++++---- .../petstore/models/Category.h | 36 +++--- .../petstore/models/ComplexParamsResponse.h | 76 ++++++------ .../petstore/models/DeepObj.h | 46 ++++---- .../petstore/models/DeepObjBaz.h | 36 +++--- .../petstore/models/NullableExample.h | 26 ++--- .../petstore/models/Order.h | 76 ++++++------ .../cpp-httplib-server/petstore/models/Pet.h | 64 +++++------ .../cpp-httplib-server/petstore/models/Tag.h | 36 +++--- .../cpp-httplib-server/petstore/models/User.h | 96 ++++++++-------- 38 files changed, 822 insertions(+), 822 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-httplib-server/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-httplib-server/model-header.mustache index 41e1bf8e2dc5..da32024178d2 100644 --- a/modules/openapi-generator/src/main/resources/cpp-httplib-server/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-httplib-server/model-header.mustache @@ -264,43 +264,43 @@ public: {{/isArray}}{{/isEnum}}{{/vars}} -friend void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& o) -{ - {{^parent}} - j = nlohmann::json::object(); - {{/parent}} - {{#parent}} - // Serialize inherited properties via the parent's serializer - to_json(j, static_cast(o)); - {{/parent}} - {{#vars}} - j["{{baseName}}"] = o.{{nameInCamelCase}}; - {{/vars}} -} - -friend void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const {{vendorExtensions.modelClassName}}& o) { - throw nlohmann::json::type_error::create(302, "{{vendorExtensions.modelClassName}} must be a JSON object", &j); + {{^parent}} + j = nlohmann::json::object(); + {{/parent}} + {{#parent}} + // Serialize inherited properties via the parent's serializer + to_json(j, static_cast(o)); + {{/parent}} + {{#vars}} + j["{{baseName}}"] = o.{{nameInCamelCase}}; + {{/vars}} } - {{#parent}} - // Deserialize inherited properties via the parent's deserializer - from_json(j, static_cast<{{parent}}&>(o)); - {{/parent}} - {{#vars}} - {{#required}} - j.at("{{baseName}}").get_to(o.{{nameInCamelCase}}); - {{/required}} - {{^required}} - {{! Present null reaches get_to (resets std::optional, rejected for non-nullable); skipped only for nullable members that cannot hold null }} - if (j.contains("{{baseName}}"){{#isNullable}}{{^vendorExtensions.isOptionalEnum}} && !j.at("{{baseName}}").is_null(){{/vendorExtensions.isOptionalEnum}}{{/isNullable}}) + + friend inline void from_json(const nlohmann::json& j, {{vendorExtensions.modelClassName}}& o) { + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "{{vendorExtensions.modelClassName}} must be a JSON object", &j); + } + {{#parent}} + // Deserialize inherited properties via the parent's deserializer + from_json(j, static_cast<{{parent}}&>(o)); + {{/parent}} + {{#vars}} + {{#required}} j.at("{{baseName}}").get_to(o.{{nameInCamelCase}}); + {{/required}} + {{^required}} + {{! Present null reaches get_to (resets std::optional, rejected for non-nullable); skipped only for nullable members that cannot hold null }} + if (j.contains("{{baseName}}"){{#isNullable}}{{^vendorExtensions.isOptionalEnum}} && !j.at("{{baseName}}").is_null(){{/vendorExtensions.isOptionalEnum}}{{/isNullable}}) + { + j.at("{{baseName}}").get_to(o.{{nameInCamelCase}}); + } + {{/required}} + {{/vars}} } - {{/required}} - {{/vars}} -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Address.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Address.h index 047b7f2af5a4..1fa50ad54990 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Address.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Address.h @@ -32,32 +32,32 @@ class Address void setCountry(const std::string& country); -friend void to_json(nlohmann::json& j, const Address& o) -{ - j = nlohmann::json::object(); - j["street"] = o.street; - j["city"] = o.city; - j["zipCode"] = o.zipCode; - j["country"] = o.country; -} - -friend void from_json(const nlohmann::json& j, Address& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Address& o) { - throw nlohmann::json::type_error::create(302, "Address must be a JSON object", &j); + j = nlohmann::json::object(); + j["street"] = o.street; + j["city"] = o.city; + j["zipCode"] = o.zipCode; + j["country"] = o.country; } - j.at("street").get_to(o.street); - j.at("city").get_to(o.city); - if (j.contains("zipCode")) - { - j.at("zipCode").get_to(o.zipCode); - } - if (j.contains("country")) + + friend inline void from_json(const nlohmann::json& j, Address& o) { - j.at("country").get_to(o.country); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Address must be a JSON object", &j); + } + j.at("street").get_to(o.street); + j.at("city").get_to(o.city); + if (j.contains("zipCode")) + { + j.at("zipCode").get_to(o.zipCode); + } + if (j.contains("country")) + { + j.at("country").get_to(o.country); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Animal.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Animal.h index 76a7dc296723..679953d9e03f 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Animal.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Animal.h @@ -28,22 +28,22 @@ class Animal void setType(const std::string& type); -friend void to_json(nlohmann::json& j, const Animal& o) -{ - j = nlohmann::json::object(); - j["name"] = o.name; - j["type"] = o.type; -} + friend inline void to_json(nlohmann::json& j, const Animal& o) + { + j = nlohmann::json::object(); + j["name"] = o.name; + j["type"] = o.type; + } -friend void from_json(const nlohmann::json& j, Animal& o) -{ - if (!j.is_object()) + friend inline void from_json(const nlohmann::json& j, Animal& o) { - throw nlohmann::json::type_error::create(302, "Animal must be a JSON object", &j); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Animal must be a JSON object", &j); + } + j.at("name").get_to(o.name); + j.at("type").get_to(o.type); } - j.at("name").get_to(o.name); - j.at("type").get_to(o.type); -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/ArrayTypes.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/ArrayTypes.h index 6b4fa3544c4f..dbb4cbed297c 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/ArrayTypes.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/ArrayTypes.h @@ -48,43 +48,43 @@ class ArrayTypes void setNestedArray(const std::vector>& nestedArray); -friend void to_json(nlohmann::json& j, const ArrayTypes& o) -{ - j = nlohmann::json::object(); - j["stringArray"] = o.stringArray; - j["intArray"] = o.intArray; - j["objectArray"] = o.objectArray; - j["enumArray"] = o.enumArray; - j["nestedArray"] = o.nestedArray; -} - -friend void from_json(const nlohmann::json& j, ArrayTypes& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "ArrayTypes must be a JSON object", &j); - } - if (j.contains("stringArray")) - { - j.at("stringArray").get_to(o.stringArray); - } - if (j.contains("intArray")) + friend inline void to_json(nlohmann::json& j, const ArrayTypes& o) { - j.at("intArray").get_to(o.intArray); + j = nlohmann::json::object(); + j["stringArray"] = o.stringArray; + j["intArray"] = o.intArray; + j["objectArray"] = o.objectArray; + j["enumArray"] = o.enumArray; + j["nestedArray"] = o.nestedArray; } - if (j.contains("objectArray")) - { - j.at("objectArray").get_to(o.objectArray); - } - if (j.contains("enumArray")) - { - j.at("enumArray").get_to(o.enumArray); - } - if (j.contains("nestedArray")) + + friend inline void from_json(const nlohmann::json& j, ArrayTypes& o) { - j.at("nestedArray").get_to(o.nestedArray); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "ArrayTypes must be a JSON object", &j); + } + if (j.contains("stringArray")) + { + j.at("stringArray").get_to(o.stringArray); + } + if (j.contains("intArray")) + { + j.at("intArray").get_to(o.intArray); + } + if (j.contains("objectArray")) + { + j.at("objectArray").get_to(o.objectArray); + } + if (j.contains("enumArray")) + { + j.at("enumArray").get_to(o.enumArray); + } + if (j.contains("nestedArray")) + { + j.at("nestedArray").get_to(o.nestedArray); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/BankAccount.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/BankAccount.h index c1c7f49c8e93..d6e99cefbbdb 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/BankAccount.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/BankAccount.h @@ -30,24 +30,24 @@ class BankAccount void setBankName(const std::string& bankName); -friend void to_json(nlohmann::json& j, const BankAccount& o) -{ - j = nlohmann::json::object(); - j["paymentType"] = o.paymentType; - j["accountNumber"] = o.accountNumber; - j["bankName"] = o.bankName; -} + friend inline void to_json(nlohmann::json& j, const BankAccount& o) + { + j = nlohmann::json::object(); + j["paymentType"] = o.paymentType; + j["accountNumber"] = o.accountNumber; + j["bankName"] = o.bankName; + } -friend void from_json(const nlohmann::json& j, BankAccount& o) -{ - if (!j.is_object()) + friend inline void from_json(const nlohmann::json& j, BankAccount& o) { - throw nlohmann::json::type_error::create(302, "BankAccount must be a JSON object", &j); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "BankAccount must be a JSON object", &j); + } + j.at("paymentType").get_to(o.paymentType); + j.at("accountNumber").get_to(o.accountNumber); + j.at("bankName").get_to(o.bankName); } - j.at("paymentType").get_to(o.paymentType); - j.at("accountNumber").get_to(o.accountNumber); - j.at("bankName").get_to(o.bankName); -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Company.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Company.h index b93392452b23..5ac52aa4f92f 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Company.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Company.h @@ -35,35 +35,35 @@ class Company void setMetadata(const std::map& metadata); -friend void to_json(nlohmann::json& j, const Company& o) -{ - j = nlohmann::json::object(); - j["name"] = o.name; - j["headquarters"] = o.headquarters; - j["departments"] = o.departments; - j["metadata"] = o.metadata; -} - -friend void from_json(const nlohmann::json& j, Company& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "Company must be a JSON object", &j); - } - j.at("name").get_to(o.name); - if (j.contains("headquarters")) + friend inline void to_json(nlohmann::json& j, const Company& o) { - j.at("headquarters").get_to(o.headquarters); + j = nlohmann::json::object(); + j["name"] = o.name; + j["headquarters"] = o.headquarters; + j["departments"] = o.departments; + j["metadata"] = o.metadata; } - if (j.contains("departments")) - { - j.at("departments").get_to(o.departments); - } - if (j.contains("metadata")) + + friend inline void from_json(const nlohmann::json& j, Company& o) { - j.at("metadata").get_to(o.metadata); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Company must be a JSON object", &j); + } + j.at("name").get_to(o.name); + if (j.contains("headquarters")) + { + j.at("headquarters").get_to(o.headquarters); + } + if (j.contains("departments")) + { + j.at("departments").get_to(o.departments); + } + if (j.contains("metadata")) + { + j.at("metadata").get_to(o.metadata); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/CreatedResponse.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/CreatedResponse.h index 20e9a00c52c5..261f728cbc47 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/CreatedResponse.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/CreatedResponse.h @@ -31,27 +31,27 @@ class CreatedResponse void setLocation(const std::string& location); -friend void to_json(nlohmann::json& j, const CreatedResponse& o) -{ - j = nlohmann::json::object(); - j["status"] = o.status; - j["id"] = o.id; - j["location"] = o.location; -} - -friend void from_json(const nlohmann::json& j, CreatedResponse& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const CreatedResponse& o) { - throw nlohmann::json::type_error::create(302, "CreatedResponse must be a JSON object", &j); + j = nlohmann::json::object(); + j["status"] = o.status; + j["id"] = o.id; + j["location"] = o.location; } - j.at("status").get_to(o.status); - j.at("id").get_to(o.id); - if (j.contains("location")) + + friend inline void from_json(const nlohmann::json& j, CreatedResponse& o) { - j.at("location").get_to(o.location); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "CreatedResponse must be a JSON object", &j); + } + j.at("status").get_to(o.status); + j.at("id").get_to(o.id); + if (j.contains("location")) + { + j.at("location").get_to(o.location); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/CreditCard.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/CreditCard.h index ac3402ea4951..e023ae841438 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/CreditCard.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/CreditCard.h @@ -53,24 +53,24 @@ class CreditCard -friend void to_json(nlohmann::json& j, const CreditCard& o) -{ - j = nlohmann::json::object(); - j["paymentType"] = o.paymentType; - j["cardNumber"] = o.cardNumber; - j["cardType"] = o.cardType; -} + friend inline void to_json(nlohmann::json& j, const CreditCard& o) + { + j = nlohmann::json::object(); + j["paymentType"] = o.paymentType; + j["cardNumber"] = o.cardNumber; + j["cardType"] = o.cardType; + } -friend void from_json(const nlohmann::json& j, CreditCard& o) -{ - if (!j.is_object()) + friend inline void from_json(const nlohmann::json& j, CreditCard& o) { - throw nlohmann::json::type_error::create(302, "CreditCard must be a JSON object", &j); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "CreditCard must be a JSON object", &j); + } + j.at("paymentType").get_to(o.paymentType); + j.at("cardNumber").get_to(o.cardNumber); + j.at("cardType").get_to(o.cardType); } - j.at("paymentType").get_to(o.paymentType); - j.at("cardNumber").get_to(o.cardNumber); - j.at("cardType").get_to(o.cardType); -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Department.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Department.h index 8db2176061c1..86888b3fd38f 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Department.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Department.h @@ -32,27 +32,27 @@ class Department void setEmployees(const std::vector& employees); -friend void to_json(nlohmann::json& j, const Department& o) -{ - j = nlohmann::json::object(); - j["name"] = o.name; - j["manager"] = o.manager; - j["employees"] = o.employees; -} - -friend void from_json(const nlohmann::json& j, Department& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Department& o) { - throw nlohmann::json::type_error::create(302, "Department must be a JSON object", &j); + j = nlohmann::json::object(); + j["name"] = o.name; + j["manager"] = o.manager; + j["employees"] = o.employees; } - j.at("name").get_to(o.name); - j.at("manager").get_to(o.manager); - if (j.contains("employees")) + + friend inline void from_json(const nlohmann::json& j, Department& o) { - j.at("employees").get_to(o.employees); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Department must be a JSON object", &j); + } + j.at("name").get_to(o.name); + j.at("manager").get_to(o.manager); + if (j.contains("employees")) + { + j.at("employees").get_to(o.employees); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Dog.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Dog.h index e61ed4c9a2fd..83906c802c4d 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Dog.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Dog.h @@ -31,28 +31,28 @@ class Dog : public Animal void setBarkVolume(const int& barkVolume); -friend void to_json(nlohmann::json& j, const Dog& o) -{ - // Serialize inherited properties via the parent's serializer - to_json(j, static_cast(o)); - j["breed"] = o.breed; - j["barkVolume"] = o.barkVolume; -} - -friend void from_json(const nlohmann::json& j, Dog& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Dog& o) { - throw nlohmann::json::type_error::create(302, "Dog must be a JSON object", &j); + // Serialize inherited properties via the parent's serializer + to_json(j, static_cast(o)); + j["breed"] = o.breed; + j["barkVolume"] = o.barkVolume; } - // Deserialize inherited properties via the parent's deserializer - from_json(j, static_cast(o)); - j.at("breed").get_to(o.breed); - if (j.contains("barkVolume")) + + friend inline void from_json(const nlohmann::json& j, Dog& o) { - j.at("barkVolume").get_to(o.barkVolume); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Dog must be a JSON object", &j); + } + // Deserialize inherited properties via the parent's deserializer + from_json(j, static_cast(o)); + j.at("breed").get_to(o.breed); + if (j.contains("barkVolume")) + { + j.at("barkVolume").get_to(o.barkVolume); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/Employee.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/Employee.h index 0411295f1d14..13b4d7cb2791 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/Employee.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/Employee.h @@ -37,34 +37,34 @@ class Employee void setSkills(const std::vector& skills); -friend void to_json(nlohmann::json& j, const Employee& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["name"] = o.name; - j["email"] = o.email; - j["address"] = o.address; - j["skills"] = o.skills; -} - -friend void from_json(const nlohmann::json& j, Employee& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Employee& o) { - throw nlohmann::json::type_error::create(302, "Employee must be a JSON object", &j); + j = nlohmann::json::object(); + j["id"] = o.id; + j["name"] = o.name; + j["email"] = o.email; + j["address"] = o.address; + j["skills"] = o.skills; } - j.at("id").get_to(o.id); - j.at("name").get_to(o.name); - j.at("email").get_to(o.email); - if (j.contains("address")) - { - j.at("address").get_to(o.address); - } - if (j.contains("skills")) + + friend inline void from_json(const nlohmann::json& j, Employee& o) { - j.at("skills").get_to(o.skills); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Employee must be a JSON object", &j); + } + j.at("id").get_to(o.id); + j.at("name").get_to(o.name); + j.at("email").get_to(o.email); + if (j.contains("address")) + { + j.at("address").get_to(o.address); + } + if (j.contains("skills")) + { + j.at("skills").get_to(o.skills); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/EnumTypes.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/EnumTypes.h index 484cb0d5b073..c00bc505597f 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/EnumTypes.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/EnumTypes.h @@ -156,33 +156,33 @@ class EnumTypes -friend void to_json(nlohmann::json& j, const EnumTypes& o) -{ - j = nlohmann::json::object(); - j["stringEnum"] = o.stringEnum; - j["numericEnum"] = o.numericEnum; - j["statusCode"] = o.statusCode; -} - -friend void from_json(const nlohmann::json& j, EnumTypes& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "EnumTypes must be a JSON object", &j); - } - if (j.contains("stringEnum")) - { - j.at("stringEnum").get_to(o.stringEnum); - } - if (j.contains("numericEnum")) + friend inline void to_json(nlohmann::json& j, const EnumTypes& o) { - j.at("numericEnum").get_to(o.numericEnum); + j = nlohmann::json::object(); + j["stringEnum"] = o.stringEnum; + j["numericEnum"] = o.numericEnum; + j["statusCode"] = o.statusCode; } - if (j.contains("statusCode")) + + friend inline void from_json(const nlohmann::json& j, EnumTypes& o) { - j.at("statusCode").get_to(o.statusCode); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "EnumTypes must be a JSON object", &j); + } + if (j.contains("stringEnum")) + { + j.at("stringEnum").get_to(o.stringEnum); + } + if (j.contains("numericEnum")) + { + j.at("numericEnum").get_to(o.numericEnum); + } + if (j.contains("statusCode")) + { + j.at("statusCode").get_to(o.statusCode); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/ErrorResponse.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/ErrorResponse.h index 86034b300594..cd4a72d9ba03 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/ErrorResponse.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/ErrorResponse.h @@ -32,30 +32,30 @@ class ErrorResponse void setDetails(const std::vector& details); -friend void to_json(nlohmann::json& j, const ErrorResponse& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; - j["code"] = o.code; - j["details"] = o.details; -} - -friend void from_json(const nlohmann::json& j, ErrorResponse& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const ErrorResponse& o) { - throw nlohmann::json::type_error::create(302, "ErrorResponse must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; + j["code"] = o.code; + j["details"] = o.details; } - j.at("message").get_to(o.message); - if (j.contains("code")) - { - j.at("code").get_to(o.code); - } - if (j.contains("details")) + + friend inline void from_json(const nlohmann::json& j, ErrorResponse& o) { - j.at("details").get_to(o.details); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "ErrorResponse must be a JSON object", &j); + } + j.at("message").get_to(o.message); + if (j.contains("code")) + { + j.at("code").get_to(o.code); + } + if (j.contains("details")) + { + j.at("details").get_to(o.details); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/NotFoundResponse.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/NotFoundResponse.h index 0c964f595d0c..2e96624c73fd 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/NotFoundResponse.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/NotFoundResponse.h @@ -28,25 +28,25 @@ class NotFoundResponse void setResource(const std::string& resource); -friend void to_json(nlohmann::json& j, const NotFoundResponse& o) -{ - j = nlohmann::json::object(); - j["error"] = o.error; - j["resource"] = o.resource; -} - -friend void from_json(const nlohmann::json& j, NotFoundResponse& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const NotFoundResponse& o) { - throw nlohmann::json::type_error::create(302, "NotFoundResponse must be a JSON object", &j); + j = nlohmann::json::object(); + j["error"] = o.error; + j["resource"] = o.resource; } - j.at("error").get_to(o.error); - if (j.contains("resource")) + + friend inline void from_json(const nlohmann::json& j, NotFoundResponse& o) { - j.at("resource").get_to(o.resource); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "NotFoundResponse must be a JSON object", &j); + } + j.at("error").get_to(o.error); + if (j.contains("resource")) + { + j.at("resource").get_to(o.resource); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/NullableOptionalTypes.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/NullableOptionalTypes.h index cc32943a4f09..52457f725d75 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/NullableOptionalTypes.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/NullableOptionalTypes.h @@ -36,40 +36,40 @@ class NullableOptionalTypes void setFieldWithDefault(const int& fieldWithDefault); -friend void to_json(nlohmann::json& j, const NullableOptionalTypes& o) -{ - j = nlohmann::json::object(); - j["requiredField"] = o.requiredField; - j["optionalField"] = o.optionalField; - j["nullableField"] = o.nullableField; - j["optionalNullableField"] = o.optionalNullableField; - j["fieldWithDefault"] = o.fieldWithDefault; -} - -friend void from_json(const nlohmann::json& j, NullableOptionalTypes& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const NullableOptionalTypes& o) { - throw nlohmann::json::type_error::create(302, "NullableOptionalTypes must be a JSON object", &j); + j = nlohmann::json::object(); + j["requiredField"] = o.requiredField; + j["optionalField"] = o.optionalField; + j["nullableField"] = o.nullableField; + j["optionalNullableField"] = o.optionalNullableField; + j["fieldWithDefault"] = o.fieldWithDefault; } - j.at("requiredField").get_to(o.requiredField); - if (j.contains("optionalField")) - { - j.at("optionalField").get_to(o.optionalField); - } - if (j.contains("nullableField") && !j.at("nullableField").is_null()) - { - j.at("nullableField").get_to(o.nullableField); - } - if (j.contains("optionalNullableField") && !j.at("optionalNullableField").is_null()) - { - j.at("optionalNullableField").get_to(o.optionalNullableField); - } - if (j.contains("fieldWithDefault")) + + friend inline void from_json(const nlohmann::json& j, NullableOptionalTypes& o) { - j.at("fieldWithDefault").get_to(o.fieldWithDefault); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "NullableOptionalTypes must be a JSON object", &j); + } + j.at("requiredField").get_to(o.requiredField); + if (j.contains("optionalField")) + { + j.at("optionalField").get_to(o.optionalField); + } + if (j.contains("nullableField") && !j.at("nullableField").is_null()) + { + j.at("nullableField").get_to(o.nullableField); + } + if (j.contains("optionalNullableField") && !j.at("optionalNullableField").is_null()) + { + j.at("optionalNullableField").get_to(o.optionalNullableField); + } + if (j.contains("fieldWithDefault")) + { + j.at("fieldWithDefault").get_to(o.fieldWithDefault); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/PrimitiveTypes.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/PrimitiveTypes.h index 81efc5f5832d..6150bb6a3f16 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/PrimitiveTypes.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/PrimitiveTypes.h @@ -47,64 +47,64 @@ class PrimitiveTypes void setPasswordField(const std::string& passwordField); -friend void to_json(nlohmann::json& j, const PrimitiveTypes& o) -{ - j = nlohmann::json::object(); - j["stringField"] = o.stringField; - j["intField"] = o.intField; - j["longField"] = o.longField; - j["floatField"] = o.floatField; - j["doubleField"] = o.doubleField; - j["boolField"] = o.boolField; - j["byteField"] = o.byteField; - j["binaryField"] = o.binaryField; - j["dateField"] = o.dateField; - j["dateTimeField"] = o.dateTimeField; - j["passwordField"] = o.passwordField; -} - -friend void from_json(const nlohmann::json& j, PrimitiveTypes& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const PrimitiveTypes& o) { - throw nlohmann::json::type_error::create(302, "PrimitiveTypes must be a JSON object", &j); + j = nlohmann::json::object(); + j["stringField"] = o.stringField; + j["intField"] = o.intField; + j["longField"] = o.longField; + j["floatField"] = o.floatField; + j["doubleField"] = o.doubleField; + j["boolField"] = o.boolField; + j["byteField"] = o.byteField; + j["binaryField"] = o.binaryField; + j["dateField"] = o.dateField; + j["dateTimeField"] = o.dateTimeField; + j["passwordField"] = o.passwordField; } - j.at("stringField").get_to(o.stringField); - j.at("intField").get_to(o.intField); - if (j.contains("longField")) - { - j.at("longField").get_to(o.longField); - } - if (j.contains("floatField")) - { - j.at("floatField").get_to(o.floatField); - } - if (j.contains("doubleField")) - { - j.at("doubleField").get_to(o.doubleField); - } - j.at("boolField").get_to(o.boolField); - if (j.contains("byteField")) - { - j.at("byteField").get_to(o.byteField); - } - if (j.contains("binaryField")) - { - j.at("binaryField").get_to(o.binaryField); - } - if (j.contains("dateField")) - { - j.at("dateField").get_to(o.dateField); - } - if (j.contains("dateTimeField")) - { - j.at("dateTimeField").get_to(o.dateTimeField); - } - if (j.contains("passwordField")) + + friend inline void from_json(const nlohmann::json& j, PrimitiveTypes& o) { - j.at("passwordField").get_to(o.passwordField); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "PrimitiveTypes must be a JSON object", &j); + } + j.at("stringField").get_to(o.stringField); + j.at("intField").get_to(o.intField); + if (j.contains("longField")) + { + j.at("longField").get_to(o.longField); + } + if (j.contains("floatField")) + { + j.at("floatField").get_to(o.floatField); + } + if (j.contains("doubleField")) + { + j.at("doubleField").get_to(o.doubleField); + } + j.at("boolField").get_to(o.boolField); + if (j.contains("byteField")) + { + j.at("byteField").get_to(o.byteField); + } + if (j.contains("binaryField")) + { + j.at("binaryField").get_to(o.binaryField); + } + if (j.contains("dateField")) + { + j.at("dateField").get_to(o.dateField); + } + if (j.contains("dateTimeField")) + { + j.at("dateTimeField").get_to(o.dateTimeField); + } + if (j.contains("passwordField")) + { + j.at("passwordField").get_to(o.passwordField); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/SimpleObject.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/SimpleObject.h index a9db63bc637c..2d1f4c104403 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/SimpleObject.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/SimpleObject.h @@ -31,27 +31,27 @@ class SimpleObject void setDescription(const std::string& description); -friend void to_json(nlohmann::json& j, const SimpleObject& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["name"] = o.name; - j["description"] = o.description; -} - -friend void from_json(const nlohmann::json& j, SimpleObject& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const SimpleObject& o) { - throw nlohmann::json::type_error::create(302, "SimpleObject must be a JSON object", &j); + j = nlohmann::json::object(); + j["id"] = o.id; + j["name"] = o.name; + j["description"] = o.description; } - j.at("id").get_to(o.id); - j.at("name").get_to(o.name); - if (j.contains("description")) + + friend inline void from_json(const nlohmann::json& j, SimpleObject& o) { - j.at("description").get_to(o.description); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "SimpleObject must be a JSON object", &j); + } + j.at("id").get_to(o.id); + j.at("name").get_to(o.name); + if (j.contains("description")) + { + j.at("description").get_to(o.description); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/SuccessResponse.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/SuccessResponse.h index ec53ecf4db3b..a569ef69f680 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/SuccessResponse.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/SuccessResponse.h @@ -28,22 +28,22 @@ class SuccessResponse void setData(const nlohmann::json& data); -friend void to_json(nlohmann::json& j, const SuccessResponse& o) -{ - j = nlohmann::json::object(); - j["status"] = o.status; - j["data"] = o.data; -} + friend inline void to_json(nlohmann::json& j, const SuccessResponse& o) + { + j = nlohmann::json::object(); + j["status"] = o.status; + j["data"] = o.data; + } -friend void from_json(const nlohmann::json& j, SuccessResponse& o) -{ - if (!j.is_object()) + friend inline void from_json(const nlohmann::json& j, SuccessResponse& o) { - throw nlohmann::json::type_error::create(302, "SuccessResponse must be a JSON object", &j); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "SuccessResponse must be a JSON object", &j); + } + j.at("status").get_to(o.status); + j.at("data").get_to(o.data); } - j.at("status").get_to(o.status); - j.at("data").get_to(o.data); -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestAllParameterTypes200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestAllParameterTypes200Response.h index eebe38029a30..b5386b6dc2a0 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestAllParameterTypes200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestAllParameterTypes200Response.h @@ -33,38 +33,38 @@ class TestAllParameterTypes200Response void setCorrelationId(const std::string& correlationId); -friend void to_json(nlohmann::json& j, const TestAllParameterTypes200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; - j["resourceId"] = o.resourceId; - j["filter"] = o.filter; - j["correlationId"] = o.correlationId; -} - -friend void from_json(const nlohmann::json& j, TestAllParameterTypes200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestAllParameterTypes200Response& o) { - throw nlohmann::json::type_error::create(302, "TestAllParameterTypes200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; + j["resourceId"] = o.resourceId; + j["filter"] = o.filter; + j["correlationId"] = o.correlationId; } - if (j.contains("message")) - { - j.at("message").get_to(o.message); - } - if (j.contains("resourceId")) - { - j.at("resourceId").get_to(o.resourceId); - } - if (j.contains("filter")) - { - j.at("filter").get_to(o.filter); - } - if (j.contains("correlationId")) + + friend inline void from_json(const nlohmann::json& j, TestAllParameterTypes200Response& o) { - j.at("correlationId").get_to(o.correlationId); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestAllParameterTypes200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } + if (j.contains("resourceId")) + { + j.at("resourceId").get_to(o.resourceId); + } + if (j.contains("filter")) + { + j.at("filter").get_to(o.filter); + } + if (j.contains("correlationId")) + { + j.at("correlationId").get_to(o.correlationId); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestApiKeySecurity200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestApiKeySecurity200Response.h index 9315589e4aae..019d2f6c28cd 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestApiKeySecurity200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestApiKeySecurity200Response.h @@ -26,23 +26,23 @@ class TestApiKeySecurity200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestApiKeySecurity200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestApiKeySecurity200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestApiKeySecurity200Response& o) { - throw nlohmann::json::type_error::create(302, "TestApiKeySecurity200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestApiKeySecurity200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestApiKeySecurity200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBasicSecurity200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBasicSecurity200Response.h index ed362c3948dd..77f7d9f8c10c 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBasicSecurity200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBasicSecurity200Response.h @@ -26,23 +26,23 @@ class TestBasicSecurity200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestBasicSecurity200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestBasicSecurity200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestBasicSecurity200Response& o) { - throw nlohmann::json::type_error::create(302, "TestBasicSecurity200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestBasicSecurity200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestBasicSecurity200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBearerSecurity200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBearerSecurity200Response.h index b09fd74022c5..e1c42693741d 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBearerSecurity200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestBearerSecurity200Response.h @@ -26,23 +26,23 @@ class TestBearerSecurity200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestBearerSecurity200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestBearerSecurity200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestBearerSecurity200Response& o) { - throw nlohmann::json::type_error::create(302, "TestBearerSecurity200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestBearerSecurity200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestBearerSecurity200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestCookieParameters200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestCookieParameters200Response.h index 5762cdcc64a1..3550a89959d2 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestCookieParameters200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestCookieParameters200Response.h @@ -26,23 +26,23 @@ class TestCookieParameters200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestCookieParameters200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestCookieParameters200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestCookieParameters200Response& o) { - throw nlohmann::json::type_error::create(302, "TestCookieParameters200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestCookieParameters200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestCookieParameters200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters200Response.h index 2ee28ba3b7ad..977a69d687b4 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters200Response.h @@ -26,23 +26,23 @@ class TestHeaderParameters200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestHeaderParameters200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestHeaderParameters200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestHeaderParameters200Response& o) { - throw nlohmann::json::type_error::create(302, "TestHeaderParameters200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestHeaderParameters200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestHeaderParameters200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters401Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters401Response.h index be045c60621c..b1b701ff4fda 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters401Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestHeaderParameters401Response.h @@ -26,23 +26,23 @@ class TestHeaderParameters401Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestHeaderParameters401Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestHeaderParameters401Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestHeaderParameters401Response& o) { - throw nlohmann::json::type_error::create(302, "TestHeaderParameters401Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestHeaderParameters401Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestHeaderParameters401Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestOAuth2Security200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestOAuth2Security200Response.h index ddced1386ca3..8410e3298da1 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestOAuth2Security200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestOAuth2Security200Response.h @@ -26,23 +26,23 @@ class TestOAuth2Security200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestOAuth2Security200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestOAuth2Security200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestOAuth2Security200Response& o) { - throw nlohmann::json::type_error::create(302, "TestOAuth2Security200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestOAuth2Security200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestOAuth2Security200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParameters200Response.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParameters200Response.h index 615cd475415f..d8af0e98c824 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParameters200Response.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParameters200Response.h @@ -26,23 +26,23 @@ class TestQueryParameters200Response void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const TestQueryParameters200Response& o) -{ - j = nlohmann::json::object(); - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, TestQueryParameters200Response& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestQueryParameters200Response& o) { - throw nlohmann::json::type_error::create(302, "TestQueryParameters200Response must be a JSON object", &j); + j = nlohmann::json::object(); + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, TestQueryParameters200Response& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestQueryParameters200Response must be a JSON object", &j); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParametersDeepObjectParameter.h b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParametersDeepObjectParameter.h index c35398a3fb67..bb2f57aec084 100644 --- a/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParametersDeepObjectParameter.h +++ b/samples/server/petstore/cpp-httplib-server/feature-test/models/TestQueryParametersDeepObjectParameter.h @@ -29,28 +29,28 @@ class TestQueryParametersDeepObjectParameter void setAge(const int& age); -friend void to_json(nlohmann::json& j, const TestQueryParametersDeepObjectParameter& o) -{ - j = nlohmann::json::object(); - j["name"] = o.name; - j["age"] = o.age; -} - -friend void from_json(const nlohmann::json& j, TestQueryParametersDeepObjectParameter& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const TestQueryParametersDeepObjectParameter& o) { - throw nlohmann::json::type_error::create(302, "TestQueryParametersDeepObjectParameter must be a JSON object", &j); + j = nlohmann::json::object(); + j["name"] = o.name; + j["age"] = o.age; } - if (j.contains("name")) - { - j.at("name").get_to(o.name); - } - if (j.contains("age")) + + friend inline void from_json(const nlohmann::json& j, TestQueryParametersDeepObjectParameter& o) { - j.at("age").get_to(o.age); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "TestQueryParametersDeepObjectParameter must be a JSON object", &j); + } + if (j.contains("name")) + { + j.at("name").get_to(o.name); + } + if (j.contains("age")) + { + j.at("age").get_to(o.age); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/ApiResponse.h b/samples/server/petstore/cpp-httplib-server/petstore/models/ApiResponse.h index 154da98ef4ad..562491147ae9 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/ApiResponse.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/ApiResponse.h @@ -31,33 +31,33 @@ class ApiResponse void setMessage(const std::string& message); -friend void to_json(nlohmann::json& j, const ApiResponse& o) -{ - j = nlohmann::json::object(); - j["code"] = o.code; - j["type"] = o.type; - j["message"] = o.message; -} - -friend void from_json(const nlohmann::json& j, ApiResponse& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "ApiResponse must be a JSON object", &j); - } - if (j.contains("code")) - { - j.at("code").get_to(o.code); - } - if (j.contains("type")) + friend inline void to_json(nlohmann::json& j, const ApiResponse& o) { - j.at("type").get_to(o.type); + j = nlohmann::json::object(); + j["code"] = o.code; + j["type"] = o.type; + j["message"] = o.message; } - if (j.contains("message")) + + friend inline void from_json(const nlohmann::json& j, ApiResponse& o) { - j.at("message").get_to(o.message); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "ApiResponse must be a JSON object", &j); + } + if (j.contains("code")) + { + j.at("code").get_to(o.code); + } + if (j.contains("type")) + { + j.at("type").get_to(o.type); + } + if (j.contains("message")) + { + j.at("message").get_to(o.message); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/Category.h b/samples/server/petstore/cpp-httplib-server/petstore/models/Category.h index 46ce502b92bc..54c1549ebaea 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/Category.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/Category.h @@ -28,28 +28,28 @@ class Category void setName(const std::string& name); -friend void to_json(nlohmann::json& j, const Category& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["name"] = o.name; -} - -friend void from_json(const nlohmann::json& j, Category& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Category& o) { - throw nlohmann::json::type_error::create(302, "Category must be a JSON object", &j); + j = nlohmann::json::object(); + j["id"] = o.id; + j["name"] = o.name; } - if (j.contains("id")) - { - j.at("id").get_to(o.id); - } - if (j.contains("name")) + + friend inline void from_json(const nlohmann::json& j, Category& o) { - j.at("name").get_to(o.name); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Category must be a JSON object", &j); + } + if (j.contains("id")) + { + j.at("id").get_to(o.id); + } + if (j.contains("name")) + { + j.at("name").get_to(o.name); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/ComplexParamsResponse.h b/samples/server/petstore/cpp-httplib-server/petstore/models/ComplexParamsResponse.h index 052a35096767..7ae624ebcbe8 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/ComplexParamsResponse.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/ComplexParamsResponse.h @@ -147,48 +147,48 @@ class ComplexParamsResponse -friend void to_json(nlohmann::json& j, const ComplexParamsResponse& o) -{ - j = nlohmann::json::object(); - j["deepObj"] = o.deepObj; - j["enumParam"] = o.enumParam; - j["pipeArr"] = o.pipeArr; - j["spaceArr"] = o.spaceArr; - j["x-enum-header"] = o.xEnumHeader; - j["cookieEnum"] = o.cookieEnum; -} - -friend void from_json(const nlohmann::json& j, ComplexParamsResponse& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "ComplexParamsResponse must be a JSON object", &j); - } - if (j.contains("deepObj")) - { - j.at("deepObj").get_to(o.deepObj); - } - if (j.contains("enumParam")) - { - j.at("enumParam").get_to(o.enumParam); - } - if (j.contains("pipeArr")) - { - j.at("pipeArr").get_to(o.pipeArr); - } - if (j.contains("spaceArr")) + friend inline void to_json(nlohmann::json& j, const ComplexParamsResponse& o) { - j.at("spaceArr").get_to(o.spaceArr); + j = nlohmann::json::object(); + j["deepObj"] = o.deepObj; + j["enumParam"] = o.enumParam; + j["pipeArr"] = o.pipeArr; + j["spaceArr"] = o.spaceArr; + j["x-enum-header"] = o.xEnumHeader; + j["cookieEnum"] = o.cookieEnum; } - if (j.contains("x-enum-header")) - { - j.at("x-enum-header").get_to(o.xEnumHeader); - } - if (j.contains("cookieEnum")) + + friend inline void from_json(const nlohmann::json& j, ComplexParamsResponse& o) { - j.at("cookieEnum").get_to(o.cookieEnum); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "ComplexParamsResponse must be a JSON object", &j); + } + if (j.contains("deepObj")) + { + j.at("deepObj").get_to(o.deepObj); + } + if (j.contains("enumParam")) + { + j.at("enumParam").get_to(o.enumParam); + } + if (j.contains("pipeArr")) + { + j.at("pipeArr").get_to(o.pipeArr); + } + if (j.contains("spaceArr")) + { + j.at("spaceArr").get_to(o.spaceArr); + } + if (j.contains("x-enum-header")) + { + j.at("x-enum-header").get_to(o.xEnumHeader); + } + if (j.contains("cookieEnum")) + { + j.at("cookieEnum").get_to(o.cookieEnum); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObj.h b/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObj.h index fe8c78df1810..6ffb82d86c9a 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObj.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObj.h @@ -32,33 +32,33 @@ class DeepObj void setBaz(const DeepObjBaz& baz); -friend void to_json(nlohmann::json& j, const DeepObj& o) -{ - j = nlohmann::json::object(); - j["foo"] = o.foo; - j["bar"] = o.bar; - j["baz"] = o.baz; -} - -friend void from_json(const nlohmann::json& j, DeepObj& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "DeepObj must be a JSON object", &j); - } - if (j.contains("foo")) - { - j.at("foo").get_to(o.foo); - } - if (j.contains("bar")) + friend inline void to_json(nlohmann::json& j, const DeepObj& o) { - j.at("bar").get_to(o.bar); + j = nlohmann::json::object(); + j["foo"] = o.foo; + j["bar"] = o.bar; + j["baz"] = o.baz; } - if (j.contains("baz")) + + friend inline void from_json(const nlohmann::json& j, DeepObj& o) { - j.at("baz").get_to(o.baz); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "DeepObj must be a JSON object", &j); + } + if (j.contains("foo")) + { + j.at("foo").get_to(o.foo); + } + if (j.contains("bar")) + { + j.at("bar").get_to(o.bar); + } + if (j.contains("baz")) + { + j.at("baz").get_to(o.baz); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObjBaz.h b/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObjBaz.h index 6ccdcc6bd3e7..ca22a293e8a5 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObjBaz.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/DeepObjBaz.h @@ -29,28 +29,28 @@ class DeepObjBaz void setY(const int& Y); -friend void to_json(nlohmann::json& j, const DeepObjBaz& o) -{ - j = nlohmann::json::object(); - j["x"] = o.X; - j["y"] = o.Y; -} - -friend void from_json(const nlohmann::json& j, DeepObjBaz& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const DeepObjBaz& o) { - throw nlohmann::json::type_error::create(302, "DeepObjBaz must be a JSON object", &j); + j = nlohmann::json::object(); + j["x"] = o.X; + j["y"] = o.Y; } - if (j.contains("x")) - { - j.at("x").get_to(o.X); - } - if (j.contains("y")) + + friend inline void from_json(const nlohmann::json& j, DeepObjBaz& o) { - j.at("y").get_to(o.Y); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "DeepObjBaz must be a JSON object", &j); + } + if (j.contains("x")) + { + j.at("x").get_to(o.X); + } + if (j.contains("y")) + { + j.at("y").get_to(o.Y); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/NullableExample.h b/samples/server/petstore/cpp-httplib-server/petstore/models/NullableExample.h index 39e3223e9476..0548f2d29549 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/NullableExample.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/NullableExample.h @@ -27,23 +27,23 @@ class NullableExample void setMaybeString(const std::string& maybeString); -friend void to_json(nlohmann::json& j, const NullableExample& o) -{ - j = nlohmann::json::object(); - j["maybeString"] = o.maybeString; -} - -friend void from_json(const nlohmann::json& j, NullableExample& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const NullableExample& o) { - throw nlohmann::json::type_error::create(302, "NullableExample must be a JSON object", &j); + j = nlohmann::json::object(); + j["maybeString"] = o.maybeString; } - if (j.contains("maybeString") && !j.at("maybeString").is_null()) + + friend inline void from_json(const nlohmann::json& j, NullableExample& o) { - j.at("maybeString").get_to(o.maybeString); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "NullableExample must be a JSON object", &j); + } + if (j.contains("maybeString") && !j.at("maybeString").is_null()) + { + j.at("maybeString").get_to(o.maybeString); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/Order.h b/samples/server/petstore/cpp-httplib-server/petstore/models/Order.h index 3dcc7a5ab735..2db4dcd2c428 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/Order.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/Order.h @@ -74,48 +74,48 @@ class Order -friend void to_json(nlohmann::json& j, const Order& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["petId"] = o.petId; - j["quantity"] = o.quantity; - j["shipDate"] = o.shipDate; - j["status"] = o.status; - j["complete"] = o.complete; -} - -friend void from_json(const nlohmann::json& j, Order& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "Order must be a JSON object", &j); - } - if (j.contains("id")) - { - j.at("id").get_to(o.id); - } - if (j.contains("petId")) - { - j.at("petId").get_to(o.petId); - } - if (j.contains("quantity")) - { - j.at("quantity").get_to(o.quantity); - } - if (j.contains("shipDate")) + friend inline void to_json(nlohmann::json& j, const Order& o) { - j.at("shipDate").get_to(o.shipDate); + j = nlohmann::json::object(); + j["id"] = o.id; + j["petId"] = o.petId; + j["quantity"] = o.quantity; + j["shipDate"] = o.shipDate; + j["status"] = o.status; + j["complete"] = o.complete; } - if (j.contains("status")) - { - j.at("status").get_to(o.status); - } - if (j.contains("complete")) + + friend inline void from_json(const nlohmann::json& j, Order& o) { - j.at("complete").get_to(o.complete); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Order must be a JSON object", &j); + } + if (j.contains("id")) + { + j.at("id").get_to(o.id); + } + if (j.contains("petId")) + { + j.at("petId").get_to(o.petId); + } + if (j.contains("quantity")) + { + j.at("quantity").get_to(o.quantity); + } + if (j.contains("shipDate")) + { + j.at("shipDate").get_to(o.shipDate); + } + if (j.contains("status")) + { + j.at("status").get_to(o.status); + } + if (j.contains("complete")) + { + j.at("complete").get_to(o.complete); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/Pet.h b/samples/server/petstore/cpp-httplib-server/petstore/models/Pet.h index f00d45db5dfd..e6fbc5933cee 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/Pet.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/Pet.h @@ -76,42 +76,42 @@ class Pet -friend void to_json(nlohmann::json& j, const Pet& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["name"] = o.name; - j["photoUrls"] = o.photoUrls; - j["status"] = o.status; - j["category"] = o.category; - j["tags"] = o.tags; -} - -friend void from_json(const nlohmann::json& j, Pet& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "Pet must be a JSON object", &j); - } - if (j.contains("id")) - { - j.at("id").get_to(o.id); - } - j.at("name").get_to(o.name); - j.at("photoUrls").get_to(o.photoUrls); - if (j.contains("status")) - { - j.at("status").get_to(o.status); - } - if (j.contains("category")) + friend inline void to_json(nlohmann::json& j, const Pet& o) { - j.at("category").get_to(o.category); + j = nlohmann::json::object(); + j["id"] = o.id; + j["name"] = o.name; + j["photoUrls"] = o.photoUrls; + j["status"] = o.status; + j["category"] = o.category; + j["tags"] = o.tags; } - if (j.contains("tags")) + + friend inline void from_json(const nlohmann::json& j, Pet& o) { - j.at("tags").get_to(o.tags); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Pet must be a JSON object", &j); + } + if (j.contains("id")) + { + j.at("id").get_to(o.id); + } + j.at("name").get_to(o.name); + j.at("photoUrls").get_to(o.photoUrls); + if (j.contains("status")) + { + j.at("status").get_to(o.status); + } + if (j.contains("category")) + { + j.at("category").get_to(o.category); + } + if (j.contains("tags")) + { + j.at("tags").get_to(o.tags); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/Tag.h b/samples/server/petstore/cpp-httplib-server/petstore/models/Tag.h index d2447f0a74e0..e8d59bf7ecfe 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/Tag.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/Tag.h @@ -28,28 +28,28 @@ class Tag void setName(const std::string& name); -friend void to_json(nlohmann::json& j, const Tag& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["name"] = o.name; -} - -friend void from_json(const nlohmann::json& j, Tag& o) -{ - if (!j.is_object()) + friend inline void to_json(nlohmann::json& j, const Tag& o) { - throw nlohmann::json::type_error::create(302, "Tag must be a JSON object", &j); + j = nlohmann::json::object(); + j["id"] = o.id; + j["name"] = o.name; } - if (j.contains("id")) - { - j.at("id").get_to(o.id); - } - if (j.contains("name")) + + friend inline void from_json(const nlohmann::json& j, Tag& o) { - j.at("name").get_to(o.name); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "Tag must be a JSON object", &j); + } + if (j.contains("id")) + { + j.at("id").get_to(o.id); + } + if (j.contains("name")) + { + j.at("name").get_to(o.name); + } } -} private: diff --git a/samples/server/petstore/cpp-httplib-server/petstore/models/User.h b/samples/server/petstore/cpp-httplib-server/petstore/models/User.h index 85de226490d8..9d639f0a0a81 100644 --- a/samples/server/petstore/cpp-httplib-server/petstore/models/User.h +++ b/samples/server/petstore/cpp-httplib-server/petstore/models/User.h @@ -78,58 +78,58 @@ class User -friend void to_json(nlohmann::json& j, const User& o) -{ - j = nlohmann::json::object(); - j["id"] = o.id; - j["username"] = o.username; - j["firstName"] = o.firstName; - j["lastName"] = o.lastName; - j["email"] = o.email; - j["password"] = o.password; - j["phone"] = o.phone; - j["userStatus"] = o.userStatus; -} - -friend void from_json(const nlohmann::json& j, User& o) -{ - if (!j.is_object()) - { - throw nlohmann::json::type_error::create(302, "User must be a JSON object", &j); - } - if (j.contains("id")) - { - j.at("id").get_to(o.id); - } - if (j.contains("username")) - { - j.at("username").get_to(o.username); - } - if (j.contains("firstName")) - { - j.at("firstName").get_to(o.firstName); - } - if (j.contains("lastName")) - { - j.at("lastName").get_to(o.lastName); - } - if (j.contains("email")) - { - j.at("email").get_to(o.email); - } - if (j.contains("password")) + friend inline void to_json(nlohmann::json& j, const User& o) { - j.at("password").get_to(o.password); + j = nlohmann::json::object(); + j["id"] = o.id; + j["username"] = o.username; + j["firstName"] = o.firstName; + j["lastName"] = o.lastName; + j["email"] = o.email; + j["password"] = o.password; + j["phone"] = o.phone; + j["userStatus"] = o.userStatus; } - if (j.contains("phone")) - { - j.at("phone").get_to(o.phone); - } - if (j.contains("userStatus")) + + friend inline void from_json(const nlohmann::json& j, User& o) { - j.at("userStatus").get_to(o.userStatus); + if (!j.is_object()) + { + throw nlohmann::json::type_error::create(302, "User must be a JSON object", &j); + } + if (j.contains("id")) + { + j.at("id").get_to(o.id); + } + if (j.contains("username")) + { + j.at("username").get_to(o.username); + } + if (j.contains("firstName")) + { + j.at("firstName").get_to(o.firstName); + } + if (j.contains("lastName")) + { + j.at("lastName").get_to(o.lastName); + } + if (j.contains("email")) + { + j.at("email").get_to(o.email); + } + if (j.contains("password")) + { + j.at("password").get_to(o.password); + } + if (j.contains("phone")) + { + j.at("phone").get_to(o.phone); + } + if (j.contains("userStatus")) + { + j.at("userStatus").get_to(o.userStatus); + } } -} private: