Skip to content

Commit add7407

Browse files
authored
Update pagination, remove xpath and validation (#4)
* Update pagination to use offset and limit * Remove unused code such as total funcs * Remove XPath * Remove Validation
1 parent 8fca01e commit add7407

File tree

7 files changed

+131
-567
lines changed

7 files changed

+131
-567
lines changed

apidoc/openapi-spec.yml

Lines changed: 17 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ openapi: 3.0.3
44
# - url: http://localhost:8081
55

66
info:
7-
version: "1.0.0-beta.22"
7+
version: "1.0.0-beta.24"
88
title: TinyIoT Thing Directory
99
description: API documentation of the [TinyIoT Thing Directory](https://github.com/tinyiot/thing-directory)
1010
license:
@@ -18,15 +18,29 @@ tags:
1818
description: Search API
1919
- name: events
2020
description: Notification API
21-
- name: validation
22-
description: Validation API (non-normative)
2321

2422
paths:
2523
/things:
2624
get:
2725
tags:
2826
- things
2927
summary: Retrieves the list of Thing Descriptions
28+
parameters:
29+
- name: offset
30+
in: query
31+
description: Offset number in the pagination
32+
required: false
33+
schema:
34+
type: number
35+
format: integer
36+
default: 0
37+
- name: limit
38+
in: query
39+
description: Number of entries per page. When not set, all entries are returned incrementally.
40+
required: false
41+
schema:
42+
type: number
43+
format: integer
3044
responses:
3145
'200':
3246
description: Successful response
@@ -251,47 +265,6 @@ paths:
251265
$ref: '#/components/responses/RespForbidden'
252266
'500':
253267
$ref: '#/components/responses/RespInternalServerError'
254-
/search/xpath:
255-
get:
256-
tags:
257-
- search
258-
summary: Query TDs with XPath expression
259-
description: The query languages, described [here](https://github.com/tinyiot/thing-directory/wiki/Query-Language), can be used to filter results and select parts of Thing Descriptions.
260-
parameters:
261-
- name: query
262-
in: query
263-
description: xPath 3.0 expression for fetching specific items. E.g. `//*[title='Kitchen Lamp']/properties`
264-
required: true
265-
schema:
266-
type: string
267-
# example: //*[title='Kitchen Lamp']/properties
268-
responses:
269-
'200':
270-
description: Successful response
271-
content:
272-
application/json:
273-
schema:
274-
type: array
275-
items:
276-
oneOf:
277-
- type: string
278-
- type: number
279-
- type: integer
280-
- type: boolean
281-
- type: array
282-
- type: object
283-
# examples:
284-
# ThingDescriptionList:
285-
# $ref: '#/components/examples/ThingDescriptionList'
286-
'400':
287-
$ref: '#/components/responses/RespBadRequest'
288-
'401':
289-
$ref: '#/components/responses/RespUnauthorized'
290-
'403':
291-
$ref: '#/components/responses/RespForbidden'
292-
'500':
293-
$ref: '#/components/responses/RespInternalServerError'
294-
295268

296269
/events:
297270
get:
@@ -352,62 +325,11 @@ paths:
352325
'500':
353326
$ref: '#/components/responses/RespInternalServerError'
354327

355-
356-
/validation:
357-
get:
358-
tags:
359-
- validation
360-
summary: Retrieves the validation result for a given Thing Description
361-
description: |
362-
The Thing Description should be provided as JSON in the request body.<br>
363-
Note: This is currently not supported using Swagger UI.<br>
364-
This endpoint is non-normative.
365-
responses:
366-
'200':
367-
description: Validation Result
368-
content:
369-
application/json:
370-
schema:
371-
$ref: '#/components/schemas/ValidationResult'
372-
'400':
373-
$ref: '#/components/responses/RespBadRequest'
374-
'401':
375-
$ref: '#/components/responses/RespUnauthorized'
376-
'403':
377-
$ref: '#/components/responses/RespForbidden'
378-
'500':
379-
$ref: '#/components/responses/RespInternalServerError'
380-
# wait for openapi 3.1.0 which brings back support for requetsBody in GET
381-
# requestBody:
382-
# content:
383-
# application/ld+json:
384-
# schema:
385-
# $ref: '#/components/schemas/ThingDescription'
386-
# examples:
387-
# ThingDescription:
388-
# $ref: '#/components/examples/ThingDescriptionWithID'
389328
security:
390329
- BasicAuth: []
391330
- BearerAuth: []
392331

393332
components:
394-
parameters:
395-
ParamPage:
396-
name: page
397-
in: query
398-
description: Page number in the pagination
399-
required: false
400-
schema:
401-
type: number
402-
format: integer
403-
ParamPerPage:
404-
name: per_page
405-
in: query
406-
description: Number of entries per page
407-
required: false
408-
schema:
409-
type: number
410-
format: integer
411333
securitySchemes:
412334
BasicAuth:
413335
type: http

catalog/catalog.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package catalog
32

43
import (
@@ -11,8 +10,6 @@ import (
1110
type ThingDescription = map[string]interface{}
1211

1312
const (
14-
ResponseContextURL = "https://linksmart.eu/thing-directory/context.jsonld"
15-
ResponseType = "Catalog"
1613
// Storage backend types
1714
BackendMemory = "memory"
1815
BackendLevelDB = "leveldb"
@@ -33,21 +30,11 @@ type CatalogController interface {
3330
update(id string, d ThingDescription) error
3431
patch(id string, d ThingDescription) error
3532
delete(id string) error
36-
list(page, perPage int) ([]ThingDescription, int, error)
37-
listAllBytes() ([]byte, error)
38-
// Deprecated
39-
filterJSONPath(path string, page, perPage int) ([]interface{}, int, error)
33+
listPaginate(offset, limit int) ([]ThingDescription, error)
4034
filterJSONPathBytes(query string) ([]byte, error)
41-
// Deprecated
42-
filterXPath(path string, page, perPage int) ([]interface{}, int, error)
43-
filterXPathBytes(query string) ([]byte, error)
44-
//filterXPathBytes(query string) ([]byte, error)
45-
total() (int, error)
4635
iterateBytes(ctx context.Context) <-chan []byte
4736
cleanExpired()
48-
4937
Stop()
50-
5138
AddSubscriber(listener EventListener)
5239
}
5340

@@ -57,10 +44,9 @@ type Storage interface {
5744
update(id string, td ThingDescription) error
5845
delete(id string) error
5946
get(id string) (ThingDescription, error)
60-
list(page, perPage int) ([]ThingDescription, int, error)
47+
listPaginate(offset, limit int) ([]ThingDescription, error)
6148
listAllBytes() ([]byte, error)
62-
total() (int, error)
63-
iterator() <-chan ThingDescription
49+
iterate() <-chan ThingDescription
6450
iterateBytes(ctx context.Context) <-chan []byte
6551
Close()
6652
}

0 commit comments

Comments
 (0)