i have a POST method REST API with request body as json, which has
{
"name": "5-Star",
"vendor": "Cadbury",
"description": "More almonds with chocolate",
"price": 5,
"primaryImage": "http://cdn.shopify.com/s/files/1/0219/2362/products/Front_a8743e5a-c6a3-4042-9cb2-834332af77d5_large.jpg?v=1377892407",
"variants":
[
{ "name" : "size",
"type" : null,
"defaultValue" : "8",
"values" :[ "8","8.5"]
},
{ "name" : "color",
"type" : "COLOR",
"values" :[ "Milky White","Chocolate"]
}
],
"tags":
[ "Chocolate", "Cadbury" ]
}
I need to know how to set parameter for variants in the above json in swagger 2.0 editor, also referenced documentation and petstore sample from swagger but i cant find any clue.
Maybe this will get you started:
properties:
... // other stuff
variants:
type: array
description: variants description
items:
properties:
name:
type: string
description: the name
... // the rest
Related
I'm retrieving data from Microsoft workbook/excel file's table.
Workbook's table has date-of-birth column which has date format.
While retrieving values using Microsoft graph's table api it returns dates as some integer value.
API i'm using:
https://graph.microsoft.com/v1.0/me/drive/root:/book.xlsx:/workbook/tables/table4/columns
Microsoft graph API reference : https://learn.microsoft.com/en-us/graph/api/table-list-columns?view=graph-rest-1.0&tabs=http
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('<user_id>')/drive/root/workbook/tables('table4')/columns",
"value": [
{
"#odata.id": "/users('<user_id>')/drive/root/workbook/tables(%27%7BF44C7573-9BBE-46F3-B0BE-C5607762D2AB%7D%27)/columns(%271%27)",
"values": [
[
"Name"
],
[
"Student 1"
],
[
"Student 2"
]
],
"id": "1",
"index": 0,
"name": "Name"
},
{
"#odata.id": "/users('<user_id>')/drive/root/workbook/tables(%27%7BF44C7573-9BBE-46F3-B0BE-C5607762D2AB%7D%27)/columns(%273%27)",
"values": [
[
"DOB"
],
[
35339
],
[
34249
]
],
"id": "3",
"index": 1,
"name": "DOB"
}
]
}
Original values are
Is there any way to get date values in its original format
The endpoint you are using
GET /me/drive/root:/book.xlsx:/workbook/tables/table4/columns
returns workbookTableColumn resource type which has only information about raw values without information about data type and formatting.
You can use id or name of workbookTableColumn and call dataBodyRange endpoint
GET /me/drive/root:/{item-path}:/workbook/tables/{id|name}/columns/{columnId|columnName}/dataBodyRange
GET /me/drive/root:/book.xlsx:/workbook/tables/{id|name}/columns/{columnId|columnName}/dataBodyRange
which returns range resource type.
Range resource type has property text which represents text values of the specified range.
...
"text": [
[
"09.06.2022"
],
[
""
]
],
...
I am trying to learn avro and have a question in schema.
Some documents say
{
"name": "userid",
"type" : "string",
"logicalType" : "uuid"
},
And some say
{
"name": "userid",
"type" : {
"type" : "string",
"logicalType" : "uuid"
}
},
Which one is right? Or are they same?
Thank you!
I ran variants of your schemas with the avro tools "random" command ( aliased as avro below). It tries to generate a random value for a schema.
A schema with just this type using the nested type syntax to specify logicalType is rejected:
avro random --schema '{ "name": "userid", "type" : { "type": "string", "logicalType" : "uuid" } }' -
[...] No type: {"name":"userid","type":{"type":"string","logicalType":"uuid"}}
However, it works when putting the logicalType next to type:
avro random --schema ' { "type" : "string", "logicalType" : "uuid" }' -
[...] Objavro.schemaL{"type":"string","logicalType":"uuid"}avro.codecdeflate}�j�U�.�\�o���
Now, when we use it in a record, we get a warning when putting logicalType next to type:
avro random --schema '{ "type": "record", "fields": [ { "type" : "string", "logicalType" : "uuid", "name": "f"} ] , "name": "rec"}' -
[...] WARN avro.Schema: Ignored the rec.f.logicalType property ("uuid"). It should probably be nested inside the "type" for the field.
Objavro.schema�{"type":"record","name":"rec","fields":[{"name":"f","type":"string","logicalType":"uuid"}]}avro.codecdeflate��w�9�9�n�s�
The nested syntax is accepted without a warning:
avro random --schema '{ "type": "record", "fields": [ { "type" : { "type": "string", "logicalType" : "uuid" } , "name": "f"} ] , "name": "rec"}' -
�w<��qcord","name":"rec","fields":[{"name":"f","type":{"type":"string","logicalType":"uuid"}}]}avro.codecdeflate8��t
Further if we look at logicaltypes inside arrays:
avro random --count 1 --schema ' { "type": "array", "items": { "type" : "string", "logicalType" : "uuid" , "name": "f"} , "name": "farr" } ' -
[... random bits]
While the nested version fails:
avro random --count 1 --schema ' { "type": "array", "items": {"type": { "type" : "string", "logicalType" : "uuid" , "name": "f"} } , "name": "farr" } ' -
[...] No type: {"type":{"type":"string","logicalType":"uuid","name":"f"}}
It appears that if a logicalType is a type of a field in a record, you need to use the nested syntax.
Otherwise you need to use non-nested syntax.
Problem: I want to reuse a definiton. Once directly and once inside an object. The following code works but the validator from http://editor.swagger.io/#/ is saying "Not a valid response definition" and pointing to the line "200".
Do I really have to define Account twice? Or is this an issue form the validator?
* responses:
* 200: <---- ERROR POINTING HERE
* description: Updated account
* schema:
* type: object
* properties:
* data:
* type: object
* properties:
* account:
* schema:
* $ref: '#/definitions/Account'
The definition itself:
"Account" : {
"type" : "object",
"required": [
"id", "username", "lastname", "firstname", "traderid", "customerid", "company", "validated"
],
"properties": {
"id": {
"type": "string"
},
"username" : {
"type": "string"
},
"lastname" : {
"type": "string"
},
"firstname" : {
"type": "string"
},
"traderid" : {
"type": "string"
},
"customerid" : {
"type": "string"
},
"company" : {
"type": "string"
},
"validated" : {
"type": "boolean"
}
},
"example" : {
"id": "57790fdde3fd3ed82681f39c",
"username": "yuhucebafu",
"validated": false,
"customerid": "57790fdce3fd3ed82681f39a"
}
},
The problem is with the use of schema in the account property.
200:
description: Updated account
schema:
type: object
properties:
data:
type: object
properties:
account:
schema: # <-- Problem is here.
$ref: '#/definitions/Account'
Here's the corrected response definition:
200:
description: Updated account
schema:
type: object
properties:
data:
type: object
properties:
account:
$ref: '#/definitions/Account'
The property name "schema" is only used as a top-level property in Swagger's response object, or a parameter object where in is set to "body".
Once you've started specifying your schema, everything within that structure mostly follows standard JSON Schema, which is highly recursive. For example:
Within an object schema, the value of each properties/[propertyName] is a schema.
Within an array schema, the value of items is a schema.
The value of each /definitions/[name] is a schema.
The value of each array element within allOf, anyOf, or oneOf is a schema.
The value of additionalProperties can be a schema (or a boolean value).
...
You get the idea. JSON Schema doesn't use the property name schema for all of these cases, because it would introduce a lot of noise in a language where practically "everything is a schema."
Can Adobe DTM read JSON such as:
<script type="application/json">
{
"analytics" : [{
"dataLayer" : [{
"tags" : [{
"adobeAnalytics" : true
}],
"pageInfo" : [{
"country" : "us",
"language" : "en",
"siteDescriptor" : "xxx",
"platform" : "web",
"domain" : "xxxxx"
}],
"activities" : [{
"eventType" : "xxxxx",
"eventCity" : "xxxxx",
"eventDate" : "xxxxx"
}]
]}
}]
}`
</script>
Previously I had this as a JavaScript object and created data elements in DTM to read the JS Object. However, due to constraints on the project, we can no longer do this as JavaScript. Is it possible to keep the same structure, add the 'type="application/json"' and keep everything else the same?
Thanks
No, at least not out of the box. You'd need to parse the JSON into a variable before being able to use it in DTM.
<script type="application/json" id="json-datalayer">
{
"analytics": [{
"dataLayer": [{
"tags": [{
"adobeAnalytics": true
}],
"pageInfo": [{
"country": "us",
"language": "en",
"siteDescriptor": "xxx",
"platform": "web",
"domain": "xxxxx"
}],
"activities": [{
"eventType": "xxxxx",
"eventCity": "xxxxx",
"eventDate": "xxxxx"
}]
}]
}]
}
</script>
Then within DTM you could do something similar to (very basic example)
JSON.parse(document.getElementById('json-datalayer').innerHTML)
As of this summer you can add the "AEM Context Hub Tool" and provide the custom JSON schema. This will enable DTM to read & monitor JSON.
Does anyone know how to define possible enum values in an OpenAPI 2.0 definition so that they will be displayed in the Model tab of Swagger UI? Example here has an enum option for the status property. How to do define such an enum in OpenAPI 2.0?
"enum" works like this in OpenAPI 2.0:
{
"in": "query",
"name": "sample",
"description": "a sample parameter with an enum value",
"type": "string",
"enum": [ "1", "2"],
"required": true
}
and in OpenAPI 3.0:
{
"in": "query",
"name": "sample",
"description": "a sample parameter with an enum value",
"schema": {
"type": "string",
"enum": [ "1", "2"]
},
"required": true
}
As you can see, there's a query parameter called sample of type string, and has an enum stating two possible values. In this case, the sample states the parameter is required, so the UI will not show an empty value as an option.
For a minimal working sample, try this:
{
"swagger": "2.0",
"info": {
"title": "title",
"description": "descriptor",
"version": "0.1"
},
"paths": {
"/sample": {
"post": {
"description": "sample",
"parameters": [
{
"in": "query",
"name": "sample",
"description": "a sample parameter with an enum value",
"type": "string",
"enum": [
"1",
"2"
],
"required": true
}
],
"responses": {
"200": {
"description": "Successful request."
}
}
}
}
}
}
To test it locally, you can declare a variable (for example spec) in your javascript, and pass it into the SwaggerUi object.
var spec = { ... };
window.swaggerUi = new SwaggerUi({
url: url,
spec: spec,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
...
The url parameter will be ignored in this case.
Eventually, the output looks like this:
Updating this with YAML syntax.
OpenAPI 2.0:
parameters:
- in: query
name: sample
description: a sample parameter with an enum value
type: string
enum:
- 1
- 2
required: true
OpenAPI 3.0:
parameters:
- in: query
name: sample
description: a sample parameter with an enum value
schema:
type: string
enum:
- 1
- 2
required: true
This should work:
{
"name": "bookingType",
"in": "path",
"type": "array",
"items": {
"enum": [
"packages", "accommodations"
]
},
"description": "lorem ipsum"
}
Reference https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#itemsObject
This isn't the exact answer, but it might work for you until they add this functionality.
Simply declare the property like so
"MyObject":{
"properties":{
"MyEnum":{
"type":"Value1 or Value2 or Value3"
}
}
}
Your ModelSchema will show {}, but The Model will show MyEnum(Value1 or Value2 or Value3, optional)