Created
October 13, 2016 04:38
-
-
Save podhmo/5f62b5c51654bdf54337f2d0455758a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x-bundler-concat: | |
- ./date.yaml | |
definitions: | |
DateRange: | |
type: object | |
properties: | |
Start: '#/definitions/Date' | |
End: '#/definitions/Date' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x-bundler-concat: | |
- ./date-range.yaml | |
definitions: | |
DateRanges: | |
type: array | |
items: | |
$ref: '#/definitions/DateRange' | |
# type DateRanges []DateRange | |
# type DateRange struct { | |
# Start Date | |
# End Date | |
# } | |
# type Date string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
definitions: | |
Date: | |
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x-bundler-namespace: A | |
x-bundler-concat: | |
- ./common/date-ranges.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── common | |
│ ├── date-range.yaml | |
│ ├── date-ranges.yaml | |
│ └── date.yaml | |
├── main.yaml | |
└── structure.txt | |
1 directory, 5 files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DEFAULT] | |
[special_marker] | |
# todo: gentle description. | |
namespace = x-bundler-namespace | |
compose = x-bundler-compose | |
concat = x-bundler-concat | |
exposed = x-bundler-exposed | |
[postscript_hook] | |
# lambda ctx, data, *args, **kwargs: do_something() | |
## examples: | |
# swagger_bundler.postscript:echo | |
# or | |
# a/b/c/d.py:function_name | |
compose = | |
bundle = ./transform.py:bundle_hook | |
add_namespace = ./transform.py:add_x_common_hook | |
validate = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from swagger_bundler.postscript import fix_data_in_target_section | |
from swagger_bundler import highlight | |
from collections import deque | |
def bundle_hook(ctx, data, *args, **kwargs): | |
"""defaultを持たないresponsesの設定にdefaultを付加する""" | |
if not kwargs.get("last"): | |
return data | |
def add_default(response): | |
if 'default' not in response: | |
response["default"] = {"$ref": "#/responses/errorResponse"} | |
fix_data_in_target_section(deque(["paths", "responses"]), data, add_default) | |
return data | |
def add_x_common_hook(ctx, data, *args, **kwargs): | |
"""commonのdefinitionsにx-common: trueを付加する""" | |
if not kwargs.get("last"): | |
return data | |
definitions = data.get("definitions") | |
if definitions is None: | |
return data | |
exposed_predicate = kwargs.get("exposed_predicate") | |
if exposed_predicate is None: | |
highlight.show_on_warning("could you upgrade swagger-bundler(>0.1.3)?") | |
return data | |
for name in exposed_predicate.get("definitions", []): | |
data["definitions"][name]["x-common"] = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment