I have created a query parameter with a default integer 0 value in RAML and in Exchange this value not displayed. Could anyone help with it?
Example RAML
uriParameters:
page:
required: true
displayName: page
description: page
type: integer
default: 0
example:
0
size:
required: true
displayName: size
description: size
type: integer
default: 100
example:
100
Result:
It seems to be a bug with the API Console when the default/example is set to 0. If you change the default to a non-zero value, then the API Console from within the API Designer or the Exchange displays the value.
Related
I need help creating a sparkline chart for an example data as below:
name
timestamps
test
action
try 1
2022-11-16 22:39:35.653819+00:00
TRUE
TRUE
try 2
2022-11-16 22:39:33.171203+00:00
TRUE
TRUE
try 1
2022-11-16 22:39:30.699472+00:00
FALSE
TRUE
try 4
2022-11-16 22:39:27.711734+00:00
TRUE
FALSE
Let's say I am only trying to create a sparkline chart for try 1 against the timestamps.
What I want the chart to show is:
If test and action is TRUE and TRUE then for that timestamp Try 1 value is 2
If test and action is TRUE and FALSE then for that timestamp Try 1 value is 1
If test and action is FALSE and FALSE then for that timestamp Try 1 value is 0
I don't want to 'code' this into the google sheet as the data uploaded will be refreshed automatically and all my code will be gone when the data is refreshed.
Is there anyway I can code this into the sparkline chart itself on google data studio?
I tried creating a field in the metric section of the sparkline chart but it gives a system error.
hopefully this should get you started.
fix the timestamp to be studio-compatible
PARSE_DATETIME("%F %H:%M:%E*S",LEFT_TEXT(timestamps,26))
get the value score from test and action
CASE WHEN action='TRUE' THEN 1 ELSE 0 END+CASE WHEN test='TRUE' THEN 1 ELSE 0 END
you can use both these calculated fields as dimension and metric for spark chart.
lastly you can apply a filter to chart to see just the 'try 1' score.
Is it possible to define an array that can not contain null?
I'm compiling it to Java with Open API 3.0
For example for this
A:
type: array
minItems: 1
items:
$ref: "#/components/schemas/B"
B:
type: string
pattern: ^[a-z]+$
I consider [null] or ["abc",null] invalid
Thanks in advance
We have a rest API that is written in Java (hosted in Wildfly). Our service is running in kubernetes (GKE). We want to leverage Cloud Endpoints to track usage and responsiveness of our API. The API is not new, we have been shipping software that interacts with it for years. It is also quite large (thousands of public methods). We have Swagger documentation for our API, and have no validation errors. When I try to deploy our Swagger using:
gcloud beta service-management deploy swagger.yaml
It is not successful. I get the following error repeated 237 times:
ERROR: unknown location: http: body field path 'body' must be a non-repeated message.
I have tracked it down to 237 methods that include a json array in a body parameter. In our API these are methods that either accept or return a list of objects.
Is there any way I can get this accepted by service-management deploy? Changing our API isn't an option, but we would really like to be able to use endpoints.
For example, this method signature:
#PUT
#Path ("/foobars/undelete")
#Consumes (MediaType.APPLICATION_JSON)
#Produces (MediaType.APPLICATION_JSON)
#ApiOperation (value = "Undelete foobars")
#ApiResponses (value =
{
#ApiResponse (
code = 200,
message = "foobars undeleted",
response = FooBar.class,
responseContainer = "List"
) , #ApiResponse (
code = 206,
message = "Not all foobars undeleted",
response = FooBar.class,
responseContainer = "List"
) , #ApiResponse (
code = 410,
message = "Not found"
) , #ApiResponse (
code = 500,
message = "Server Error"
)
})
public Response undeleteFooBars (#ApiParam (value = "FooBar ID List") List<UUID> entityIds)
generates this swagger snippet:
"/foobars/undelete":
put:
tags:
- foo
summary: Undelete FooBars
description: ''
operationId: undeleteFooBars
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: FooBar ID List
required: false
schema:
type: array
items:
type: string
format: uuid
responses:
'200':
description: Foo Bars undeleted
schema:
type: array
items:
"$ref": "#/definitions/FooBar"
'206':
description: Not all FooBars undeleted
schema:
type: array
items:
"$ref": "#/definitions/FooBar"
'410':
description: Not found
'500':
description: Server Error
I have had the exact same problem with Endpoints, where it does not seem to think that passing an array of objects is valid as a body parameter. I worked around this by just using a generic object and a decent description. The description will not programatically fix anything, but using a generic object allows Endpoints to work and the description gives information to the consumer of the API for what is expected.
parameters:
- in: body
name: body
description: Array of FooBar objects
required: false
schema:
type: object
This seems like an oversight on the part of the Endpoints team IMHO as using an array of objects in the body fits fine within the OpenApi spec and works with tools like http://editor.swagger.io/
Edit: I should also add that it is generally bad practice to use just a raw array as a request body or response body as it can cause a contract breaking change if additional properties are desired in the future, like say a count or pagination information.
If this is an existing API and you are just documenting the existing contract, then this solution will work to get the job done, but if you are designing a new API, then a better definition would be:
parameters:
- in: body
name: body
description: All the FooBar objects
required: false
schema:
type: object
properties:
items:
type: array
items:
$ref: '#/definitions/FooBarResource'
Since this could later be extended to add additional properties like
parameters:
- in: body
name: body
description: All the FooBar objects
required: false
schema:
type: object
properties:
count:
type: integer
description: The total count of resources
callbackUrl:
type: string
description: The URL to trigger once creation is complete
items:
type: array
items:
$ref: '#/definitions/FooBarResource'
description: The resources to create
You can do better than a plain object. Yyou can specify an array as the the value of an object with a single key. This way you preserve your type information:
parameters:
- description: "Your items to add"
in: body
name: listings
required: true
schema:
type: object
properties:
payload:
type: array
maxItems: 1000
minItems: 1
$ref: "#/definitions/listing"
It's ugly but at least it documents whatever the model you are passing in should look like.
I have this schema
var StuffSchema = new mongoose.Schema({
_id: { type: String, required: true, unique: true },
name: { type: String, required: true }
});
mongoose.model('Stuff', StuffSchema);
Works fine.
Now I need to add another schema "Cargo" containing this
mystuff: { type:[String], ref: 'Stuff', required:true},
that is, I want mystuff to contain array of ids of Stuff, but this fails with validation error when running this code
mongoose.model('Cargo').create( some data...)
if I use an empty array for the mystuff field.
It seems to work if I change the Cargo schema to
mystuff: { type:[String], ref: 'Stuff'},
but I want the mystuff field to be required and allow empty arrays
What can I do to make this happen?
Empty arrays are created by default (see also this). The attribute required: true requires the array to have at least one element in it (source code). You can remove that attribute to get your desired behavior.
(Aside, mongoose assigns a default _id field with the type ObjectId to all schemas. Declaring it is unnecessary, and using a string is not typical, although certainly allowed.)
Edit Nov 2017: This is a candidate change in Mongoose 5. See https://github.com/Automattic/mongoose/issues/5139.
95% of my fields for a form I have use a custom validator -> hence I include it as apart of my defaults config of the container.
However, for the remaining 5% of fields, I want to use the built-in validation. Is there a way to manually specify using the default validator for a given field type?
Currently I try,
{
name: 'normalNumberField',
xtype: 'numberfield',
validator: Ext.form.field.Number.validate,
...
}
but I'm getting an error that Ext.form is undefined (why? I clearly have a reference to Ext ... )
The validator is not specified by default. Number field validation occurs in multiple steps (this is taken from the ExtJS docs):
Field specific validator
A validator offers a way to customize and reuse a validation specification. If a field is configured with a validator function,
it will be passed the current field value. The validator function
is expected to return either:
Boolean true if the value is valid (validation continues).
a String to represent the invalid message if invalid (validation halts).
Basic Validation
If the validator has not halted validation, basic validation proceeds as follows:
allowBlank : (Invalid message = blankText)
Depending on the configuration of allowBlank, a
blank field will cause validation to halt at this step and return
Boolean true or false accordingly.
minLength : (Invalid message = minLengthText)
If the passed value does not satisfy the minLength
specified, validation halts.
maxLength : (Invalid message = maxLengthText)
If the passed value does not satisfy the maxLength
specified, validation halts.
Preconfigured Validation Types (VTypes)
If none of the prior validation steps halts validation, a field
configured with a vtype will utilize the corresponding
Ext.form.field.VTypes validation function. If invalid, either the
field's vtypeText or the VTypes vtype Text property will be used
for the invalid message. Keystrokes on the field will be filtered
according to the VTypes vtype Mask property.
Field specific regex test
If none of the prior validation steps halts validation, a field's configured regex test will be processed. The
invalid message for this test is configured with regexText
Number field specific validation
The additional validations run test that the value is a number, and
that it is within the configured min and max values.
So, long story short, to override your validator that you specified in defaults, you can simply use a validator which always returns true.
{
name: 'normalNumberField',
xtype: 'numberfield',
validator: function(){ return true; },
...
}