Skip to content

Commit e541b80

Browse files
committed
fix issues #57
1 parent 683bd27 commit e541b80

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

swagger_py_codegen/command.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
from os import path
23
import codecs
34
try:
45
import simplejson as json
@@ -7,6 +8,7 @@
78
from os import makedirs
89
from os.path import join, exists, dirname
910

11+
import six
1012
import yaml
1113
import click
1214

@@ -19,7 +21,13 @@
1921
from .base import Template
2022

2123

24+
def get_ref_filepath(filename, ref_file):
25+
ref_file = path.normpath(path.join(path.dirname(filename), ref_file))
26+
return ref_file
27+
28+
2229
def spec_load(filename):
30+
spec_data = {}
2331
if filename.endswith('.json'):
2432
loader = json.load
2533
elif filename.endswith('.yml') or filename.endswith('.yaml'):
@@ -33,7 +41,19 @@ def spec_load(filename):
3341
else:
3442
loader = yaml.load
3543
with codecs.open(filename, 'r', 'utf-8') as f:
36-
return loader(f)
44+
data = loader(f)
45+
spec_data.update(data)
46+
for field, values in six.iteritems(data):
47+
if field not in ['definitions', 'parameters', 'paths']:
48+
continue
49+
if not isinstance(values, dict):
50+
continue
51+
for _field, value in six.iteritems(values):
52+
if _field == '$ref' and value.endswith('.yml'):
53+
_filepath = get_ref_filepath(filename, value)
54+
field_data = spec_load(_filepath)
55+
spec_data[field] = field_data
56+
return spec_data
3757

3858

3959
def write(dist, content):

tests/testdef.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Account:
2+
type: object
3+
required:
4+
- emailAddress
5+
properties:
6+
emailAddress:
7+
type: string
8+
installationInformation:
9+
$ref: '#/definitions/InstallationInformation'
10+
11+
12+
InstallationInformation:
13+
description: A collection of information that describes an instance of the application and what device it is running on.
14+
properties:
15+
OSType:
16+
type: string
17+
description:
18+
Android or Apple or other

tests/testing.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
swagger: '2.0'
2+
info:
3+
version: "0.1.1"
4+
title: test Application
5+
6+
paths:
7+
/account:
8+
get:
9+
responses:
10+
'200':
11+
description: the status of an account
12+
schema:
13+
properties:
14+
account:
15+
$ref: '#/definitions/Account'
16+
17+
definitions:
18+
$ref: 'testdef.yml'

0 commit comments

Comments
 (0)