Can i use swagger to create common response structure? - swagger

I have common response structure for successful response:
{
"status": "ok",
"response": <data is here>
}
and error response:
{
"status": "error",
"message": "<error description>"
}
How can i describe it using Swagger without copy/paste root structure for successful response.
Example of data:
{
"status": "ok",
"response": {
"name": "Loki",
"age": 1100
}
}

Related

Google Document AI custom processor training failed for unknown reason

After annotating my data set and training a custom processor on Google Document AI, I get the following error message after 40 mins:
{
"name": "projects/500809854407/locations/eu/operations/10980743890623751388",
"done": true,
"result": "error",
"response": {},
"metadata": {
"#type": "type.googleapis.com/google.cloud.documentai.uiv1beta3.TrainProcessorVersionMetadata",
"commonMetadata": {
"state": "FAILED",
"createTime": "2023-01-13T15:11:36.505757Z",
"updateTime": "2023-01-13T15:50:10.343765Z",
"resource": "projects/500809854407/locations/eu/processors/b94da5023b6cb35d/processorVersions/98637063da2b64d4"
},
"trainingDatasetValidation": {},
"testDatasetValidation": {}
},
"error": {
"code": 13,
"message": "Internal error encountered.",
"details": []
}
}
Any idea what could be the problem?

Is there a way to post a message with a code snippet?

The new way to upload images as hosted content through the Send Message endpoint is great! However, is there a way to upload text/plain as hosted content in order to post a Code Snippet Card in a message?
I have tried uploading text but the response gives me an error that says that the only content types allowed are 'image/jpg,image/jpeg,image/png'.
Example request:
{
"body": {
"contentType": "html",
"content": "<attachment id=\"4d92eb51ab9c48ebb5b364794a2fa569\"></attachment>"
},
"attachments": [
{
"id": "4d92eb51ab9c48ebb5b364794a2fa569",
"contentType": "application/vnd.microsoft.card.codesnippet",
"contentUrl": null,
"content": "{\"name\":\"\",\"language\":\"CSharp\",\"lines\":1,\"wrap\":false,\"codeSnippetUrl\":\"../hostedContents/1/$value\"}",
"name": null,
"thumbnailUrl": null
}
],
"hostedContents":[
{
"#microsoft.graph.temporaryId": "1",
"contentBytes": "VGVzdA==",
"contentType": "text/plain"
}
]
}
Response:
{
"error": {
"code": "BadRequest",
"message": "Unsupported content type in hostedContent with Id '1'. Allowed values are 'image/jpg,image/jpeg,image/png'",
"innerError": {
"date": "2020-10-07T12:17:15",
"request-id": "ed24f5df-3e1f-4871-b430-e4c1c9f30348",
"client-request-id": "ed24f5df-3e1f-4871-b430-e4c1c9f30348"
}
}
}
I received an answer in the Documentation GitHub: https://github.com/microsoftgraph/microsoft-graph-docs/issues/10210#issuecomment-705050649
Code snippets are not supported at the moment. They are on list of things to support, but there is no timeline to share yet.

Error when set schedule for private video using Google APIs Explorer

Question: Why did I get this error? The error message is not informative/helpful. Please assist to solve.
I tried to simulate this on Google APIs Explorer:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.update
Part: status
{
"id": "3zZ1lCz-rp4",
"status": {
"privacyStatus": "private",
"publishAt": "2019-04-12T12:12:12.12Z"
}
}
But not working. Getting response:
{
"error": {
"errors": [
{
"domain": "youtube.video",
"reason": "invalidVideoMetadata",
"message": "The request metadata is invalid.",
"locationType": "other",
"location": "body"
}
],
"code": 400,
"message": "The request metadata is invalid."
}
}

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

rails json response not able to build

I have a method in controller creat
it respond generate array of records like
[{"code"=>500, "body"=>{"message"=>"Ivalid data or you enter a duplicate data"}}, {"code"=>200, "body"=>{"id"=>"775606be-d3ae-4b43-a820-74022f8f273f"}}, {"code"=>500, "body"=>{"message"=>["Name has already been taken"]}}, {"code"=>500, "body"=>{"message"=>[:Error, ["No Fable", "level not found in rand", "Invalid or Blank e"]]}}]
now I want to make it n a json response
def create
k=[{"code"=>500, "body"=>{"message"=>"Ivalid data or you enter a duplicate data"}}, {"code"=>200, "body"=>{"id"=>"775606be-d3ae-4b43-a820-74022f8f273f"}}, {"code"=>500, "body"=>{"message"=>["Name has already been taken"]}}, {"code"=>500, "body"=>{"message"=>[:Error, ["No Federation ID in Cookie ID\n# Mapping Table", "level not found in Brand", "Invalid or Blank Source Type"]]}}]
# render create.json.jbuilder
render json: k, status: 200
end
so it generate
{
"bulks": [
{
"code": 500,
"body": {
"message": "Ivalid data or you enter a duplicate data"
}
},
{
"code": 200,
"body": {
"id": "7754322222222f"
}
},
{
"code": 500,
"body": {
"message": [
"Name has already been taken"
]
}
},
{
"code": 500,
"body": {
"message": [
"Error",
[
"No Fable",
"level not found in Brand",
"Invalid or Blank Source Type"
]
]
}
}
]
}
it added bulks: while render the json in controller
how can I remove the bulks the expected json would be
{ {
"code": 500,
"body": {
"message": "Ivalid data or you enter a duplicate data"
}
},
{
"code": 200,
"body": {
"id": "775606be-d3ae-4b43-a820-74022f8f273f"
}
},
{
"code": 500,
"body": {
"message": [
"Name has already been taken"
]
}
},
{
"code": 500,
"body": {
"message": [
"Error",
[
"No Fable",
"level not found in Brand",
"Invalid or Blank Source Type"
]
]
}
} }
Please help

Resources