1
+ # =================================================================
2
+
3
+ # Authors: Joana Simoes <jo@doublebyte.net>
4
+ #
5
+ # Copyright (c) 2024 Joana Simoes
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person
8
+ # obtaining a copy of this software and associated documentation
9
+ # files (the "Software"), to deal in the Software without
10
+ # restriction, including without limitation the rights to use,
11
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the
13
+ # Software is furnished to do so, subject to the following
14
+ # conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26
+ # OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ # =================================================================
29
+
30
+
31
+ import logging
32
+ from http import HTTPStatus
33
+ from typing import Tuple
34
+
35
+ from pygeoapi .util import to_json
36
+
37
+ from . import APIRequest , API , F_JSON , SYSTEM_LOCALE
38
+
39
+ LOGGER = logging .getLogger (__name__ )
40
+
41
+ CONFORMANCE_CLASSES = [
42
+ 'http://www.opengis.net/spec/ogcapi-styles-1/0.0/conf/core' ,
43
+ 'http://www.opengis.net/spec/ogcapi-styles-1/0.0/conf/html' ,
44
+ 'http://www.opengis.net/spec/ogcapi-styles-1/0.0/conf/mapbox-style'
45
+ ]
46
+
47
+
48
+ def get_styles (api : API , request : APIRequest ) -> Tuple [dict , int , str ]:
49
+ """
50
+ Fetches the set of styles available.
51
+ For each style it returns the id, a title, links to the stylesheet of the style in each supported encoding,
52
+ and the link to the metadata.
53
+
54
+ :param request: A request object
55
+
56
+ :returns: tuple of headers, status code, content
57
+ """
58
+
59
+ format_ = request .format or F_JSON
60
+
61
+ # Force response content type and language (en-US only) headers
62
+ headers = request .get_response_headers (SYSTEM_LOCALE , ** api .api_headers )
63
+
64
+ # TODO: implement this
65
+
66
+ data = '{"styles": [{"title": "night", "id": "night"}]}'
67
+
68
+ if format_ == F_JSON :
69
+ headers ['Content-Type' ] = 'application/json'
70
+ return headers , HTTPStatus .OK , to_json (data , api .pretty_print )
71
+ else :
72
+ return api .get_format_exception (request )
73
+
74
+
75
+ def get_oas_30 (cfg : dict , locale : str ) -> tuple [list [dict [str , str ]], dict [str , dict ]]: # noqa
76
+ """
77
+ Get OpenAPI fragments
78
+
79
+ :param cfg: `dict` of configuration
80
+ :param locale: `str` of locale
81
+
82
+ :returns: `tuple` of `list` of tag objects, and `dict` of path objects
83
+ """
84
+
85
+ from pygeoapi .openapi import OPENAPI_YAML
86
+
87
+ paths = {}
88
+
89
+ paths ['/styles' ] = {
90
+ 'get' : {
91
+ 'summary' : 'lists the available styles' ,
92
+ 'description' : 'This operation fetches the set of styles available.' ,
93
+ 'tags' : ['Discover and fetch styles' ],
94
+ 'operationId' : 'getStyles' ,
95
+ 'externalDocs' : {
96
+ 'description' : 'The specification that describes this operation: OGC API - Styles (DRAFT)' ,
97
+ 'url' : 'https://docs.ogc.org/DRAFTS/20-009.html'
98
+ },
99
+ 'parameters' : [
100
+ {'$ref' : '#/components/parameters/access_token' },
101
+ {'$ref' : '#/components/parameters/fStyles' }
102
+ ],
103
+ 'responses' : {
104
+ '200' : {'$ref' : f"{ OPENAPI_YAML ['oapif-1' ]} #/components/responses/Features" }, # noqa
105
+ '400' : {'$ref' : f"{ OPENAPI_YAML ['oapif-1' ]} #/components/responses/InvalidParameter" }, # noqa
106
+ # TODO: add 406
107
+ '500' : {'$ref' : f"{ OPENAPI_YAML ['oapif-1' ]} #/components/responses/ServerError" } # noqa
108
+ }
109
+ }
110
+ }
111
+
112
+ return [{'name' : 'styles' }], {'paths' : paths }
0 commit comments