Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    rrajpaul
    @rrajpaul
    Thanks for the suggestion, I was unaware of oatpp-mongocxxmapper. I will give it a go as I am really trying to improve my c++ skills. I have built web api using MS >net Core 2.1/2.2 and it is very easy with some experience but not at all easy in c++

    Again thanks for your help

    Ryan

    oat++
    @oatpp_io_twitter
    Cool, just try to make it work, and if you stuck - ping me, I'll be happy to help.
    Thomas Denoréaz
    @ThmX
    Hi everybody! Say I have a small question concerning the custom mapping: is there a way to use an enum for a field? If yes, is there an example out there? If not, do you have any pointers such that I can create an example and maybe add it to the documentation?
    oat++
    @oatpp_io_twitter
    Hello @ThmX ,
    Unums are not in the set of default available mapping-enabled types.
    So yes, you'll have to implement a custom ObjectMapper to support your enum type ...
    Thomas Denoréaz
    @ThmX
    Thanks for the fast answer! I'll do that then :) Is there any example of how to implement a custom ObjectMapper? The documentation told me to come here :'D
    oat++
    @oatpp_io_twitter
    The basic approach for creating custom ObjectMapper is:

    Create a type metadata

    #include "oatpp/core/Types.hpp"
    
    namespace myapp {
    
      typedef oatpp::data::mapping::type::Type Type;
    
      namespace __class {
    
          class MyEnum {
          public:
            constexpr static const char* const CLASS_NAME = "myapp::MyEnum";
    
            static Type* getType(){
              static Type type(CLASS_NAME, nullptr);
              return &type;
            }
    
          };
    
      }
    
    }

    Is there any example of how to implement a custom ObjectMapper? The documentation told me to come here :'D

    Yep, you are in the right place - just give me a few minutes to prepare code-snippets :)

    oat++
    @oatpp_io_twitter

    Declare the ObjectWrapper for your type:

    enum MyEnumType : int {
      a = 1,
      b = 2
    };
    
    typedef oatpp::data::mapping::type::ObjectWrapper<MyEnumType, __class::MyEnum> MyMappingEnabledEnum;
    Thomas Denoréaz
    @ThmX
    Hmm forgot to add: the use case is to use it with oatpp-swagger, would that work or should I also write some kind of "swagger spec generator" for this type?
    oat++
    @oatpp_io_twitter

    Reference your type in the Serializer/Deserializer

    void Serializer::writeField(oatpp::data::stream::OutputStream* stream, const AbstractObjectWrapper& polymorph) {
    
      const Type* type = polymorph.valueType;
    
      if(type->name == myapp::__class::MyEnum::CLASS_NAME) {
        // TODO serialize enum to stream
      }  else {
        throw std::runtime_error("Unknown data type");
      }
    
    }

    Hmm forgot to add: the use case is to use it with oatpp-swagger, would that work or should I also write some kind of "swagger spec generator" for this type?

    You'll have to add your custom functionality to swagger

    Thomas Denoréaz
    @ThmX
    Great! Thanks a lot!! :)
    oat++
    @oatpp_io_twitter
    You are welcome!
    And here is where types are referenced in swagger https://github.com/oatpp/oatpp-swagger/blob/master/src/oatpp-swagger/oas3/Generator.cpp#L73
    Please let me know if you have more questions
    oat++
    @oatpp_io_twitter

    Hey @/all ,
    Update :bell:

    The new oatpp/oatpp#182 was merged to master - providing support for Content-Encoding and Accept-Encoding headers.

    Also oatpp-zlib module is now available.

    The API

    In order to add encoders/decoders available for your server, all you need to do is to update AppComponents file. No changes need to be done to user-endpoints code.

    AppComponents.hpp

    #include "oatpp-zlib/EncoderProvider.hpp"
    
    ...
    
      OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, serverConnectionHandler)([] {
    
        OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // get Router component
    
        /* Create HttpProcessor::Components */
        auto components = std::make_shared<oatpp::web::server::HttpProcessor::Components>(router);
    
        /* Add content encoders */
        auto encoders = std::make_shared<oatpp::web::protocol::http::encoding::ProviderCollection>();
    
        encoders->add(std::make_shared<oatpp::zlib::DeflateEncoderProvider>());
        encoders->add(std::make_shared<oatpp::zlib::GzipEncoderProvider>());
    
        components->contentEncodingProviders = encoders;
    
        /* Add content decoders */
        auto decoders = std::make_shared<oatpp::web::protocol::http::encoding::ProviderCollection>();
    
        decoders->add(std::make_shared<oatpp::zlib::DeflateDecoderProvider>());
        decoders->add(std::make_shared<oatpp::zlib::GzipDecoderProvider>());
    
        components->bodyDecoder = std::make_shared<oatpp::web::protocol::http::incoming::SimpleBodyDecoder>(decoders);
    
        /* return HttpConnectionHandler */
        return std::make_shared<oatpp::web::server::HttpConnectionHandler>(components);
    
      }());
    
    ...

    Refs:


    Cheers :tada:
    Leonid

    Benedikt-Alexander Mokroß
    @bhorn
    Hey @rrajpaul have you tried the mapper? I haven't touched it in a while since Leonid and I decided to implement a more generic bson mapper (which then should be compatible with mongodb, too).
    Feel free to ask any questions since I still regard the mapper as work-in-progress and would be very happy to receive as much feedback as possible. We can learn from it to make an even better bson mapper in the future
    rrajpaul
    @rrajpaul
    I am still playing around with it. I got a bit busy with work but I will see if I can get the example using full rest api to work. I may have questions, I will reach out to you.
    oat++
    @oatpp_io_twitter

    Hey @/all ,
    Update :bell:

    The new shiny 1.0.0 version is now released - 1.0.0.

    In this release:

    • Configurable object mapping - now user can create own types and add support for these types in ApiController, ApiClient, json::mapping::ObjectMapper.
    • Predefined mapping-enabled unsigned integer types are added.
    • Full support for automatic content compression/decompression based on Accept-Encoding / Content-Encoding headers.
    • CMake. Options added to disable logs. OATPP_DISABLE_LOGV, OATPP_DISABLE_LOGD, OATPP_DISABLE_LOGI, OATPP_DISABLE_LOGW, OATPP_DISABLE_LOGE

    Cheers :tada:
    Leonid

    Alex Benedict
    @abenedic
    Hello, I am experimenting with this a bit for work. As part of that we need TLS support, but cannot use LibreSSL and must use OpenSSL or BoringSSL. How open would you be to having the oatpp-libressl module have configurable TLS support if there were a libTLS shim?
    oat++
    @oatpp_io_twitter

    Hello, @abenedic ,
    Thanks for the question!

    Well the TLS is something that can be easily substituted in oatpp with any other implementation.
    Currently, oatpp has two TLS adoptor module: oatpp-libressl and oatpp-mbedtls. But having more adaptors is a good idea - especially for BoringSSL.

    How open would you be to having the oatpp-libressl module have configurable TLS support if there were a libTLS shim?

    I think it will confuse a user - like which adaptor should be taken and how should I patch/tweak it to get libressl or openssl or desired tls version.

    On the other hand, it's pretty straight forward to create a new adaptor for BoringSSL and/or LibreSSL - there are already two examples. And I think the effort to create a new adaptor is comparable with the effort of creating libTLS shim and making oatpp-libressl configurable.
    oat++
    @oatpp_io_twitter
    So what I want propose is to create the BoringSSL adaptor for oatpp - I will provide all necessary assistance.
    And meanwhile, you can play with the framework using other adaptor. Once oatpp-boringssl is done - switch the adaptors.
    Alex Benedict
    @abenedic
    That sounds reasonable, I might be able to get something done by this weekend(unless some one is motivated). There isn't much work to be done to get that ready(based on the libressl version).
    oat++
    @oatpp_io_twitter
    Sounds great!
    I've created the oatpp-boringssl repository here - https://github.com/oatpp/oatpp-boringssl please feel free to fork it.
    Also later today I'll put some boilerplate code there if you not get started by that time.
    oat++
    @oatpp_io_twitter

    Hey @abenedic ,

    I took a closer look at BoringSSL - it seems to be very Google-specific and it's unclear to me what is the best way to include it in the module.

    So I think the better idea and less painful is to adapt OpenSSL
    The oatpp-openssl repo - https://github.com/oatpp/oatpp-openssl
    Alex Benedict
    @abenedic
    I just saw your message, I was just fiddling with getting it set up as a submodule and trying to get build files generated. It does seem like a big hassle to get it work in a cross platform way.
    I got most of the libressl specific cmake stuff configured to work with boringssl, so I will likely just copy over my work on that part already and just change the BoringSSL stuff to OpenSSL. Had a bit less time than I would have liked to work on it today, learned a bit more about CMake though which was nice.
    Alex Benedict
    @abenedic
    If a person installs it from the package manager then boringssl should look like openssl 1.1.0 though, so really the user could choose the backend by installing boringssl instead of openssl. As long as they don't change anything major from openssl as far as the TLS stuff goes it should be possible to support either with some minimal changes. One of the bigger issues is that boringssl return codes are different from in openssl.
    Alex Benedict
    @abenedic
    A decent amount of the logic in the libressl, mbedtls, and eventual openssl modules is similar, maybe in the future there may be some opportunity for refactoring this and maybe setting the TLS module at compile time when compiling oatpp. This would be my preference personally. I would like to have https by default when using the framework and have some choice at compile time, but I personally don't see much advantage to having it be a module decidable later.
    oat++
    @oatpp_io_twitter

    Hey, thanks for the update!
    It looks like we are in the opposite time-zones:)

    A decent amount of the logic in the libressl, mbedtls, and eventual openssl modules is similar, maybe in the future there may be some opportunity for refactoring this and maybe setting the TLS module at compile time when compiling oatpp.

    Having some kind of uber TLS module is definitely a good idea. Not sure about making it a part of core oatpp module though - oatpp by design works with streams. It doesn't care about where that stream comes from, is it TCP or Bluetooth or TLS over Bluetooth or whatever. You just take oatpp as a stream processor and plug any stream provider to it.
    But we'll see how things will work out in the future.

    Please keep me updated on the progress, and ping me if you have any questions!
    Alex Benedict
    @abenedic
    Yeah UTC-7 here. Sure that sounds sensible. I tend to have a bit of time in the morning(~8am locally) and around the end of day(~4pm) to work on open source projects. I have BoringSSL installed locally, so I was planning on just getting it to work first in the boringssl module and then use that as the base for the openssl module. I should have it currently at the point where I just need to change all the libTLS stuff to use the older interfaces from boringssl. I am planning on keeping the interfaces exactly the same so the current tests can be reused as much as possible, which should help with the "uber TLS" module later if you go that route.
    oat++
    @oatpp_io_twitter
    Hah and I am currently in utc+7 on my vacation :)
    Thats sounds great especially that you have experience with boringssl (as I dont have). It will be goot to have at least one tls module supporting tls1.3. So yeah it's a valuable effort!
    rrajpaul
    @rrajpaul
    @bhorn I have updated my local copy of oatpp-mongocxxmapper to compile against oatpp v1.0.0
    rrajpaul
    @rrajpaul
    @bhorn I tried to use the starter project with oatpp-mongocxxmapper but I felt that either progresql or the crud example would be better suited for the example.
    Benedikt-Alexander Mokroß
    @bhorn
    @rrajpaul nice that you got it running on 1.0.0, I wasn't able to bump it since my mongo-environment is gone and i had no time to set it up again. Could you fork the repository and create a pull-request to my repository? We could consider to make oatpp-mongocxxmapper an official module if enough data is aquired to prove its reliability. So we are really happy about any reports
    rrajpaul
    @rrajpaul
    @bhorn I am still working on the starter project - got it to compile and run but not insert data or get data etc. Once I get get, post, put and delete working I will do a pull request
    Benedikt-Alexander Mokroß
    @bhorn
    @rrajpaul nice! thank you.
    rrajpaul
    @rrajpaul
    @bhorn I am getting an error when trying to return a dto object from a bsoncxx::v_noabi::document using readFromDocument
    @bhorn

    @bhorn -- sample DTO
    // StyleDto.hpp
    // crud
    //
    // Created by Leonid on 3/13/18.
    // Modified by Ryan Rajpaul 01/31/2020
    // Copyright © 2018 oatpp. All rights reserved.
    //

    ifndef DTOs_hpp

    define DTOs_hpp

    include "oatpp/core/data/mapping/type/Object.hpp"

    include "oatpp/core/macro/codegen.hpp"

    include OATPP_CODEGEN_BEGIN(DTO)

    class StyleDto : public oatpp::data::mapping::type::Object {

    DTO_INIT(StyleDto, Object)

    DTO_FIELD(Int32, StyleId);
    DTO_FIELD(String, Manufacturer, "Manufacturer");
    DTO_FIELD(String, Brand, "Brand");
    DTO_FIELD(String, Category, "Category");
    DTO_FIELD(String, Type, "Type");
    DTO_FIELD(String, Description, "Description");

    };

    include OATPP_CODEGEN_END(DTO)

    endif / DTOs_hpp /

    @bhorn -- method below StyleDto::ObjectWrapper Database::getStyleById(v_int32 id){
    bsoncxx::stdx::optional<bsoncxx::v_noabi::document::value> result =
    m_db[COLLECTION_NAME].find_one({document{} << "StyleId" << id << finalize});

    auto docView = result->view();
    auto style = m_mongomapper->readFromDocument(docView);
    
    if(style) {
        OATPP_LOGD(TAG, "Found style with id %d", id);
    
        return style;
    }
    return style;

    }

    rrajpaul
    @rrajpaul

    @bhorn -- Method that will try to get a mongodb document by StyleId

    StyleDto::ObjectWrapper Database::getStyleById(v_int32 id){
    bsoncxx::stdx::optional<bsoncxx::v_noabi::document::value> result =
    m_db[COLLECTION_NAME].find_one({document{} << "StyleId" << id << finalize});

    auto docView = result->view();
    auto style = m_mongomapper->readFromDocument(docView);
    
    if(style) {
        OATPP_LOGD(TAG, "Found style with id %d", id);
    
        return style;
    }
    return style;

    }

    @bhorn sample json definition of a style document from style collection

    {
    "StyleId": NumberInt(4400),
    "Manufacturer": "Acme Inc",
    "Category": "Boys",
    "Type": "Footwear",
    "Description": "Running shoes"
    }