blob: bc46681d1cb72de953d80ed8c7d99499cdccb9d7 [file] [log] [blame]
ToineSiebelink98c07872021-04-20 17:33:09 +01001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
shivasubedi44beaa32021-09-13 15:16:30 +01003.. Copyright (C) 2021 Nordix Foundation
ToineSiebelink98c07872021-04-20 17:33:09 +01004
5.. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING
6.. _design:
7
8
9CPS Path
10########
11
12.. toctree::
13 :maxdepth: 1
14
15Introduction
16============
17
ToineSiebelinkf0527c52021-07-06 13:03:03 +010018Several CPS APIs use the CPS path (or cpsPath in Java API) parameter.
19The CPS path parameter is used for querying xpaths. CPS path is inspired by the `XML Path Language (XPath) 3.1. <https://www.w3.org/TR/2017/REC-xpath-31-20170321/>`_
ToineSiebelink98c07872021-04-20 17:33:09 +010020
21This section describes the functionality currently supported by CPS Path.
22
23Sample Data
24===========
25
26The xml below describes some basic data to be used to illustrate the CPS Path functionality.
27
28.. code-block:: xml
29
30 <shops>
31 <bookstore name="Chapters">
ToineSiebelinkf0527c52021-07-06 13:03:03 +010032 <bookstore-name>Chapters</bookstore-name>
33 <categories code="1" name="SciFi" numberOfBooks="2">
34 <books>
35 <book title="2001: A Space Odyssey" price="5">
36 <label>sale</label>
37 <label>classic</label>
38 <edition>1968</edition>
39 <edition>2018</edition>
40 </book>
41 <book title="Dune" price="5">
42 <label>classic</label>
43 <edition>1965</edition>
44 </book>
45 </books>
46 </categories>
47 <categories code="2" name="Kids" numberOfBooks="1">
48 <books>
49 <book title="Matilda" />
50 </books>
51 </categories>
ToineSiebelink98c07872021-04-20 17:33:09 +010052 </bookstore>
53 </shops>
54
ToineSiebelinkf0527c52021-07-06 13:03:03 +010055**Note.** 'categories' is a Yang List and 'code' is its key leaf. All other data nodes are Yang Containers. 'label' and 'edition' are both leaf-lists.
ToineSiebelink98c07872021-04-20 17:33:09 +010056
57General Notes
58=============
59
ToineSiebelinkf0527c52021-07-06 13:03:03 +010060- String values must be wrapped in quotation marks ``"`` (U+0022) or apostrophes ``'`` (U+0027).
ToineSiebelink98c07872021-04-20 17:33:09 +010061- String comparisons are case sensitive.
ToineSiebelinkf0527c52021-07-06 13:03:03 +010062- List key-fields containing ``\`` or ``@[`` will not be processed correctly when being referenced with such key values in absolute or descendant paths. This means such entries will be omitted from any query result. See `CPS-500 <https://jira.onap.org/browse/CPS-500>`_ Special Character Limitations of cpsPath Queries
ToineSiebelink98c07872021-04-20 17:33:09 +010063
ToineSiebelinkf0527c52021-07-06 13:03:03 +010064Query Syntax
65============
ToineSiebelink98c07872021-04-20 17:33:09 +010066
ToineSiebelinkf0527c52021-07-06 13:03:03 +010067``( <absolute-path> | <descendant-path> ) [ <leaf-conditions> ] [ <text()-condition> ] [ <ancestor-axis> ]``
ToineSiebelink98c07872021-04-20 17:33:09 +010068
ToineSiebelinkf0527c52021-07-06 13:03:03 +010069Each CPS path expression need to start with an 'absolute' or 'descendant' xpath.
70
71absolute-path
72-------------
73
74**Syntax**: ``'/' <container-name> ( '[' <list-key> ']' )? ( '/' <containerName> ( '[' <list-key> ']' )? )*``
75
76 - ``container name``: Any yang container or list.
77 - ``list-key``: One or more key-value pairs, each preceded by the ``@`` symbol, combined using the ``and`` keyword.
78 - The above van repeated any number of times.
79
80**Examples**
81 - ``/shops/bookstore``
82 - ``/shops/bookstore/categories[@code=1]``
83 - ``/shops/bookstore/categories[@code=1]/book``
84
85**Limitations**
86 - Absolute paths must start with the top element (data node) as per the model tree.
87 - Each list reference must include a valid instance reference to the key for that list. Except when it is the last element.
88
89descendant-path
90---------------
91
92**Syntax**: ``'//' <container-name> ( '[' <list-key> ']' )? ( '/' <containerName> ( '[' <list-key> ']' )? )*``
93
94 - The syntax of a descendant path is identical to a absolute path except that it is preceded by a double slash ``//``.
95
96**Examples**
97 - ``//bookstore``
98 - ``//categories[@code=1]/book``
99 - ``//bookstore/categories``
100
101**Limitations**
102 - Each list reference must include a valid instance reference to the key for that list. Except when it is the last element.
103
104leaf-conditions
105---------------
106
107**Syntax**: ``<xpath> '[' @<leaf-name1> '=' <leaf-value1> ( ' and ' @<leaf-name> '=' <leaf-value> )* ']'``
108 - ``xpath``: Absolute or descendant or xpath to the (list) node which elements will be queried.
ToineSiebelink98c07872021-04-20 17:33:09 +0100109 - ``leaf-name``: The name of the leaf which value needs to be compared.
110 - ``leaf-value``: The required value of the leaf.
111
112**Examples**
113 - ``/shops/bookstore/categories[@numberOfBooks=1]``
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100114 - ``//categories[@name="Kids"]``
115 - ``//categories[@name='Kids']``
lukegleeson2b6d6872021-11-02 09:42:46 +0000116 - ``//categories[@code=1]/books/book[@title='Dune' and @price=5]``
ToineSiebelink98c07872021-04-20 17:33:09 +0100117
118**Limitations**
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100119 - Only the last list or container can be queried leaf values. Any ancestor list will have to be referenced by its key name-value pair(s).
120 - Multiple attributes can only be combined using ``and``. ``or`` and bracketing is not supported.
121 - Only leaves can be used, leaf-list are not supported.
122 - Only string and integer values are supported, boolean and float values are not supported.
ToineSiebelink98c07872021-04-20 17:33:09 +0100123
124**Notes**
puthuparambil.aditya05316072021-04-23 12:52:09 +0100125 - For performance reasons it does not make sense to query using key leaf as attribute. If the key value is known it is better to execute a get request with the complete xpath.
ToineSiebelink98c07872021-04-20 17:33:09 +0100126
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100127text()-condition
128----------------
ToineSiebelink98c07872021-04-20 17:33:09 +0100129
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100130The text()-condition can be added to any CPS path query.
131
132**Syntax**: ``<cps-path> ( '/' <leaf-name> '[text()=' <string-value> ']' )?``
133 - ``cps-path``: Any CPS path query.
134 - ``leaf-name``: The name of the leaf or leaf-list which value needs to be compared.
135 - ``string-value``: The required value of the leaf or leaf-list element as a string wrapped in quotation marks (U+0022) or apostrophes (U+0027). This wil still match integer values.
ToineSiebelink98c07872021-04-20 17:33:09 +0100136
137**Examples**
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100138 - ``//book/label[text()="classic"]``
139 - ``//book/edition[text()="1965"]``
ToineSiebelink98c07872021-04-20 17:33:09 +0100140
141**Limitations**
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100142 - Only the last list or container can be queried for leaf values with a text() condition. Any ancestor list will have to be referenced by its key name-value pair(s).
143 - Only one leaf or leaf-list can be tested.
144 - Only string and integer values are supported, boolean and float values are not supported.
145 - Since CPS cannot return individual leaves it will always return the container with all its leaves. Ancestor-axis can be used to specify a parent higher up the tree.
146 - When querying a leaf value (instead of leaf-list) it is better, more performant to use a text value condition use @<leaf-name> as described above.
puthuparambil.adityaff714622021-04-23 11:55:24 +0100147
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100148ancestor-axis
niamhcore4395c1f2021-05-05 11:42:20 +0100149-------------
150
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100151The ancestor axis can be added to any CPS path query but has to be the last part.
niamhcore4395c1f2021-05-05 11:42:20 +0100152
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100153**Syntax**: ``<cps-path> ( '/ancestor::' <ancestor-path> )?``
niamhcore4395c1f2021-05-05 11:42:20 +0100154 - ``cps-path``: Any CPS path query.
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100155 - ``ancestor-path``: Partial path to ancestors of the target node. This can contain one or more ancestor nodes separated by a ``/``.
niamhcore4395c1f2021-05-05 11:42:20 +0100156
157**Examples**
158 - ``//book/ancestor::categories``
159 - ``//categories[@genre="SciFi"]/book/ancestor::bookstore``
160 - ``book/ancestor::categories[@code=1]/books``
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100161 - ``//book/label[text()="classic"]/ancestor::shop``
niamhcore4395c1f2021-05-05 11:42:20 +0100162
163**Limitations**
164 - Ancestor list elements can only be addressed using the list key leaf.
ToineSiebelinkf0527c52021-07-06 13:03:03 +0100165 - List elements with compound keys are not supported.