Yaml中的文本格式"示例:"

时间:2018-05-16 15:19:26

标签: yaml swagger swagger-ui

我试图在YAML文件中显示一些格式化文本(在from kivy.app import App from kivy.uix.button import Label, Button from kivy.lang import Builder from kivy.properties import BooleanProperty from kivy.uix.behaviors import FocusBehavior from kivy.uix.recycleboxlayout import RecycleBoxLayout from kivy.uix.recycleview.layout import LayoutSelectionBehavior from kivy.uix.recycleview.views import RecycleDataViewBehavior from kivy.uix.screenmanager import ScreenManager, Screen Builder.load_string(""" <ScreenTest>: Label: pos_hint: {"x": .45, "top": 1} text: "Headline" size_hint: .1, .1 BoxLayout: pos_hint: {"x": 0.02, "top": .8} RecycleView: id: species_list_view data: [{'name': "Species1", "text": "S1"}, {'name': "Species2", "text": "S2"}] viewclass: 'SelectableLabel' SelectableRecycleBoxLayout: default_size: None, dp(56) default_size_hint: 1, None size_hint_y: None orientation: 'vertical' multiselect: False touch_multiselect: False Label: id: species_text text: "Speciestext" BoxLayout: size_hint_y: None height: 30 spacing: 10 canvas: Color: rgba: .5, .2, .1, 1 Rectangle: pos: self.pos size: self.size Button: text: "Go Back" Button: text: "Next" <SelectableLabel>: # Draw a background to indicate selection canvas.before: Color: rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1) Rectangle: pos: self.pos size: self.size """) class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout): pass class SelectableLabel(RecycleDataViewBehavior, Label): ''' Add selection support to the Label ''' index = None selected = BooleanProperty(False) selectable = BooleanProperty(True) def refresh_view_attrs(self, rv, index, data): ''' Catch and handle the view changes ''' self.index = index return super(SelectableLabel, self).refresh_view_attrs( rv, index, data) def on_touch_down(self, touch): ''' Add selection on touch down ''' if super(SelectableLabel, self).on_touch_down(touch): return True if self.collide_point(*touch.pos) and self.selectable: return self.parent.select_with_touch(self.index, touch) def apply_selection(self, rv, index, is_selected): ''' Respond to the selection of items in the view. ''' self.selected = is_selected if is_selected: print("selection changed to {0}".format(rv.data[index])) else: print("selection removed for {0}".format(rv.data[index])) class ScreenTest(Screen): pass screen_manager = ScreenManager() screen_manager.add_widget(ScreenTest(name="screen_test")) class TestApp(App): def build(self): return screen_manager test_app = TestApp() test_app.run() 键中):

example:

获得这样的Swagger输出:

  log_level_per_component:
     type: object
     example:
       "{
        \"Component1\": \"Info\",\n
        \"Component2\": \"Debug\",\n
        \"Component3\": \"Fatal\",\n
        ...\n
        }"

但我总是这样:

"log_level_per_component": "{
                            "Component1": "Info",n
                            "Component2": "Debug",n
                            "Component3": "Fatal",n
                            ...
                            }"

知道我可以做些什么来解决它?


更新2018-05-17,了解Helen关于她的解决方案的屏幕截图请求:

这是我通过使用&#34;示例所得到的两种解决方案:&#34;:

这就是我使用&#34;示例:&#34;:

两者都是空的。

1 个答案:

答案 0 :(得分:0)

YAML是JSON的超集,因此您可以在YAML中使用普通的JSON对象文字语法:

  log_level_per_component:
    type: object
    example:
      Component1: Info
      Component2: Debug
      Component3: Fatal

或者,您可以使用YAML对象语法,Swagger UI将示例呈现为JSON(假设您的请求或响应类型为JSON):

$("#nav_evnavmenu > li > a").on('mouseenter', function () { // binding onclick
    if ($(this).parent().hasClass('selected')) {
        $("#nav_evnavmenu .selected div div").slideUp(100); // hiding popups
        $("#nav_evnavmenu .selected").removeClass("selected");
    } else {
        $("#nav_evnavmenu .selected div div").slideUp(100); // hiding popups
        $("#nav_evnavmenu .selected").removeClass("selected");

        if ($(this).next(".subs").length) {
            $(this).parent().addClass("selected"); // display popup
            $(this).next(".subs").children().slideDown(200);
        }
    }
});