Skip to content

Commit

Permalink
add x-auto-generated
Browse files Browse the repository at this point in the history
  • Loading branch information
podhmo committed Oct 19, 2016
1 parent e5218a8 commit 38d2005
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions example3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,27 @@ nested/main.yaml
properties:
boo:
$ref: '#/definitions/FooBarBoo'
x-auto-generated: true
FooBarBoo:
type: object
properties:
yoo:
$ref: '#/definitions/FooBarBooYoo'
x:
$ref: '#/definitions/X'
x-auto-generated: true
FooBarBooYoo:
type: object
properties:
yah:
$ref: '#/definitions/FooBarBooYooYah'
x-auto-generated: true
FooBarBooYooYah:
type: object
properties:
yay:
type: string
x-auto-generated: true
Boo:
type: array
items:
Expand All @@ -129,19 +133,23 @@ nested/main.yaml
$ref: '#/definitions/BooItemsUser'
grouplist:
$ref: '#/definitions/BooItemsGrouplist'
x-auto-generated: true
BooItemsGrouplist:
type: array
items:
$ref: '#/definitions/BooItemsGrouplistItems'
x-auto-generated: true
BooItemsGrouplistItems:
type: object
properties:
name:
type: string
x-auto-generated: true
BooItemsUser:
type: object
properties:
name:
type: string
age:
type: number
x-auto-generated: true
18 changes: 14 additions & 4 deletions swagger_bundler/postscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def lifting_definition(ctx, data, *args, **kwargs):
w = SubDefinitionExtractor(replace=True)
for name in list(data["definitions"].keys()):
prop = data["definitions"].pop(name)
extracted = w.extract(prop, [name])
extracted = w.extract(prop, MarkedExtractorContext([name]))
extracted[name] = prop
data["definitions"].update(reversed(extracted.items()))



def fix_data_in_target_section(paths, d, fn):
if hasattr(d, "keys"):
for k in list(d.keys()):
Expand Down Expand Up @@ -79,20 +78,31 @@ def save_object(self, name, definition):
newdef["type"] = "object"
newdef["properties"] = definition
self.r[name] = newdef
return newdef

def save_array(self, name, definition):
newdef = self.r.__class__()
newdef["type"] = "array"
newdef["items"] = definition
self.r[name] = newdef
return newdef


class MarkedExtractorContext(ExtractorContext):
def save_object(self, name, definition):
newdef = super().save_object(name, definition)
newdef["x-auto-generated"] = True

def save_array(self, name, definition):
newdef = super().save_array(name, definition)
newdef["x-auto-generated"] = True


class SubDefinitionExtractor:
def __init__(self, replace=True):
self.replace = replace

def extract(self, data, path, r=None):
ctx = ExtractorContext(path, r)
def extract(self, data, ctx):
self._extract(data, ctx)
for k in list(ctx.r.keys()):
ctx.r[k] = copy.deepcopy(ctx.r[k])
Expand Down

0 comments on commit 38d2005

Please sign in to comment.