Comments (4)
I know that there is an implementation of traversing structures with names in boost pfr, but in my opinion it is not very good to lay on it because:
firstly it is tied to the intrinsics of compilers and can potentially break at any moment
secondly it does a lot of instantiations on one structure, it seems to me that it will potentially slow down a lot in a large project. What's the alternative? I have an implementation on NTTP, traits, templates, constexp function and lite macros(declare enum).
At the moment I have implemented basic arrays and restrictions on them, string and restrictions on them, structures, as well as the auto parse/serialize of handlers, auto-generation of openapi description from all this, wrote the necessary things for the postgres driver. Although my implementation is made solely out of interest and my own needs, but it seems to me that it can be considered. Formally, everything is covered by tests, it is really possible to approach this more thoroughly.
Example array with restriction and tests: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/json/parse/basic_array.cpp
Example of view:
Type in body: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/models/lesson_filter/type.hpp
Declaration request and response: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/views/timetable/declarations.hpp
View: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/views/timetable/view.cpp
The openapi scheme is generated at the start of the service based on the information from the config (since the endpoint type and its path are set there), and then it is given by /openapi. There is no difficulty for me to change this behavior. This behavior is tested here:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/doc/serialize/basic_path.cpp
I also want to add that now all the traits are implemented through types with static fields, but this caused problems if necessary to update them. I have a local version where all the traits have become Nttp, and the constexp strings have become fixed-size so that it is easier to work with them.
How do you look at such an implementation? I would be interested to at least hear an opinion.
P.s.Here I will leave different links to implementations of different pieces.
- implementation of abstract handler https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/http/handler.hpp
- test with body and header in response: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/http/basic_http_response.cpp
- test with body, cookie and header in request:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/http/basic_http_request.cpp - full complete impl enums:
macro to declare: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/enum/declare.hpp
enumerator func to pg:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/enum/enumerator_func.hpp
enum to OpenApi Doc:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/doc/enum.hpp - generate OpenApi doc in this folder:
https://github.com/sabudilovskiy/timetable_vsu_backend/tree/new_openapi/src/openapi/doc
For example, structures:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/doc/reflective.hpp - My structures can use additionalProperties: true,
examples:
serialize: https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/json/serialize/basic_object.cpp#L36
parse:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/utests/openapi/json/parse/basic_object.cpp#L59
openapi:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/doc/reflective.hpp - example of generated openapi schema by my server:
https://pastebin.com/9vpFZgES
This openapi generated from all OpenApiViews and settings in static config:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/configs/static_config.yaml.in#L101 - impl openapi::types::Array, it can use min, max and uniqueItems as restrictions and user can write it in any order:
https://github.com/sabudilovskiy/timetable_vsu_backend/blob/new_openapi/src/openapi/types/array.hpp
from userver.
@sabudilovskiy your approach is very interesting, but it is a totally different approach that requires explicit markup in code. We'll take a closer look, which approach suits our needs better
from userver.
@sabudilovskiy your approach is very interesting, but it is a totally different approach that requires explicit markup in code. We'll take a closer look, which approach suits our needs better
Initially, this was done based on the fact that there was no other way to provide names for the fields. However, now everything is different. I think it is possible to remove the markup in most cases, however restrictions on openapi, an explicit indication of where the field will be placed in the request (header/body/cookie) would be easiest to do this way. In the near future I want to use boost.pfr.name and standard types so that I don't have to markup anything in most cases (however markup is required in requests and responses). Or is there some other way for requests and responses?
from userver.
https://github.com/linuxnyasha/Serialization-userver_formats I wrote this. Could this be added to userver in the future? There's not much here yet, but it can all be added.
from userver.
Related Issues (20)
- BUG 2: MacOS arm64
- BUG: Turn off `USERVER_FEATURE_UBOOST_CORO` when install `userver`
- USERVER_FEATURE_PATCH_LIBPQ fails to build with Postgresql16 HOT 1
- Support minItems and maxItems array properties in static config
- SpscQueue race condition bug HOT 2
- Link static all
- Update mongo-c driver version
- Account for PATH in ProcessStarter::Exec
- Type mismatch for Postgres bit(N) type
- userver-2.0 package broken deps? (userver-all vs librdkavka-dev) HOT 1
- Get client's address in handler
- Pass open telemetry parent span-id through AMQP headers along with trace-id HOT 2
- Change urabbitmq::ConsumerComponentBase::Process signature so that it could receive at least headers and routing key HOT 3
- Add possibility to change or change accuracy for timings metrics
- Add support for server side SSL grpc verification (specifying SSL details in grpc client)
- Misspellings in project HOT 3
- Grpc client ssl is disabled by default even if auth-type: ssl used
- Cannot get ENV variables in config_vars.
- MAYBE BUG: `LOG` -> `USERVER_LOG`
- Replace `std::aligned_storage`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from userver.