From 46883750e48aee481ed5e8f46ff032dc1be9d545 Mon Sep 17 00:00:00 2001 From: Corey Shields Date: Tue, 29 Dec 2020 10:33:16 -0500 Subject: [PATCH] Remove former openapi postprocess script Signed-off-by: Corey Shields --- contrib/postprocess-openapi-schema.py | 79 --------------------------- 1 file changed, 79 deletions(-) delete mode 100755 contrib/postprocess-openapi-schema.py diff --git a/contrib/postprocess-openapi-schema.py b/contrib/postprocess-openapi-schema.py deleted file mode 100755 index bf9cb17..0000000 --- a/contrib/postprocess-openapi-schema.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# -# Script to postprocess OpenAPI generated schema -# -# Copyright (C) 2020 Libre Space Foundation -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import argparse -import sys - -import yaml - - -class Dumper(yaml.Dumper): - def ignore_aliases(self, data): - return True - - -parser = argparse.ArgumentParser(description="Postprocess OpenAPI generated schema") -parser.add_argument('--api-version', type=str, help='Set API version') -parser.add_argument('--server-url', type=str, help='Set API server base URL') -parser.add_argument('--expand-aliases', action='store_true', help='Expand anchors and aliases') -parser.add_argument( - '--enable-apikey-auth', action='store_true', help='Enable DRF API key authentication' -) -parser.add_argument( - 'input_file', - type=argparse.FileType('r', encoding='UTF-8'), - help='OpenAPI schema file or \'-\' for stdin' -) -args = parser.parse_args() - -schema = yaml.safe_load(args.input_file) -if args.api_version is not None: - schema['info']['version'] = args.api_version - -if args.server_url is not None: - schema['servers'] = [{'url': args.server_url}] - -if args.enable_apikey_auth: - schema.update( - { - 'components': { - 'securitySchemes': { - 'ApiKeyAuth': { - 'type': 'apiKey', - 'in': 'header', - 'name': 'Authorization' - } - } - }, - 'security': [ - { - 'ApiKeyAuth': [] - }, - ] - } - ) - -if args.expand_aliases: - schema_dump = yaml.dump( - schema, default_flow_style=False, sort_keys=False, Dumper=Dumper - ).encode('utf-8') -else: - schema_dump = yaml.dump(schema, default_flow_style=False, sort_keys=False).encode('utf-8') - -sys.stdout.buffer.write(schema_dump)