Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 55c81fbd authored by Raphael JOIE's avatar Raphael JOIE
Browse files

remove files as we want it to be in api-best-practices

parent 9bd2b078
Branches
No related tags found
1 merge request!5remove files as we want it to be in api-best-practices
......@@ -39,35 +39,3 @@ npm run demo
npm run build
```
and open test/browser/index.htm in web browser
## Gitlab CI Pipelines
A few-lines Gitlab pipelines is provided as part of this repo to publish OpenAPI specs
in [Gitlab Pages](https://docs.gitlab.com/ee/user/project/pages/). This pipeline
will automatically search for OpenAPI specifications published in the Project registry
and publish a page to browse all version found
> For the pipeline to work, openapi `json` specifications must first be published
> as generic package
> ```yaml
> - publish-openapi-specs-generic-package-job:
> variables:
> VERSION: v0.1.0
> script:
> - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file build/openapi.json "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/openapi/${VERSION}/openapi.json"'
> ```
```yaml
include:
- project: 'digit-c4/dev/openapi-browser'
file: 'gitlab-ci/pages-job.yml'
ref: v0.1
stages:
- doc
# Job to generate pages must be named `pages`
pages:
stage: doc
tags:
- docker
```
#!/usr/bin/env python3
import json
import os
import requests
CI_API_V4_URL = os.getenv('CI_API_V4_URL')
CI_PROJECT_ID = os.getenv('CI_PROJECT_ID')
CI_JOB_TOKEN = os.getenv('CI_JOB_TOKEN')
r = requests.get(f"{CI_API_V4_URL}/projects/{CI_PROJECT_ID}/packages?package_name=openapi",
headers={"JOB-TOKEN": CI_JOB_TOKEN})
try:
r.raise_for_status()
except:
raise Exception("Unable to load OpenAPI packages from Gitlab project registry")
data = r.json()
os.makedirs("public", exist_ok=True)
versions = {}
for package in data:
version = package['version']
openapi = requests.get(f"{CI_API_V4_URL}/projects/{CI_PROJECT_ID}/packages/generic/openapi/{version}/openapi.json",
headers={"JOB-TOKEN": CI_JOB_TOKEN})
openapi.raise_for_status()
filename = f'{version}.openapi.json'
with open(f'public/{filename}', 'w') as f:
f.write(str(openapi.text))
versions[version] = filename
with open("public/versions.js", 'w') as f:
f.write(f"NMS_OPENAPI_VERSIONS = {str(json.dumps(versions))}")
FROM code.europa.eu:4567/digit-c4/dev/python-best-practices/python-poetry:3.11-alpine
RUN pip install requests
WORKDIR /usr/bin
COPY gitlab-ci/ci-script.py ci-script
RUN chmod +x ci-script
WORKDIR /openapi-browser
COPY dist/umd/index.js index.js
COPY dist/umd/assets/styles.css styles.css
COPY gitlab-ci/index.html index.html
<html>
<head>
<script crossorigin src="https://unpkg.com/react@18.2.0/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js"></script>
<script charset="UTF-8" src="index.js"></script>
<script charset="UTF-8" src="versions.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="root"></div>
<script>
OpenApiBrowser({
props: {
versions: NMS_OPENAPI_VERSIONS,
}
})
</script>
</body>
</html>
pages:
tags:
- docker
image: code.europa.eu:4567/digit-c4/dev/openapi-browser/gitlab-ci:latest
script:
- ci-script
- cp /openapi-browser/index.js public/index.js
- cp /openapi-browser/index.html public/index.html
- cp /openapi-browser/styles.css public/styles.css
artifacts:
paths:
- public
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment