DocuSign optional parameter node js sdk - node.js

How to specify the optional parameter in update node js sdk method. Update ( account ID, envelope I'd , envelope obj )

You just add the parameter you want to the call
so, if there's an optional parameter in a method method1, you can call it like this:
method1(param1, param2, param3);
(where if param3 is optional you can also call it like this:)
method1(param1, param2);
you can also (See here - Is there a way to provide named parameters in a function call in JavaScript?) specify the names of the parameters:
method1(param1 - "param1", param2: "param2");

Related

how to use optional url parameters with NestjS

I'm trying to replace our current backend service using Nestjs library,
however, I want to create a route with 2 optional parameters in the URL something like :
/route/:param1/config/:OptionalParam3?/:OptionalParam3?
that means the route should catch :
route/aa/config
route/aa/config/bb
route/aa/config/bb/cc
how can I achieve that, I have tried to use ? and () but it's not working well.
If you are looking for how to annotate an optional query parameter, you can do it like so:
#ApiQuery({
name: "myParam",
type: String,
description: "A parameter. Optional",
required: false
})
async myEndpoint(
#Query("myParam") myParam?: string
): Promise<blah> {
[...]
}
Router params name should be unique. The correct route path is:
Existing one is:
/route/:param1/config/:OptionalParam3?/:OptionalParam3?
Correction:
/route/:param1/config/:OptionalParam3?/:OptionalParam4?
Opinion: You can use query params if the params are optional. It is never a good idea to create optional param routes (disagreements agreed). Both serve the same purpose, but having them as the query params makes it more understandable for debugging and fellow developers.
I solved this problem by using #Query decorator as below:
Here is my controller:
#Get()
async getAll(#Query('someParameter') someParameter?: number) {
return this.service.getAll(someParameter);
}
Here is my client (Angular) service:
getAll(someParameter?: number) {
return this.http.get(`apiUrl/controllerAddress?someParameter=${someParameter}`
);
}
You can use this structure:
-route
-aa
-config
-[[...id]].js
It will work for the routes :
route/aa/config/{anything}

ServiceStack - Customize Generated OpenAPI JSON using OpenApiFeature

Using the ServiceStack OpenApiFeature, the generated operationId in the openapi.json file follows this convention:
[RequestName][route path slice without first path*][http verb][digit if required for uniqueness]
The route path slice without first path* simply removes the first item in the path. So if the route path is blog/author/name, the logic would grab author/name.
This is defined in the OpenApiService::GetOperationName method. In some cases, this logic creates sub-optimal operation naming in tools that rely on openapi.json. As an example, if you have a service that exposes GET operations for a customer's details, customer summary, etc. and the details request is defined like this:
[Api("Get a customer's details.")]
[Route("/customer/details", "GET")]
public class GetCustomerDetailsRequest : IReturn<GetCustomerDetailsResponse>
{ ... }
The route will be something like this (which is good):
/customer/details?customerId=2
...but the generated OpenAPI operationId would be GetCustomerDetailsRequestdetails_Get, which isn't great.
Is there a way to customize the generated operationId using the OpenApiFeature? If not, is there some other naming convention that will maintain the REST-esque route convention but provide a better OpenAPI operationId?
EDIT: Thanks to mythz for pointing out the ApiDeclarationFilter. It allows you to complete customize the generated openapi.json. This is how I'm changing the operationId:
Plugins.Add(new OpenApiFeature
{
ApiDeclarationFilter = declaration =>
{
foreach (var p in declaration.Paths)
{
foreach (var httpVerb in _httpVerbs) // _httpVerbs is just a list of http verbs
{
// retrieve the operation value using reflection and pattern matching. This is to prevent having to use a switch statement to go through each http verb and check if it's been implemented
if (p.Value.GetType().GetProperty(httpVerb).GetValue(p.Value) is OpenApiOperation operation)
{
// Set the "OperationId" property using the convention [RequestClassName]_[Http Verb]. Note for simplicity here, I'm not checking for a unique operation Id. You should do that to ensure open api compliance
ReflectionHelper.SetProperty($"{httpVerb}.OperationId", p.Value,
$"{operation.RequestType}_{httpVerb}");
}
}
}
}
});
Apart from the API metadata attributes, you can further customize what JSON is returned using the filters available, e.g:
Plugins.Add(new OpenApiFeature
{
ApiDeclarationFilter = (openApiDoc) => ...,
OperationFilter = (verb, operation) => ...,
SchemaFilter = (schema) => ...,
SchemaPropertyFilter = (openApiProperty) => ...,
});

Mockito override return value on multiple calls from static class

There are two calls made to a static class for getting the object. Like below:
MyObject myobj1 = Mock(MyObject.class)
PowerMock(static1.class)
when(static1.method(param1,parame2,param3).thenreturn(myobj1);
myobj1.setcontent(inputstream1);
MyObject myobj2 = Mock(MyObject.class)
when(static1.method(param1,parame2,param3).thenreturn(myobj2);
myobj2.setcontent(inputstream2);
With above calls we notice that content set in the response of method calls is overridden by content of inputstream2.
How can we create multiple return objects using Mockito?
When you do multiple stubbings with the same parameters each one overrides the previous one. When you call
when(static1.method(param1, param2, param3).thenReturn(myobj2);
this overrides the previous stubbing of static1.method(param1, param2, param3) that returned myobj1.
In order to return a different return value on each invocation of static1.method() you need to chain the thenReturn() calls like this:
when(static1.method(param1, param2, param3)
.thenReturn(myobj1)
.thenreturn(myobj2);
Alternatively, you can abbreviate this to
when(static1.method(param1, param2, param3)
.thenReturn(myobj1, myobj2);
Using either of the two ways, the first call of static1.method() will return myobj1 and the second one will return myobj2.
As a result your code should first work with inputstream1 and then with inputstream2.

Missing type annotation error flow js

I am using flow js for static type checking in my project. I am getting errors while checking type.
Here are the steps which I followed while setting up flow in project.
npm i flow-bin -SD
Added commands in project.json:
"scripts": {
"flow": "flow",
"flow:check": "flow check ./src/"
}
Now, While running npm run flow:check, I am getting this error.
Missing type annotation for fn.
6| module.exports = function( ds, schema, fn ) {
^^
Because Flow needs you to tell it the type signature of that function.
Now if that's code you don't control (code inside node_modules for example) I suggest to exclude that from being typechecked by Flow; most libraries don't ship/bundle type definitions for Flow (the flow-typed repo might have them).
If that is code that you control (it's part of your app's code), then just add the types. For example (this are random types, you should replace these with the correct ones):
module.exports = function( ds: string, schema: number, fn: (string) => boolean ): boolean {
// ...
};
In this example, the ds parameter has to be a string, the schema has to be a number, and the fn parameter has to be a function that accepts a string as the only parameter and will return a boolean when called. And the result type of the exported function is a boolean as well.

No routing convention was found to select an action for the OData path with template '~/entityset'

I have two Odata action methods defined. The one with parameter gets invoked while the other without parameter doesnt get invoked and throws error No routing convention was found to select an action for the OData path with template '~/entityset'.
Here is the code of my action methods
[EnableQuery]
public IQueryable<User> GetUser()
{
return db.Users;
}
// GET: odata/User(5)
[EnableQuery]
public SingleResult<User> GetUser([FromODataUri] int key)
{
return SingleResult.Create(db.Users.Where(user => user.Id == key));
}
The query that I am using are as follows
http://bureauservice/api/odata/UserOdata - Doesnt work
http://bureauservice/api/odata/UserOdata(1) - works
Could someone tell me why the first link doesnt work.
Please change the name of the method which returns entityset to "Get[EntitySetName]" or "Get".
Change from
public IQueryable<User> GetUser()
To
public IQueryable<User> GetUserOdata()
Or
public IQueryable<User> Get()
Set the name of the first action as GetUsers (plural) because you are getting the whole collection of users while in the second you are asking for a single user.
You may want to add the parenthesis to the first URL:
http://bureauservice/api/odata/UserOdata()
If you are just starting to proactise odata, then Odata v4 is good start point, as it is an OASIS standard, but v3 is not.
Here is the v4 version Function sample:
https://github.com/OData/ODataSamples/tree/master/WebApiCore/ODataFunctionSample.

Resources