Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created October 13, 2016 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save podhmo/5f62b5c51654bdf54337f2d0455758a6 to your computer and use it in GitHub Desktop.
Save podhmo/5f62b5c51654bdf54337f2d0455758a6 to your computer and use it in GitHub Desktop.
x-bundler-concat:
- ./date.yaml
definitions:
DateRange:
type: object
properties:
Start: '#/definitions/Date'
End: '#/definitions/Date'
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
definitions:
Date:
type: string
x-bundler-namespace: A
x-bundler-concat:
- ./common/date-ranges.yaml
.
├── common
│   ├── date-range.yaml
│   ├── date-ranges.yaml
│   └── date.yaml
├── main.yaml
└── structure.txt
1 directory, 5 files
[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 =
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