Skip to content

Commit

Permalink
Add python to remove default Jersey WADL from yaml
Browse files Browse the repository at this point in the history
Eclipse Jersey used by trace-server enables WADL [1] by default. Even
when disabling the latter ([1]), Swagger (in server) keeps generating
the corresponding endpoint paths in openapi.{json|yaml}.

Add an executable python script, along with proper python support for
it, that removes those WADL paths. Document usage of this simple script
in README.

Base the hereby introduced python support and initial use on [2]'s ways.

[1] https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/user-guide.html#d0e13703
[2] https://github.com/theia-ide/tsp-python-client

Signed-off-by: Marco Miller <marco.miller@ericsson.com>
  • Loading branch information
marco-miller committed Oct 13, 2021
1 parent 51cd9e1 commit 21d4382
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.venv/
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.formatting.provider": "autopep8",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ The specification should be edited with the [OpenAPI (Swagger) Editor extension]

The latter extension is assumed for consistent formatting of the `./API.yaml` file over time.

### Setup

To initialize a local virtual environment, type the following commands in the root directory:

```shell
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```

The virtual environment can be replaced with another local setup.

### Alternate TSP version

Above, `API.yaml` has been the manually documented TSP version up until now.
Expand All @@ -39,6 +51,7 @@ In the meantime, Swagger has recently been added to trace-server.
1. Browse [to here][4] ([swagger][5]) or so to generate server's TSP.
1. Bring the resulting file over; e.g.: `mv ~/Downloads/openapi.yaml .`
1. Update the latter with its license information: `./openapi`
1. Remove the default Eclipse Jersey's WADL paths: `./openapi.py`
1. The resulting git diff may then be pushed for review, at will.

[1] org.eclipse.tracecompass.incubator.trace.server.jersey.rest.core
Expand Down
46 changes: 46 additions & 0 deletions openapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# The MIT License (MIT)
#
# Copyright (C) 2021 - Ericsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
import re

NAME = "openapi"
FILE = NAME + ".yaml"
TEMP = NAME + ".tmp"

tmp = open(TEMP, 'w')
wadl = False
with open(FILE) as yaml:
for line in yaml:
if re.match(r'^\s\s/.+:$', line):
# line is a path; check if wadl to remove it:
wadl = "application.wadl" in line
elif wadl:
# wadl stops if no longer within a wadl path:
wadl = not re.match(r'^\S+:$', line)
if not wadl:
tmp.write(line)

os.rename(TEMP, FILE)
23 changes: 0 additions & 23 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,29 +706,6 @@ paths:
description: default response
content:
'*/*': {}
/application.wadl/{path}:
get:
operationId: getExternalGrammar
parameters:
- name: path
in: path
required: true
schema:
type: string
responses:
default:
description: default response
content:
application/xml: {}
/application.wadl:
get:
operationId: getWadl
responses:
default:
description: default response
content:
application/vnd.sun.wadl+xml: {}
application/xml: {}
components:
schemas:
Filter:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autopep8
pylint

0 comments on commit 21d4382

Please sign in to comment.