Create TemplatePlaceholders

This commit is contained in:
Daniel García Aubert 2018-08-23 18:24:17 +02:00
parent e3f6d4e9fd
commit 409170f661

View File

@ -851,34 +851,9 @@ components:
type: string
description: when method is set to token, the values listed here allow you to instantiate the Named Map. See this [example](http://docs.carto.com/faqs/manipulating-your-data/#how-to-create-a-password-protected-named-map) for how to create a password-protected map.
placeholders:
type: object
description: >
Variables that can be placed in layergroup's definition (SQL or CartoCSS of any layer). Placeholders need to be defined with a `type` and a default value for MapConfigs. See details about defining a MapConfig `type` for [Layergroup configurations](http://docs.carto.com/carto-engine/maps-api/mapconfig/#layergroup-configurations).
Valid placeholder names start with a letter and can only contain letters, numbers, or underscores. They have to be written between the `<%=` and `%>` strings in order to be replaced inside the Named Maps API.
```javascript
<%= my_color %>
````
The set of supported placeholders for a template need to be explicitly defined with a specific type, and default value, for each placeholder.
The placeholder type will determine the kind of escaping for the associated value. Supported types are:
Types | Description
--- | ---
sql_literal | internal single-quotes will be sql-escaped
sql_ident | internal double-quotes will be sql-escaped
number | can only contain numerical representation
css_color | can only contain color names or hex-values
Placeholder default values will be used whenever new values are not provided as options, at the time of creation on the client. They can also be used to test the template by creating a default version with new options provided.
When using templates, be very careful about your selections as they can give broad access to your data if they are defined loosely.
example: <%= my_color %>
$ref: '#/components/schemas/TemplatePlaceholders'
layergroup:
type: object
description: The layergroup configurations, as specified in the template. See [MapConfig File Format](http://docs.carto.com/carto-engine/maps-api/mapconfig/) for more information
$ref: '#/components/schemas/MapConfig'
view:
type: object
description: Extra keys to specify the view area for the map. It can be used to have a static preview of a Named Map without having to instantiate it. It is possible to specify it with `center` + `zoom` or with a bounding box `bbox`. Center+zoom takes precedence over bounding box. Also it is possible to choose which layers are visible or not with `preview_layers` indicating its visibility by layer index or id (visible by default).
@ -917,6 +892,28 @@ components:
- auth
- placeholders
- layergroup
TemplatePlaceholders:
type: object
description: >
Variables that can be placed in layergroup's definition (SQL or CartoCSS of any layer). Placeholders need to be defined with a `type` and a default value for MapConfigs. See details about defining a MapConfig `type` for [Layergroup configurations](http://docs.carto.com/carto-engine/maps-api/mapconfig/#layergroup-configurations). Valid placeholder names start with a letter and can only contain letters, numbers, or underscores. They have to be written between the `<%=` and `%>` strings in order to be replaced inside the Named Maps API.
**Example**:```<%= my_color %>```
The set of supported placeholders for a template need to be explicitly defined with a specific type, and default value, for each placeholder. Placeholder default values will be used whenever new values are not provided as options, at the time of creation on the client. They can also be used to test the template by creating a default version with new options provided. When using templates, be very careful about your selections as they can give broad access to your data if they are defined loosely.
properties:
type:
type: string
enum: [sql_literal, sql_ident, number, css_color]
description: >
sql_literal: internal single-quotes will be sql-escaped
sql_ident: internal double-quotes will be sql-escaped
number: can only contain numerical representation
css_color: can only contain color names or hex-values
default:
type: 'string or number or hex-value'
required:
- type
- default
NamedMapResponse:
type: object
properties: