8000 docs(openapi): autogenerate curl commands with redoc by deepankarm · Pull Request #2130 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs(openapi): autogenerate curl commands with redoc #2130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: |
pip install .[daemon] --no-cache-dir
JINA_VERSION=$(sed -n '/^__version__/p' ./jina/__init__.py | cut -d \' -f2)-master
Expand All @@ -51,26 +54,28 @@ jobs:
cd schema
mkdir -p schemas
jina export-api --schema-path schemas/"$JINA_VERSI 8000 ON.json" schemas/master.json schemas/master --yaml-path "$JINA_VERSION.yml" master.yml --json-path "$JINA_VERSION.json" master.json master
python -c "from daemon import _write_openapi_schema; _write_openapi_schema()"
python ../scripts/get-gateway-openapi.py
python ../scripts/get-openapi-schemas.py
npm install --prefix ~ snippet-enricher-cli
~/node_modules/.bin/snippet-enricher-cli --input=gateway.json --targets=shell_curl > gateway-with-code.json
~/node_modules/.bin/snippet-enricher-cli --input=daemon.json --targets=shell_curl > daemon-with-code.json
cd -
- name: redoc-cli-jinad
uses: seeebiii/redoc-cli-github-action@v10
with:
args: 'bundle schema/daemon.json -o jinad.html'
args: 'bundle schema/daemon-with-code.json -o jinad.html'
- name: redoc-cli-gateway
uses: seeebiii/redoc-cli-github-action@v10
with:
args: 'bundle schema/gateway.json -o rest.html'
args: 'bundle schema/gateway-with-code.json -o rest.html'
- name: push-to-api-repo
run: |
mkdir -p schema/daemon/
cp jinad.html schema/daemon/master.html
rm schema/daemon.json
rm schema/daemon.json schema/daemon-with-code.json
rm -rf schema/jinad
mkdir -p schema/rest/
cp rest.html schema/rest/master.html
rm schema/gateway.json
rm schema/gateway.json schema/gateway-with-code.json
cd schema
git config --local user.email "dev-bot@jina.ai"
git config --local user.name "Jina Dev Bot"
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: |
JINA_VERSION=${GITHUB_REF/refs\/tags\/v/}
JINA_MINOR_VERSION=${JINA_VERSION%.*}
Expand All @@ -32,28 +35,30 @@ jobs:
cd schema
mkdir -p schemas
jina export-api --schema-path schemas/"$JINA_VERSION.json" schemas/latest.json schemas/latest --yaml-path "$JINA_VERSION.yml" latest.yml --json-path "$JINA_VERSION.json" latest.json latest
python -c "from daemon import _write_openapi_schema; _write_openapi_schema()"
python ../scripts/get-gateway-openapi.py
python ../scripts/get-openapi-schemas.py
npm install --prefix ~ snippet-enricher-cli
~/node_modules/.bin/snippet-enricher-cli --input=gateway.json --targets=shell_curl > gateway-with-code.json
~/node_modules/.bin/snippet-enricher-cli --input=daemon.json --targets=shell_curl > daemon-with-code.json
cd -
- name: redoc-cli-jinad
uses: seeebiii/redoc-cli-github-action@v10
with:
args: 'bundle schema/daemon.json -o jinad.html'
args: 'bundle schema/daemon-with-code.json -o jinad.html'
- name: redoc-cli-gateway
uses: seeebiii/redoc-cli-github-action@v10
with:
args: 'bundle schema/gateway.json -o rest.html'
args: 'bundle schema/gateway-with-code.json -o rest.html'
- name: push-to-api-repo
run: |
mkdir -p schema/daemon/
cp jinad.html schema/daemon/index.html
cp jinad.html schema/daemon/${{env.JINA_VERSION}}.html
rm schema/daemon.json
rm schema/daemon.json schema/daemon-with-code.json
rm -rf schema/jinad
mkdir -p schema/rest/
cp rest.html schema/rest/index.html
cp rest.html schema/rest/${{env.JINA_VERSION}}.html
rm schema/gateway.json
rm schema/gateway.json schema/gateway-with-code.json
cd schema
git config --local user.email "dev-bot@jina.ai"
git config --local user.name "Jina Dev Bot"
Expand Down
11 changes: 1 addition & 10 deletions daemon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ def _get_app():
return app


def _write_openapi_schema(filename='daemon.json'):
app = _get_app()
schema = app.openapi()
schema['info']['x-logo'] = {
'url': 'https://api.jina.ai/logo/logo-product/jina-core/horizontal-layout/colored/Product%20logo_Core_vertical_colorful%402x-margin.png'
}
with open(filename, 'w') as f:
json.dump(schema, f)


def _start_uvicorn(app: 'FastAPI'):
config = Config(
app=app,
Expand Down Expand Up @@ -112,6 +102,7 @@ def _start_fluentd():


def main():
"""Entrypoint for JinaD"""
global jinad_args
jinad_args = _get_run_args()
if not jinad_args.no_fluentd:
Expand Down
16 changes: 0 additions & 16 deletions scripts/get-gateway-openapi.py

This file was deleted.

37 changes: 37 additions & 0 deletions scripts/get-openapi-schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json

from daemon import _get_app
from daemon.parser import get_main_parser
from jina.logging import JinaLogger
from jina.parsers import set_gateway_parser
from jina.peapods.runtimes.asyncio.rest.app import get_fastapi_app


JINA_LOGO_URL = 'https://api.jina.ai/logo/logo-product/jina-core/horizontal-layout/colored/Product%20logo_Core_vertical_colorful%402x-margin.png'
DAEMON_SCHEMA_FILENAME = 'daemon.json'
GATEWAY_SCHEMA_FILENAME = 'gateway.json'


args = set_gateway_parser().parse_args([])
logger = JinaLogger('')
gateway_app = get_fastapi_app(args, logger)
gateway_schema = gateway_app.openapi()
gateway_schema['info']['x-logo'] = {'url': JINA_LOGO_URL}
gateway_schema['servers'] = []
gateway_schema['servers'].append(
{'url': f'http://localhost:{args.port_expose}', 'description': 'Local Jina gateway'}
)
with open(GATEWAY_SCHEMA_FILENAME, 'w') as f:
json.dump(gateway_schema, f)


args = get_main_parser().parse_args([])
daemon_app = _get_app()
daemon_schema = daemon_app.openapi()
daemon_schema['info']['x-logo'] = {'url': JINA_LOGO_URL}
daemon_schema['servers'] = []
daemon_schema['servers'].append(
{'url': f'http://localhost:{args.port_expose}', 'description': 'Local JinaD server'}
)
with open(DAEMON_SCHEMA_FILENAME, 'w') as f:
json.dump(daemon_schema, f)
0