Skip to content

Commit 770f350

Browse files
authored
Merge pull request #3660 from lcaouen/new_swagger_generation
New swagger generation
2 parents ed9fce4 + e08d6f1 commit 770f350

File tree

7 files changed

+90
-32
lines changed

7 files changed

+90
-32
lines changed

.github/workflows/build_swagger.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"sphinx_rtd_theme>=3.0",
99
"myst-parser>=4.0",
1010
"setuptools",
11+
"sphinxcontrib.openapi"
1112
]
1213

1314
[tool.pixi.workspace]

docs/source/_ext/safe_openapi.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
from docutils import nodes
3+
from docutils.parsers.rst import Directive
4+
from sphinx.util.nodes import nested_parse_with_titles
5+
6+
class SafeOpenApiDirective(Directive):
7+
"""
8+
Usage :
9+
.. safe_openapi:: path/to/openapi.yaml
10+
"""
11+
required_arguments = 1
12+
13+
def run(self):
14+
env = self.state.document.settings.env
15+
docdir = os.path.dirname(env.doc2path(env.docname))
16+
17+
# Argument from the directive
18+
openapi_path = self.arguments[0]
19+
20+
# Find absolute path
21+
full_path = os.path.normpath(os.path.join(docdir, openapi_path))
22+
23+
if os.path.exists(full_path):
24+
# add the normal `openapi` directive
25+
node = nodes.paragraph()
26+
directive_text = f".. openapi:: {openapi_path}\n"
27+
self.state_machine.insert_input([directive_text], self.state_machine.input_lines.source(0))
28+
return []
29+
else:
30+
# add file not found
31+
warning = nodes.paragraph(text=f"OpenAPI file {openapi_path} not found")
32+
return [warning]
33+
34+
35+
def setup(app):
36+
app.add_directive("safe_openapi", SafeOpenApiDirective)
37+
return {"version": "1.0"}

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
# Add any Sphinx extension module names here, as strings. They can be extensions
3131
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3232
extensions = [
33+
"sphinxcontrib.openapi",
3334
"myst_parser",
3435
"preferences_listing",
36+
"safe_openapi"
3537
]
3638

3739
# Add any paths that contain templates here, relative to this directory.

services/alarm-logger/doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ The automatic purge is run using a cron expression defined in preference ``purge
4747
An Elasticsearch index is considered eligible for deletion if the last inserted message date is before current time
4848
minus the number of days computed from ``date_span_units`` and ``retain_indices_count``.
4949

50+
***
51+
API
52+
***
53+
.. safe_openapi:: ../../../../../services/alarm-logger/target/spec-open-api.json
54+
55+
5056
.. _SpringDocumentation: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronExpression.html

services/alarm-logger/pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,49 @@
173173
</execution>
174174
</executions>
175175
</plugin>
176+
<!-- Plugin declaration -->
177+
<plugin>
178+
<groupId>io.github.kbuntrock</groupId>
179+
<artifactId>openapi-maven-plugin</artifactId>
180+
<version>0.0.28</version>
181+
<executions>
182+
<execution>
183+
<id>documentation</id>
184+
<goals>
185+
<goal>documentation</goal>
186+
</goals>
187+
</execution>
188+
</executions>
189+
<configuration>
190+
<!-- This section defines the general configuration, which can be overriden for each generated document. -->
191+
<apiConfiguration>
192+
<library>SPRING_MVC</library> <!-- SPRING_MVC is the default value. Here this tag could be deleted. Other possible values are JAKARTA_RS and JAVAX_RS -->
193+
<fileFormat>json</fileFormat>
194+
<tagAnnotations> <!-- Only useful if you use Spring MVC -->
195+
<!-- RestController is the default value, but can be replaced by RequestMapping -->
196+
<annotation>RestController</annotation>
197+
</tagAnnotations>
198+
</apiConfiguration>
199+
<!-- This section defines which folders contains the source code to be read to extract the javadoc. -->
200+
<javadocConfiguration>
201+
<scanLocations>
202+
<!-- Other 'location' tag can be added to reference javadoc in other modules. -->
203+
<!-- Path is relative to the project root path. -->
204+
<location>src/main/java</location>
205+
</scanLocations>
206+
</javadocConfiguration>
207+
<!-- This section defines a list of documentations to generate. In this exemple, only one is generated. -->
208+
<apis>
209+
<api>
210+
<locations>
211+
<!-- Replace here by a package relevant for your project. -->
212+
<location>org.phoebus.alarm.logging</location>
213+
</locations>
214+
</api>
215+
</apis>
216+
</configuration>
217+
</plugin>
218+
176219
</plugins>
177220
</build>
178221
</profile>

services/alarm-logger/src/main/java/org/phoebus/alarm/logging/rest/SearchController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public List<AlarmLogMessage> search(@Parameter(hidden = true) @RequestParam Map<
103103

104104
@Operation(summary = "Search alarms by PV name")
105105
@RequestMapping(value = "/search/alarm/pv/{pv}", method = RequestMethod.GET)
106-
public List<AlarmLogMessage> searchPv(@Parameter(description = "PV name") @PathVariable String pv) {
106+
public List<AlarmLogMessage> searchPv(@Parameter(name="pv", description = "PV name") @PathVariable String pv) {
107107
Map<String, String> searchParameters = new HashMap<>();
108108
searchParameters.put("pv", pv);
109109
List<AlarmLogMessage> result = AlarmLogSearchUtil.search(ElasticClientHelper.getInstance().getClient(), searchParameters);

0 commit comments

Comments
 (0)