How to define apiParam json object on apidoc - api-doc

I want to define object apiParam for example
let data = {
id:null,
status:null,
category:null
}
The variable data is a json object I want to show object params on apiParam.

Related

How to serialize Fields response to object type from Elasticsearch.Net client GET doc request

When I use the Elasticsearch.Net client to do a Get document request, I am setting _source to false and specifying the stored fields I want to return. I do not want the _source because there are large contents and even if I exclude them, the server still loads the source into memory to parse it which is very slow and I do not want.
When I do have source included, I can just specify the object type and it is automatically de-serialized from the _source. How can I do this with the Fields property? It is of type FieldValues : IsADictionaryBase<string, LazyDocument>
var response = await client.GetAsync<MyObject>(docId,
s => s.Index(myIndex)
.SourceEnabled(false)
.StoredFields(new string[] {
"MyStringArray1",
"MyStringArray2",
"MyLongValue" }
));
The only way I have found to do this is to iterate over all the properties in the object manually.
MyObject mine = new MyObject()
{
MyStringArray1 = response.Fields["MyStringArray1"].As<string[]>(),
MyStringArray2 = response.Fields["MyStringArray2"].As<string[]>(),
MyLongValue = response.Fields.Value<long>("MyLongValue")
};
Is there an easier way to deserialize to MyObject type?

gson.toJson() return null when object initialized and class properties set immediately

I am using gson library to handle json to body conversion. below code returns null value for toJson() method. can some one please suggest me if i miss anything.
Fruits fruits = new Fruits() {
{
setName("mango");
setPrice(10);
}
};
String body = gson.toJson(fruits);

Comma-delimited request params not working with Kotlin data class

I have an endpoint which can accept dozens of request params. It would be nice to collect all these params in a data class. Additionally, the request params must be separated by commas
path?param=1,2
to keep backward compatibility.
Assume we have this endpoint:
#GetMapping("path")
fun someFun(#RequestParam param: Set<Int> = emptySet()
...other 11 params
)
I created a data class to collect all the request params:
data class ClusteredParams(val param: Set<Int> = emptySet()
...other 11 params
)
So the endpoint looks like the following:
#GetMapping("path")
fun someFun(param: ClusteredParams)
When I called path?param=1,2 I got:
"error": "Failed to convert value of type java.lang.String[] to required type java.util.Set; nested exception is java.lang.NumberFormatException: For input string: "1,2"",
"field": "param",
"rejectedValue": "1,2"
When I call path?param=1&param=2 everything is fine. This problem does not exist when ClusteredParams class is written in Java.
public class ClusteredParams {
private Set<Int> param;
...other 11 params
getters and setters
}
I don't know the answer, but I did the comparison what works and when:
in Java:
You can either call ?path=1,2 and ?path=1&path=2 no matter if your request param is declared using #RequestParam path: List<Int> inside signature of controller method, or it is a field of external object that's used to group all request params of controller method.
In Kotlin:
if you declare your request param inside of controller method signature, as a #RequestParam path: List<Int> or whatever else, you can call it using both methods, so:
?path=1,2 and ?path=1&path=2
If you however extract it to separate data class, and then expect this class to be populated in controller method, you can only do the ?path=1&path=2, because in the case of ?path=1,2 you get:
org.springframework.validation.BindException because it tries to parse entire '1,2' instead of split it first.
I hope now it is more clear, does anyone have idea why this happens?
Instead of val use var inside data class body:
data class ClusteredParams(
...other 11 params
) {
var param: Set<Int> = emptySet()
}

Unable to access object property except by stringify/parse before the data in Graphql/resolver context

Unable to access my resolver returned object, however, I can see its content, but accessing properties returns an undefined. Only solution I found is using Stringify/Parse on my value.
Using JSON Stringify then PARSE on my Object turns it to be readable, but this is a lame solution :)
const MonkeyResolver = {
Monkey: {
address: (data, args, context) => {
console.log({data}); // Returns the actual entire object (monkey>address)
console.log(data.address); // --> Returns undefined
const newData = JSON.stringify(data);
const parsedData = JSON.parse(newData);
console.log(data.address); // --> Returns the address
}
}
}
My expected object is such as :
Object(monkey)
address:
city
street
What did I misunderstand?
Solved : if the reference database model schema manager does not include the properties, graphql prevent using the properties. I had to check out my defined schemas and solved by adding the needed object properties.

Web API parameter filtering

This must be simple and I'm being incredibly dense but I can't find an example to help me figure it out. I want to filter my list of tblAsset items by their assessmentId which is passed in through a parameter. I'm able to get the parameter value ok, but I'm not sure how to write the query.
My model is built from an existing Database using the Model creation wizard.
Thanks for any help!
public IEnumerable<tblAsset> GettblAssets()
{
NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
var assessmentId = nvc["aid"];
//limit the assets by assessmentId somehow and return
}
You could use the .Where extension method on the IQueryable<tblAsset> instance returned by your database:
public IEnumerable<tblAsset> GettblAssets()
{
NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
var assessmentId = nvc["aid"];
// TODO: you might need to adjust the property names of your model accordingly
// Also if the assessmentId property is an integer on your model type
// you will need to parse the value you read from the request to an integer
// using the int.Parse method
return db.tblAsset.Where(a => a.assessmentId == assessmentId);
}

Resources