Skip to content

Commit

Permalink
ramlfications: patch to support Windows. Resolves #5
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbonney committed Nov 8, 2018
1 parent c7103f9 commit cbe50e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2018 British Broadcasting Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import jsonref


# Work around ramlfications Windows compatibility issues
def _parse_json(self, jsonfile, base_path):
"""
Parses JSON as well as resolves any `$ref`s, including references to
local files and remote (HTTP/S) files.
"""
base_path = os.path.abspath(base_path)
if not base_path.endswith("/"):
base_path = base_path + "/"
if os.name == "nt":
base_path = "file:///" + base_path.replace('\\', '/')
else:
base_path = "file://" + base_path

with open(jsonfile, "r") as f:
schema = jsonref.load(f, base_uri=base_path, jsonschema=True)
return schema
10 changes: 10 additions & 0 deletions Specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
import json
import ramlfications

from Patches import _parse_json


try:
# Patch ramlfications for Windows support
ramlfications.loader.RAMLLoader._parse_json = _parse_json
except AttributeError:
pass


class Specification(object):
def __init__(self, file_path):
self.data = {}
Expand Down

0 comments on commit cbe50e4

Please sign in to comment.