I'm using swagger-php annotations to generatee the documentation of my REST API, and I'd like to use pre-defined examples for describing responses.
The YAML code below works:
components:
examples:
exampleUser:
value:
id: 1
name: "Alan Cool"
email: "joe#cool.com.br"
password: "string"
status: "string"
ultimo_acesso: 155850122
cpf: "string"
rg: "string"
cargo: "string"
grupo_id: 7
empresa_id: 88
thumbnail_id: 99
loja_id: 1299
But, when trying to generate the code above via annotations, I can't get it to work. 'm trying:
/**
* #OA\Examples(
* summary = "exampleUser",
* description = "exampleUser",
* value = "exampleUser"
* )
*/
It seems that there is no doumentation for PHP annotations so far. Any suggestions?
Related
i would like to create the path object for the following url
url: "http://127.0.0.1:5000"
in the code when the user enters the above mentioned url followed by slash \ a method called start() is to be called and executed.
that method when called it receives response from the backend in form of json file and it retuens it.
how to build the path and responses object for such action please
code:
#app.route("/", methods=['GET','POST'] )
def startCoord2():
baseURL = "https://api.openrouteservice.org/v2/directions/driving-car?api_key=5b3ce3597851110001cf62480ecf8c403567479a87de01df5da651fb&start=8.681436,49.414554&end=8.681561,49.414747"
with urllib.request.urlopen(baseURL) as response:
print ("str(response): " + str(response))
print ("str(response.getCode(): " + str(response.getcode()))
data = response.read()
print ("response.read(): " + str(data))
dataAsJSONObject = json.loads(data)
distance = str(dataAsJSONObject["features"][0]['properties']['segments'][0]['distance'])
return dataAsJSONObject #config['EndPoint']['url'] + config['EndPoint']['api_key'] + "&start=" + startLat + "," + startLng + "&end=" + end1Lat + "," + endLng + ""
yaml file:
openapi: '3.0.2'
info:
title: &apiTitle "Distance micro-service API."
description: "This micro-service receives four comma separated GPS coordinates in the following order, startLongitude, startLatitude, endLongitude
, endLatitude in the url. Then it receives a response in a form of json file. The json file is to be fetched for the distance which represents the distance between
the aforementioned GPS coordinates"
version: '1.0'
termsOfService: "http://127.0.0.1:5000/getDistance/terms"
contact:
name: " "
url: "http://127.0.0.1:5000"
email: "me#provider.com"
license:
name: "CC Attribution-ShareAlike 4.0 (CC BY-SA 4.0)"
url: "https://openweathermap.org/price"
servers:
- url: http://127.0.0.1:5000
description: Local host test server. When accessed it will return the distance from Berlin to Alexandria in Egypt in kilometers.
variables:
originAndDestinationGPSCoords:
default: 13.404954,52.520008,29.924526,31.205753
description:
Local host test server. When accessed it will return the distance from Berlin to Alexandria in Egypt in kilometers.
paths:
/:
get:
tags:
- "get response data in json format"
summary:
get the distance between 8.681436,49.414554,8.681561,49.414747
description: >
to display data in json formate
responses:
'200':
description: Distance fetched successfully.
I’m new to telegraf and influxdb, and currently looking forward to exploring telegraf, but unfortunetly, I have some difficulty getting started, I will try to explain my problem below:
Objectif: parsing JSON file using telegraf input plugin.
Input : https://wetransfer.com/downloads/0abf7c609d000a7c9300dc20ee0f565120200624164841/ab22bf ( JSON file used )
The input json file is a repetition of the same structure that starts from params and ends at it.
you find below the main part of the input file :
{
"events":[
{
"params":[
{
"name":"element_type",
"value":"Home_Menu"
},
{
"name":"element_id",
"value":""
},
{
"name":"uuid",
"value":"981CD435-E6BC-01E6-4FDC-B57B5CFA9824"
},
{
"name":"section_label",
"value":"HOME"
},
{
"name":"element_label",
"value":""
}
],
"libVersion":"4.2.5",
"context":{
"locale":"ro-RO",
"country":"RO",
"application_name":"spresso",
"application_version":"2.1.8",
"model":"iPhone11,8",
"os_version":"13.5",
"platform":"iOS",
"application_lang_market":"ro_RO",
"platform_width":"320",
"device_type":"mobile",
"platform_height":"480"
},
"date":"2020-05-31T09:38:55.087+03:00",
"ssid":"spresso",
"type":"MOBILEPAGELOAD",
"user":{
"anonymousid":"6BC6DC89-EEDA-4EB6-B6AD-A213A65941AF",
"userid":"2398839"
},
"reception_date":"2020-06-01T03:02:49.613Z",
"event_version":"v1"
}
Issue : Following the documentation, I tried to define a simple telegraf.conf file as below:
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/file.json"]
json_name_key = "My_json"
#... Listing all the string fields in the json.(I put only these for simplicity reason).
json_string_fields = ["ssid","type","userid","name","value","country","model"]
data_format = "json"
json_query= "events"
Basically declaring string fields in the telegraf.conf file would do it, but I couldn’t get all the fields that are subset in the json file, like for example what’s inside ( params or context ).
So finally, I get to parse fields with the same level of hierarchy as ssid, type, libVersion, but not the ones inside ( params, context, user).
Output : Screen2 ( attachment ).
OUTPUT
By curiosity, I tried to test the documentation’s example, in order to verify whether I get the same expected result, and the answer is no :/, I don’t get to parse the string field in the subset of the file.
The doc’s example below:
Input :
{
"a": 5,
"b": {
"c": 6,
"my_field": "description"
},
"my_tag_1": "foo",
"name": "my_json"
}
telegraf.conf
[[outputs.influxdb_v2]]
…
[[inputs.file]]
files = ["/home/mouhcine/json/influx.json"]
json_name_key = "name"
tag_keys = ["my_tag_1"]
json_string_fields = ["my_field"]
data_format = "json"
Expected Output : my_json,my_tag_1=foo a=5,b_c=6,my_field="description"
The Result I get : "my_field" is missing.
Output: Screen 1 ( attachement ).
OUTPUT
By the way, I use the influxdb cloud 2, and I apologize for the long description of this little problem, I would appreciate some help please :), Thank you so much in advance.
This answer clearly shows some examples of proto text parsing, but does not have an example for maps.
If a proto has:
map<int32, string> aToB
I would guess something like:
aToB {
123: "foo"
}
but it does not work. Does anyone know the exact syntax?
I initially tried extrapolating from an earlier answer, which led me astray, because I incorrectly thought multiple k/v pairs would look like this:
aToB { # (this example has a bug)
key: 123
value: "foo"
key: 876 # WRONG!
value: "bar" # NOPE!
}
That led to the following error:
libprotobuf ERROR: Non-repeated field "key" is specified multiple times.
Proper syntax for multiple key-value pairs:
(Note: I am using the "proto3" version of the protocol buffers language)
aToB {
key: 123
value: "foo"
}
aToB {
key: 876
value: "bar"
}
The pattern of repeating the name of the map variable makes more sense after re-reading this relevant portion of the proto3 Map documentation, which explains that maps are equivalent to defining your own "pair" message type and then marking it as "repeated".
A more complete example:
proto definition:
syntax = "proto3";
package myproject.testing;
message UserRecord {
string handle = 10;
bool paid_membership = 20;
}
message UserCollection {
string description = 20;
// HERE IS THE PROTOBUF MAP-TYPE FIELD:
map<string, UserRecord> users = 10;
}
message TestData {
UserCollection user_collection = 10;
}
text format ("pbtxt") in a config file:
user_collection {
description = "my default users"
users {
key: "user_1234"
value {
handle: "winniepoo"
paid_membership: true
}
}
users {
key: "user_9b27"
value {
handle: "smokeybear"
}
}
}
C++ that would generate the message content programmatically
myproject::testing::UserRecord user_1;
user_1.set_handle("winniepoo");
user_1.set_paid_membership(true);
myproject::testing::UserRecord user_2;
user_2.set_handle("smokeybear");
user_2.set_paid_membership(false);
using pair_type =
google::protobuf::MapPair<std::string, myproject::testing::UserRecord>;
myproject::testing::TestData data;
data.mutable_user_collection()->mutable_users()->insert(
pair_type(std::string("user_1234"), user_1));
data.mutable_user_collection()->mutable_users()->insert(
pair_type(std::string("user_9b27"), user_2));
The text format is:
aToB {
key: 123
value: "foo"
}
I need to send an input in the below format to an API, I'm running into problems producing the desired format which is below.
{ "application" :
"{\"attributes\":{\"type\":\"genesis__Applications__c\"},\"genesis__Days_Convention__c\":\"ACTUAL/ACTUAL\", \"RecordTypeID\":\"012260000004RHF\",
\"genesis__Interest_Calculation_Method__c\":\"Flat\",
\"genesis__Interest_Rate__c\":10.0000,
\"genesis__Loan_Amount__c\":22120.00,
\"Application_Completed__c\":false,
\"genesis__Payment_Frequency__c\":\"WEEKLY\",
\"genesis__Product_Type__c\":\"LOAN\", \"genesis__Term__c\":24,
\"genesis__Interest_Only_Period__c\":2,
\"genesis__Balloon_Payment__c\":100.00}", "relatedObjects" : "{
\"genesis__Account__c\" : {\"attributes\":
{\"type\":\"Account\"}, \"Name\":\"LONDON METALS HOLDINGS
LIMITED\" }, \"Loan_Product_Purpose__c\" : {\"attributes\":
{\"type\":\"Loan_Product_Purpose__c\"}, \"Name\":\"Equipment
Purchase\" }}" }
API is accepting above format as input.
Input specifications as shown.
We tried JSON builder that did not help instead producing the below format
which is not valid for API.
"\"{:attributes:{:type:\\"genesis__Applications__c\\"},
:genesis__Days_Convention__c:\\"ACTUAL/ACTUAL\\",
:RecordTypeID:\\"012260000004RHF\\",
:genesis__Interest_Calculation_Method__c:\\"Flat\\",
:genesis__Interest_Rate__c:10.0, :genesis__Loan_Amount__c:22120.0,
:Application_Completed__c:false,
:genesis__Payment_Frequency__c:\\"WEEKLY\\",
:genesis__Product_Type__c:\\"LOAN\\", :genesis__Term__c:24,
:genesis__Interest_Only_Period__c:2,
:genesis__Balloon_Payment__c:100.0}\""
edit1: Input Hash object
{:application=> {:attributes=>{:type=>"genesis__Applications__c"},
:genesis__Days_Convention__c=>"ACTUAL/ACTUAL",
:RecordTypeID=>"012260000004RHF",
:genesis__Interest_Calculation_Method__c=>"Flat",
:genesis__Interest_Rate__c=>10.0,
:genesis__Loan_Amount__c=>22120.0,
:Application_Completed__c=>false,
:genesis__Payment_Frequency__c=>"WEEKLY",
:genesis__Product_Type__c=>"LOAN", :genesis__Term__c=>24,
:genesis__Interest_Only_Period__c=>2,
:genesis__Balloon_Payment__c=>100.0}, :relatedObjects=>
{:genesis__Account__c=>{:attributes=>{:type=>"Account"},
:Name=>"LONDON METALS HOLDINGS LIMITED"},
:Loan_Product_Purpose__c=>{:attributes=>{:type=>"Loan_Product_Purpose__c"}, :Name=>"Equipment Purchase"}}}
How are you using JSON? It should work just fine
require 'json'
h = {:application=>
{:attributes=>{:type=>"genesis__Applications__c"},
:genesis__Days_Convention__c=>"ACTUAL/ACTUAL",
:RecordTypeID=>"012260000004RHF",
:genesis__Interest_Calculation_Method__c=>"Flat",
:genesis__Interest_Rate__c=>10.0,
:genesis__Loan_Amount__c=>22120.0,
:Application_Completed__c=>false,
:genesis__Payment_Frequency__c=>"WEEKLY",
:genesis__Product_Type__c=>"LOAN", :genesis__Term__c=>24,
:genesis__Interest_Only_Period__c=>2,
:genesis__Balloon_Payment__c=>100.0}, :relatedObjects=>
{:genesis__Account__c=>{:attributes=>{:type=>"Account"}, :Name=>"LONDON METALS HOLDINGS LIMITED"},
:Loan_Product_Purpose__c=>{:attributes=>{:type=>"Loan_Product_Purpose__c"}, :Name=>"Equipment Purchase"}}}
puts h.to_json
prints:
{"application":{"attributes":{"type":"genesis__Applications__c"},"genesis__Days_Convention__c":"ACTUAL/ACTUAL","RecordTypeID":"012260000004RHF","genesis__Interest_Calculation_Method__c":"Flat","genesis__Interest_Rate__c":10.0,"genesis__Loan_Amount__c":22120.0,"Application_Completed__c":false,"genesis__Payment_Frequency__c":"WEEKLY","genesis__Product_Type__c":"LOAN","genesis__Term__c":24,"genesis__Interest_Only_Period__c":2,"genesis__Balloon_Payment__c":100.0},"relatedObjects":{"genesis__Account__c":{"attributes":{"type":"Account"},"Name":"LONDON METALS HOLDINGS LIMITED"},"Loan_Product_Purpose__c":{"attributes":{"type":"Loan_Product_Purpose__c"},"Name":"Equipment Purchase"}}}
Ok, now I see the value of application and relatedObjects are strings (with json content). So try this instead:
require 'json'
application = {:attributes=>{:type=>"genesis__Applications__c"},
:genesis__Days_Convention__c=>"ACTUAL/ACTUAL",
:RecordTypeID=>"012260000004RHF",
:genesis__Interest_Calculation_Method__c=>"Flat",
:genesis__Interest_Rate__c=>10.0,
:genesis__Loan_Amount__c=>22120.0,
:Application_Completed__c=>false,
:genesis__Payment_Frequency__c=>"WEEKLY",
:genesis__Product_Type__c=>"LOAN", :genesis__Term__c=>24,
:genesis__Interest_Only_Period__c=>2,
:genesis__Balloon_Payment__c=>100.0}
relatedObjects = {:genesis__Account__c=>{:attributes=>{:type=>"Account"}, :Name=>"LONDON METALS HOLDINGS LIMITED"},
:Loan_Product_Purpose__c=>{:attributes=>{:type=>"Loan_Product_Purpose__c"}, :Name=>"Equipment Purchase"}}
h = {:application=> application.to_json,
:relatedObjects=> relatedObjects.to_json}
puts h.to_json
I am trying to plot a graph using highcharts in Flask. I have no problems when I give the data in the code itself. But when I retrieve the data from the database, it returns with a , in the end like
[(72,),(70.5,),(78.8,),(73,),(76,),(75,),]
So, this is not passing the data to the graph and I have an empty space on the webpage.
This is the code I have used:
views.py
#control.route("/")
def index(chartID = 'chart_ID', chart_type = 'line', chart_height = 350):
chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
series = [{"data": [tempg()]}]
title = {"text": 'My Title'}
xAxis = {"title": {"text": 'xAxis Label'}}
yAxis = {"title": {"text": 'yAxis Label'}}
return render_template('control/index.html', uptime=GetUptime(), chartID=chartID, chart=chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
def tempg():
tempgrs = [tempg for tempg in Temperature.query.with_entities(Temperature.tempft).all()]
return tempgrs
Is it because of the extra comma at the end, that i'm not able to get the chart or is it any other coding fault.
Thanks in Advance.