Rapidjson regex validation giving unexpected result - c++

I'm using the same example from examples/schemavalidator.cpp.
My schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "SampleMessage",
"properties": {
"id": {
"type": "string"
},
"regexfield": {
"type": "string",
"pattern": "^[\\x00-\\x7F]*$"
},
"status": {
"type": "string",
"enum": [
"VALID",
"INVALID"
]
}
},
"required": [
"regexfield",
"status"
]
}
My message;
{
"id": "w10ooe",
"regexfield": "w10ooe¼",
"status": "VALID"
}
Expected result:
validation fail for pattern
Actual result
Input JSON is valid.
As you can see, the pattern is for validating if the regexfield contains only ASCII characters. However, the validation returns successful even when the field has a non-ascii value. The same regex gives expected result when checking with regex101.com. can you please explain how to address this issue and a workaround?

The default regex engine does not support character escapes of the form \xXX (note the lack of a x option in this switch).
You can switch to std::regex (which does support this) by setting both of the following preprocessor symbols:
RAPIDJSON_SCHEMA_USE_INTERNALREGEX=0
RAPIDJSON_SCHEMA_USE_STDREGEX=1
You can either #define these macros at the top of your file or set them as a preprocessor flag in your build system (-D...)

Related

How can I get a partial response for Method: instances.aggregatedList Compute API in GCP

I am trying to get specific response from Compute API method instances.aggregatedList by setting the fields request param as per https://cloud.google.com/resource-manager/docs/performance#partial-response
But I am getting 400 BAD REQUEST.
Is there a sample which I can refer for getting partial response for aggregated methods?
If you use the following CURL command:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) "https://compute.googleapis.com/compute/v1/projects/[CHANGE-FOR-YOUR-PROJECT-ID]/aggregated/instances?maxResults=1"
You'll notice that the result will have a similar form to:
{
"id": "projects/[PROJECT-ID]/aggregated/instances",
"items": {
"zones/us-central1-a": {
"instances": [
{
"id": "[INSTANCE-ID]",
"creationTimestamp": "2020-09-21T06:22:21.604-07:00",
"name": "instance-1",
"description": "",
"tags": {
"items": [
"http-server",
"https-server"
],
"fingerprint": "XXXXXX"
},
"machineType": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/zones/us-central1-a/machineTypes/e2-medium",
"status": "RUNNING",
"zone": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/zones/us-central1-a",
"canIpForward": false,
"networkInterfaces": [
{
"network": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/global/networks/default",
"subnetwork": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/regions/us-central1/subnetworks/[SUBNETWORK_NAME]",
"networkIP": "10.8.0.13",
"name": "nic0",
... with a lot more fields
As you can see the result is a little bit different as the response body explained in the documentation:
{
"id": string,
"items": [
{
"scopeName": string,
"instances": [
{
"id": string,
"creationTimestamp": string,
"name": string,
"description": string,
"tags": {
"items": [
string
],
"fingerprint": string
},
"machineType": string,
"status": enum,
"statusMessage": string,
"zone": string,
"canIpForward": boolean,
"networkInterfaces": [
{
"network": string,
"subnetwork": string,
"networkIP": string,
"ipv6Address": string,
"name": string,
.... with a lot more fields
Notice that if you compare both results, the actual response that you receive has an additional "zones/us-central1-a": field before the instances: field that I believe is causing the behavior you experience.
If you are interested in working with partial resources and get only some particular fields on the response you simply need to respect the syntax rules explained on the documentation you've shared and use the escape characters accordingly on your query parameters.
E.g. if you are only interested in getting the id of your project as well as the instances' name, machineType and status I tested the following curl command from the Cloud Shell with my GCP project and it worked without issues:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) "https://compute.googleapis.com/compute/v1/projects/[PROJECT-ID]/aggregated/instances?fields=id,items/zones%2Finstances(name,machineType,status)"
where I see that something similar to the following is returned:
{
"id": "projects/[PROJECT-ID]/aggregated/instances",
"items": {
"zones/us-central1-a": {
"instances": [
{
"name": "instance-1",
"machineType": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/zones/us-central1-a/machineTypes/e2-medium",
"status": "RUNNING"
},
{
"name": "instance-2",
"machineType": "https://www.googleapis.com/compute/v1/projects/[PROJECT-ID]/zones/us-central1-a/machineTypes/e2-medium",
"status": "TERMINATED"
}
]
}
}
}

Regex workaround infinite repetition inside lookbehind

I'm trying to match the text value_to_match when preceeded by a line "attribute": "type" and preceeded (at some point) by a "marketTypeId": 123456789 in Intellij regex search.
In the following text the search should match value_to_match only.
{
"marketTypeId": 123456789,
"description": "Market description",
"periodType": "MATCH",
"periodInstance": 1,
"feedMappingData": [
{
"outcomeIdFeedcodeMap": {
"2": "123456789001",
"1": "123456789002"
},
"conditions": [
{
"element": "Market",
"attribute": "type",
"condition": "EQUALS",
"value": "value_to_match"
},
{
"element": "Market",
"attribute": "traded_pre_match",
"condition": "EQUALS",
"value": "true"
}
]
},
{
"marketTypeId": 12121212,
"description": "Market description",
"periodType": "MATCH",
"periodInstance": 1,
"feedMappingData": [
{
"outcomeIdFeedcodeMap": {
"2": "12121212001",
"1": "12121212002"
},
"conditions": [
{
"element": "Market",
"attribute": "type",
"condition": "EQUALS",
"value": "value_NOT_to_match"
},
{
"element": "Market",
"attribute": "traded_pre_match",
"condition": "EQUALS",
"value": "true"
}
]
},
I've been trying to use lookbehind with the conditions but it seems Intellij regex search does not support infinite repetition inside lookbehind.
Is there any workaround for situations like this?
Using Intellij and positive lookbehind
The regex used in Intellij:
(?s)(?<="marketTypeId":\s123456789,.{1,500}"attribute":\s"type",.{1,100}"value":\s")value_to_match(?=")
Note:
Dotall mode can also be enabled via the embedded flag expression (?s)
Read more about this flag expression and regex lookarounds in reference:
https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html
Used Intellij version 2020.2
Picture of Intellij and match:
More can be read about Intellij and matching here:
Is there a way with Regex to grab the first word and replace a quoted section?

Creating an eBay fulfilment policy. ("Please select a valid postage service.")

After a day of work with Postman, I have managed to reduce the number of errors down to 1. No idea how to get past it.
Definitely not an authorisation problem. I've been making lots of authorised calls.
URI:
POST https://api.ebay.com/sell/account/v1/fulfillment_policy
Body:
{
"categoryTypes": [
{
"name": "ALL_EXCLUDING_MOTORS_VEHICLES"
}
],
"freightShipping": "false",
"globalShipping": "false",
"handlingTime": {
"unit": "DAY",
"value": "1"
},
"localPickup": "true",
"marketplaceId": "EBAY_AU",
"name": "100 grams",
"shippingOptions": [
{
"costType": "CALCULATED",
"optionType": "DOMESTIC",
"shippingServices": [
{
"shippingCarrierCode": "Australia Post",
"shippingServiceCode": "AU_Regular"
}
]
}
]
}
Output:
{
"errors": [
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[0].shippingService"
}
]
}
]
}
Things I've Tried:
Deleting "shippingOptions": [...] (and everything inside the []s) got rid of the errors and resulted in the successful creation of a new fulfillment policy. However, I wanted to include shipping options in my call.
shippingCarrierCode doesn't seem to do anything. I've changed it to all sorts of sensible and non sensible things, including deleting it entirely. No impact on the output.
Changing shippingServiceCode to anything non-standard (eg "shippingServiceCode": "potato") results in getting the exact same error, but twice instead of once. (See below) How can I get the same error twice with only one shipping option?
Including a domestic and international option, I get the same error twice also. (Same output as below, except the second DomesticItemShippingService[1].shippingService is instead DomesticItemShippingService[0].shippingService)
Making an international option AND a domestic option, BOTH with silly service names results in 3 errors. (I was expecting 4.)
Code:
{
"errors": [
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[0].shippingService"
}
]
},
{
"errorId": 20403,
"domain": "API_ACCOUNT",
"category": "REQUEST",
"message": "Invalid .",
"longMessage": "Please select a valid postage service.",
"inputRefIds": [
"service"
],
"parameters": [
{
"name": "XPATH",
"value": "DomesticItemShippingService[1].shippingService"
}
]
}
]
}
What did I do wrong this time?
I did get an answer to my question. Not here, even though I sent them the link here, but I got the answer (eventually) through official eBay channels.
I'll post that answer here for everyone. I was thinking of adding correct stackoverflow formatting, but decided it would be better to leave the correct answer untouched from the original.
Hello Jonathon ,
Ignore my last message and Apologize for the confusion.
Here is the reason why you are getting the error:
You have to set "localPickup": "false", refer doc for your help:
https://developer.ebay.com/api-docs/sell/account/resources/fulfillment_policy/methods/createFulfillmentPolicy#request.localPickup
And you will get response as:
{ "name": "100 grams", "marketplaceId": "EBAY_AU",
"categoryTypes": [
{
"name": "ALL_EXCLUDING_MOTORS_VEHICLES",
"default": true
} ], "handlingTime": {
"value": 1,
"unit": "DAY" }, "shippingOptions": [
{
"optionType": "DOMESTIC",
"costType": "CALCULATED",
"shippingServices": [
{
"sortOrder": 1,
"shippingCarrierCode": "Australia Post",
"shippingServiceCode": "AU_Regular",
"freeShipping": false,
"buyerResponsibleForShipping": false,
"buyerResponsibleForPickup": false
}
],
"insuranceOffered": false,
"insuranceFee": {
"value": "0.0",
"currency": "AUD"
}
} ], "globalShipping": false, "pickupDropOff": false, "freightShipping": false, "fulfillmentPolicyId": "6104871000",
"warnings": [] }
Let us know if you need further assistance!!!
Best Regards, eBay Developer Support
Check them out here. Make sure you have all the required fields.
pickupDropOff
shippingOptions.shippingServices.shipToLocations.regionIncluded

Avro schema is not valid

I am trying to save this Avro schema. I get the message that the schema is not valid. Can someone share why its not valid?
{
"type": "record",
"name": "Interactions",
"namespace": "com.amazonaws.personalize.schema",
"fields": [
{
"name": "InvoiceNo",
"type": "int"
},
{
"name": "StockCode",
"type": "int"
},
{
"name": "Description",
"type": "long"
},
{
"name": "Quantity",
"type": "string"
},
{
"name": "InvoiceDate",
"type": "string"
},
{
"name": "UnitPrice",
"type": "string"
},
{
"name": "CustomerID",
"type": "string"
},
{
"name": "CustomerID",
"type": "string"
},
{
"name": "Country",
"type": "string"
}
],
"version": "1.0"
}
I'm a bit late to the party here but I think your issue is twofold.
(1) You haven't reformatted your columns to use the field names that Personalize want to see. Required fields for Interactions are USER_ID, ITEM_ID, and TIMESTAMP. (With TIMESTAMP being in Unix Epoch format.) See reference here.
(2) The five specified fields for Interactions are USER_ID, ITEM_ID, TIMESTAMP, EVENT_TYPE, and EVENT_VALUE. If you do include more fields, they will be considered metadata fields and you can only include up to 5 metadata fields. If you do include them AND the data type is "String" you, they must be specified as "categorical". See page 35 of the Personalize Developer's Guide for an example.
Hope this helps!

How to extract all the Id's value from the Json given below using Regular expression extractor or any other Extractor(Xpath, Beanshell etc)

[
{
"id": 1,
"name": "MetaOperationN1",
"type": "Operation"
},
{
"id": 2,
"name": "GreenOper2",
"type": "Operation"
},
{
"id": 3,
"name": "GreenOper4",
"type": "Operation"
},
{
"id": 4,
"name": "GreenOper5",
"type": "Operation"
},
{
"id": 5,
"name": "GreenOper6",
"type": "Operation"
},
{
"id": 6,
"name": "GreenOper7",
"type": "Operation"
},
{
"id": 7,
"name": "GreenOper8",
"type": "Operation"
},
{
"id": 8,
"name": "GreenOper9",
"type": "Operation"
},
{
"id": 9,
"name": "GreenOper10",
"type": "Operation"
},
{
"id": 10,
"name": "GreenOper11",
"type": "Operation"
}
]
Using Regular Expression Extractor with following configuration:
Reference Name: anything meaningful, i.e. ID
Regular Expression: "id": (\d+),
Template: $1$
Match No.: -1
Using JSON Path Extractor (available via JMeter Plugins)
Reference Name: whatever you want, i.e. ID
JSONPath Expression: $..id
In both cases you'll get IDs list as:
ID_1=1
ID_10=10
ID_2=2
ID_3=3
ID_4=4
etc.
For more information on installing JSON Path Extractor and regarding JSON Path language check out Using the XPath Extractor in JMeter (scroll down to "Parsing JSON")
Dont use regex for parsing json docs.. easily done by referring this
If you want to use regex.. go ahead:
"id": (\d+)
And extract out ids with $1