Query parameters are not percent-encoded for curl with OpenAPI - swagger

I generate open api documentation with springdoc 1.6.7 .
When i want to test an endpoint with following query parameter on swagger ui:
{
"page": 0,
"size": 0,
"sort": "string",
"order": "asc",
"q": {
"any": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"company": "string",
"login": "string",
"noSubscription": true
}
}
It generate following curl request:
curl -X 'GET'
'https://myEndpoint?page=0&size=0&sort=string&order=asc&q[any]=string&q[firstName]=string&q[lastName]=string&q[email]=string&q[company]=string&q[login]=string&q[noSubscription]=true'
-H 'accept: application/json'
The character '[' and ']' are not encoded, so curl request doesn't work.
Here java code from swagger is generated:
#Operation(summary = "XXXX", description = "XXX")
#ApiResponses(value = {
#ApiResponse(responseCode = "200", description = "Success",
content = { #Content(mediaType = "application/json",
schema = #Schema(implementation = PageCollectionContact.class)) }),
#ApiResponse(responseCode = "400", description = "Invalid query parameters",
content = { #Content(
schema = #Schema(implementation = ApiErrorsDTO.class))})})
PageCollectionDTO<AddressBookUserDTO> getContacts(#EffectivePrincipaleUserInfo EffectiveUserInfo userInfo,
#Parameter(description = "Contains parameter to filter response",in = ParameterIn.QUERY) #ModelAttribute AddressBookFilterDTO filterDTO,
HttpServletResponse response,
HttpServletRequest request);

Related

Rails - how to get response properly?

uri = URI(some_url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.read_body
Try to on browser, it returns result like this.
[
{
"id": 663,
"name": "string1"
},
{
"id": 644,
"name": "string2"
},
{
"id": 685,
"name": "string3"
},
]
But I am getting this error with my code.
Error: Net::HTTPBadResponse:wrong status line: "\x15\x03\x01\x00\x02\x02"

Generate response example values using swagger with GRPC

I'm generating swagger json file using protoc-gen-swagger with gRPC service. The output json is being generated with empty response examples, I want to add response examples to the definition so it gets automatically populated in the generated json.
This is my current definition.
service UserService {
rpc GetUser (GetUserRequest) returns (UserResponse){
option (google.api.http) = {
get: "/api/v1/user/{username}"
response_body: "*"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
description: "Returns user object";
operation_id: "get_user";
summary: "Get User";
};
}
}
message GetUserRequest {
string username = 1;
}
message UserResponse {
User user = 1;
}
message User {
string first_name = 1;
string last_name = 2;
string username = 3;
}
When I generate the swagger file using the command
protoc -I ${PROTOPATH} \
-I $GOPATH/src \
--swagger_out=logtostderr=true:${OUT_PATH}
I get a swagger file with this user object definition
"User": {
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"username": {
"type": "string"
},
}
}
What I want is to generate it with example values like this:
"User": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "Adam"
},
"last_name": {
"type": "string",
"example": "Smith"
},
"username": {
"type": "string",
"example": "asmith79"
},
}
}
Found the answer to this here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.proto#L197
Simple by adding grpc.gateway.protoc_gen_swagger.options.openapiv2_schema as an option to the message.
import "protoc-gen-swagger/options/annotations.proto";
message User {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
example: { value: '{ "first_name": "Adam", "last_name":"Smith", "username":"asmith79"}' }
};
string first_name = 1;
string last_name = 2;
string username = 3;
}

Microsoft graph batch inserting new task and updating details

Current steps for creating task are
POST /planner/tasks
GET /planner/tasks/{id from post call}/details
PATCH /planner/tasks/{id from post call}/details
If-Match: {etag from get call}
but I want to batch three steps in single call using https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching
And according to odata v4 references http://docs.oasis-open.org/odata/odata-json-format/v4.01/csprd02/odata-json-format-v4.01-csprd02.html#sec_ReferencingNewEntities we can refer entities in same batch call using ${id of other request}
{
"requests": [
{
"id": "task",
"url": "/planner/tasks",
"body": {
"title": "asff",
"appliedCategories": {
"category5": true
},
"planId": "mSV7ODf3g0iTJrUtsNcvHZYAB-ZW",
"bucketId": "WFN6kxMykE-4xxqLUh1uS5YALCWq",
"assignments": {
"4393baf8-8a52-4164-bf93-b1cba5130329": {
"#odata.type": "#microsoft.graph.plannerAssignment",
"orderHint": " !"
}
},
"dueDateTime": "2018-04-23T18:30:00.000Z"
},
"method": "POST",
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "getDetail",
"method": "GET",
"dependsOn": [
"task"
],
"url": "/planner/tasks/$task/details"
},
{
"id": "patchDetail",
"dependsOn": [
"getDetail"
],
"url": "/planner/tasks/$task/details",
"method": "PATCH",
"headers": {
"Content-Type": "application/json",
"if-match": "$getDetail"
},
"body": {
"description": "gwrthbetrhnety"
}
}
}
]
}
but Get details call is failing with error
{
"id": "getDetail",
"status": 400,
"body": {
"error": {
"code": "BadRequest",
"message": "The request URI is not valid. Since the segment 'tasks' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource.",
"innerError": {
"request-id": "a46ce528-993f-4cff-865e-98b2b98d5f23",
"date": "2018-04-17T10:38:29"
}
}
}
}
What I'm doing wrong here
I believe what is missing is the URI (should be POST https://graph.microsoft.com/v1.0/$batch instead of POST /planner/tasks) and "id" field has to be numeric. Check out MS documentation:
https://learn.microsoft.com/en-us/graph/json-batching?context=graph%2Fapi%2F1.0&view=graph-rest-1.0
Here is an example of combining POST and GET in a batch call

Reply sent email by Gmail API

Currently I'm trying to create send and reply using gmail api, in documentation here
Refernces and In-Reply-To must be set in compliance with the RFC 2822 standard, the problem is when I try to get References and In-Reply-To from specified id like below:
`{
"id": "16183e0822247c79",
"threadId": "16183e0822247c79",
"labelIds": [
"SENT"
],
"snippet": "terkait",
"historyId": "1640387",
"internalDate": "1518335984000",
"payload": {
"partId": "",
"mimeType": "multipart/mixed",
"filename": "",
"headers": [
{
"name": "Received",
"value": "from 1059028371380 named unknown by gmailapi.google.com with HTTPREST; Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "Date",
"value": "Sat, 10 Feb 2018 23:59:44 -0800"
},
{
"name": "From",
"value": "jaisanas2#gmail.com"
},
{
"name": "To",
"value": "jaisanas3#gmail.com"
},
{
"name": "Message-Id",
"value": "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw#mail.gmail.com\u003e"
},
{
"name": "Subject",
"value": "terkait"
},
{
"name": "Mime-Version",
"value": "1.0"
},
{
"name": "Content-Type",
"value": "multipart/mixed; boundary=\"--==_mimepart_5a7ff7f050e3_3263ffa0ceb1cc020ea\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"--==_mimepart_5a7ff7f05063_3263ffa0ceb1cc01916\"; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "7bit"
}
],
"body": {
"size": 14,
"data": "PHA-dGVya2FpdDwvcD4="
}
}
]
}
]
},
"sizeEstimate": 929
}`
When you see the result there are no headers In-Reply-To and Refernces, my questions is it is possible to reply email using API ?
Here is my code in ruby:
client = google_client user_id
token = Token.find_by_user_id(user_id)
access_token = token.access_token
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = client
message = Mail.new
message.date = Time.now
message.subject = "Re: #{subject}"
message.from = token.email
message.to = "#{to}"
# message.thread_id = "#{thread_id}"
message.message_id = "\u003cCA+8aSZeXMOETdH8NYtd18UWk5eiQnvT0oEnEWy_1HL6mJPuKjw#mail.gmail.com\u003e"
message.part content_type: 'multipart/alternative' do |part|
part.html_part = Mail::Part.new(body: "#{body}", content_type: 'text/html; charset=UTF-8')
end
msg = message.encoded
message_object = Google::Apis::GmailV1::Message.new(raw:message.to_s, thread_id: thread_id, content_type: 'message/rfc822')
gmail.send_user_message('me', message_object)
This code successfully send email in the same thread, but not reply email, here is what looks like inside my gmail sent emails:
As you can see, message with body lauv does not reply message terkait instead I just sent email lauv, my question is how to reply email?
Here you need to set In-Reply-To and References headers. If there is only one email in the thread use the message_id as In-Reply-To and References

QuickBooks API POST using Google Apps Script

Does anyone have a working example of doing a POST to the QuickBooks API using Google Apps Script?
I'm trying to create an estimate using the QuickBooks API, however although the request body below works in the API explorer, from within Apps Script I get:
Error: Fetch failed, code: 400, message: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Unrecognized token 'Line': was expecting ('true', 'false' or 'null')\n specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"},"time":"2016-08-02T09:51:28.917-07:00"} (line 195, file "Tests")
But I can't see why the API expects a boolean rather than the "Line" key.
This is how I define it as a POST payload in the code:
var payload = {
"Line": [
{
"Id": "3",
"LineNum": 1,
"Amount": 10,
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"ItemRef": {
"value": "2",
"name": "Hours"
},
"UnitPrice": 10,
"Qty": 2
}
},
{
"Amount": 10,
"DetailType": "SubTotalLineDetail",
"SubTotalLineDetail": {}
}
],
"TxnTaxDetail": {
"TotalTax": 0
},
"CustomerRef": {
"value": "1",
"name": "Mr Blobby"
},
"CustomerMemo": {
"value": "Thank you for your business and have a great day!"
},
"TotalAmt": 31.5,
"ApplyTaxAfterDiscount": false,
"PrintStatus": "NeedToPrint",
"EmailStatus": "NotSet",
}
var companyId = PropertiesService
.getUserProperties()
.getProperty('QuickBooks.companyId')
var url = 'https://quickbooks.api.intuit.com/v3/company/' + companyId + '/estimate'
var options = {
headers: {
'Accept': 'application/json'
},
contentType: 'application/json',
method: 'post',
payload: payload,
muteHttpExceptions: true,
}
var service = OAuth1_.getService();
var response = service.fetch(url, options)
You need to stringify the whole payload before passing it to the OAuth.fetch() call.
So
var payload = JSON.stringify({
"Line": [
{
"Id": "3",
.
.
})

Resources