Connexion create object instance - python-3.x

I am working on refactoring a flask app which uses connexion package for the RESTful API. Previously the code base was function based and I`m refactoring it with some OOP design principles.
app = connexion.App(__name__)
app.add_api(
os.path.join(global_variables.ROOT_DIR, "openapi.yaml"),
pythonic_params=True,
validate_responses=VALIDATE_RESPONSES,
validator_map={"parameter": request_parameter_validator.RequestParameterValidator},
)
In the openapi.yaml the operationId specifies the full path to the class method which handles the request, but it throws the error:
TypeError: be_autocomplete_handler() missing 1 required positional argument: 'self'
How can I create an instance of that class in this case and pass it in the parameters field? Also, I do not pass any parameters in the constructor for now.
However, is there a preferred workflow in this case? Rather than creating an object instance?

Related

No MessageBodyWriter for Single

I'm trying to use resteasy-rxjava2 to provide an XML document using jaxb, within a vertx application (using a non-vertx legacy library we have). But I get:
Could not find MessageBodyWriter for response object of type:
org.jboss.resteasy.rxjava2.propagation.ContextPropagatorOnSingleAssemblyAction$ContextPropagatorSingle of media type:
application/xml;charset=UTF-8
From what I can tell, this comes down to the difference between a MessageBodyWriter and the AsyncResponseProvider that is in the resteasy-rxjava2 dependency for a Single (SingleProvider).
I have the following resteasy service definition
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
// CHECKSTYLE:OFF too many parameters
public Response getQuery(...)
How do I get resteasy to properly serve the data asynchrously, using the SingleProvider or otherwise.
The #Get method must return the Single explicitly or it doesn't work. (Can't use Response or Object). In my case, the Single contains the jaxb xml root element.
#GET
#Path(FdsnwsPaths.QUERY)
#Produces(MediaType.APPLICATION_XML)
#Stream
public Single<FDSNStationXML> getQuery(...)
Then, to make things more complicated, in order to handle specific exception types and map them to specific response status codes, I have to create a custom ExceptionMapper which creates the Response object I used to be able to create directly in the method. (in resteasy-vertx, I found no documentation on how to do this, but in my case, I am creating my own VertxRestEasyDeployment object so I can register the class of the ExceptionMapper(s) like this:
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.getActualProviderClasses().addAll(providerClasses);
For reference, this is all being done with:
RestEasy 5.0.3.Final (including resteasy-rxjava2)
RxJava 2.2.20
Vertx 3.9.5

Web API Project - Base Class Does Not Have Parameterless Constructor

As my training goes on, I've come accross this BaseApiClass without parameterless constructor, so when I'm inhereting the base class, I always pass the required parameter. But on run time I got an error like this:
Note: I've noticed that they're using Autofac but I'm not familiar with that..
Here's what the api controller looks like:
and base class:
I tried adding parameterless constructor but it obviously throws error because it doesn't correspond to my baseclass.
Here's what my Global.asax looks like:
I'm kind of new to this. Any suggestion would be great!

Passing parameter to typescript decorators

So, I am working on developing a CRUD server in nestjs, using Mongo as the database, and I am trying to inject the database connection that can be obtained from the service constructor (#InjectConnection() private connection?: mongoose.Connection), into a decorator by doing #Decorator(this.connection). This is not possible because the decorator factory runs before the connection to the database has been initialised. With this being, every time that the decorator is used, the connection is undefined. Is there a workaround for this kind of situation? I really wan't to implement the solution using typescript decorators.
decorators in typescript has 3 arguments. target which is the prototype of the class, key which is the key that you are applying the decorator to and third descriptors which is to change the value of the key. essentially when you type #Decorator, typescripts sees it as a function. this is how you defined your decorator.
#Decorator=function Decorator(target:any,key:string,desc:PropertyDescriptor){}
now you want to write it like this
#Decorator()
that means you have add additional () to the right side as well. this is simple maths.
#Decorator()=function Decorator()(target:any,key:string,desc:PropertyDescriptor){}
what you have to do is you have define decorator as the function which returns a function with those parameters.
function Decorator(...args){
return function(target:any,key:string,desc:PropertyDescriptor){
// you can access to ...args here
}}

Dialogflow V2 - Custom Contexts

How can I create a custom system context to pass values from my API to dialogflow which is not dependent on any event.
I tried to put the same in the output context, but it is giving error Invalid Argument as the context name doesn't exist.
Here is the below pseudo code which I am doing (Java),
1. define the contextSettings object by setting credentials provider.
2. Create ContextsClient object using contextSettings object.
3. Create CreateContextRequest object by setting parent and context object.
4. Get the final Context object using ContextsClient.createContext(contextRequest)
5. Set the above context object in queryParameters to pass in DetectIntent Request.
But this is failing in Step # 4, and giving an error as Invalid Argument as the context name is not present under /projects/session
Please help me resolving this issue.
The reason that I want to create custom context is that I need to set values from API to pass to dialogflow and it is independent of Events or a specific flows.
We were able to create custom context in Dialogflow V1 using AIContext class and set the context object in the AIRequest object.
Thanks,
Ron
I am able to resolve the issue. I was not passing fully formed context path while creating the context object.
Context dialogflowContext = Context.newBuilder().setName(
"projects/[project-id]/agent/sessions/" + sessionId + "/contexts/[context-name]")
.setParameters(paramPair).setLifespanCount(1).build();

AutoMapper inline mapping throwing mapper not initialized

I'm trying to use AutoMapper in a API wrapper class library project to map from API models to our domain models. While looking at the AutoMapper documentation I ran into the inline mapping feature.
Documentation says:
AutoMapper creates type maps on the fly (new in 6.2.0). When you call Mapper.Map for the first time, AutoMapper will create the type map configuration and compile the mapping plan. Subsequent mapping calls will use the compiled map.
So I wrote the following line of code in my wrapper class library:
var data = response.Results.Select(Mapper.Map<Session, Media>).ToList();
basically just trying to map the Session object I get from the API into our Media objects. But this throws the following error:
Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.
I was under the impression that inline mapping is exactly supposed to bypass having to initialize and define configuration for AutoMapper? Am I wrong?
Also if I am indeed wrong then how are you supposed to configure and initialize AutoMapper inside a class library to where it happens only once? I would like the library to be independent, meaning I don't want the programmer using the library to have to configure AutoMapper in his project in order for the library to work properly.

Resources