Skip to content
Snippets Groups Projects
Commit 913cf4e3 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Move root attributes patching to a generator class

parent 6f71857a
No related branches found
No related tags found
No related merge requests found
......@@ -16,5 +16,5 @@ arkindex/iiif-users/
htmlcov
ponos
openapi/*.yml
!openapi/patch.yml
!openapi/paths.yml
*.key
......@@ -60,8 +60,8 @@ backend-openapi:
- mkdir -p output
- pip install -e .
- pip install uritemplate==3 apistar>=0.7.2
- arkindex/manage.py generateschema > output/original.yml
- openapi/patch.py openapi/patch.yml output/original.yml > output/schema.yml
- arkindex/manage.py generateschema --generator_class arkindex.project.openapi.SchemaGenerator > output/original.yml
- openapi/patch.py openapi/paths.yml output/original.yml > output/schema.yml
variables:
PONOS_DATA_DIR: /tmp
......
from arkindex.project.openapi.schemas import AutoSchema, SearchAutoSchema # noqa: F401
from arkindex.project.openapi.generators import SchemaGenerator # noqa: F401
from pathlib import Path
from rest_framework.schemas.openapi import SchemaGenerator as BaseSchemaGenerator
import yaml
PATCH_FILE = Path(__file__).absolute().parent / 'patch.yml'
class SchemaGenerator(BaseSchemaGenerator):
def get_schema(self, **kwargs):
with PATCH_FILE.open() as f:
patch = yaml.safe_load(f)
schema = super().get_schema(**kwargs)
schema.update(patch)
return schema
info:
title: Arkindex API
contact:
name: Teklia
url: https://www.teklia.com/
email: paris@teklia.com
components:
securitySchemes:
sessionAuth:
in: cookie
name: arkindex.auth
type: apiKey
tokenAuth:
scheme: Token
type: http
agentAuth:
scheme: Bearer
type: http
security:
- tokenAuth: []
- sessionAuth: []
servers:
- description: Arkindex
url: https://arkindex.teklia.com
- description: Arkindex preproduction
url: https://arkindex.dev.teklia.com
tags:
- name: corpora
- name: elements
- name: search
- name: oauth
- name: imports
- name: files
- name: images
- name: ponos
- name: iiif
description: IIIF manifests, annotation lists and services
- name: ml
description: Machine Learning tools and results
- name: entities
- name: users
- name: management
description: Admin-only tools
File moved
......@@ -13,7 +13,7 @@ def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'patch',
help='File describing patches to make on the schema',
help="File describing patches to make on the schema's paths",
type=argparse.FileType('r'),
)
parser.add_argument(
......@@ -38,15 +38,13 @@ def get_args():
return args
def update_schema(schema, patches):
def update_schema(schema, paths):
"""
Perform updates on an OpenAPI schema using another YAML file describing patches.
The update is not recursive; any root key will overwrite the schema's original data.
For paths, each operation has its keys updated; the whole operation is not overwritten.
Perform updates on an OpenAPI schema's paths using another YAML file describing patches.
In paths, each operation has its keys updated; the whole operation is not overwritten.
Same goes for an operation's responses.
"""
# Update each method separately
paths = patches.pop('paths', {})
for path, methods in paths.items():
if path not in schema['paths']:
print('Creating path {}'.format(path), file=sys.stderr)
......@@ -69,11 +67,6 @@ def update_schema(schema, patches):
schema['paths'][path][method].update(operation)
# Update other root keys
for k, v in patches.items():
print('Patching {}'.format(k), file=sys.stderr)
schema[k] = v
# Set the API version to the Arkindex package version
try:
# Try with the VERSION file
......
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment