File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import absolute_import
2+ from os import path
23import codecs
34try :
45 import simplejson as json
78from os import makedirs
89from os .path import join , exists , dirname
910
11+ import six
1012import yaml
1113import click
1214
1921from .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+
2229def 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
3959def write (dist , content ):
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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'
You can’t perform that action at this time.
0 commit comments