2016-12-07 6 views
0

Файл Swagger работает как ожидается с предупреждением.Файл Swagger с предупреждением

{ 
    'swagger': "2.0", 
    "info": { 
    "version": "3.0", 
    "title": "Sample Service", 
    }, 
    "schemes": [ "http" ], 
    "host": "sampleservice.azurewebsites.net", 
    "paths": { 
    "/": { 
     "post": { 
     "summary": "Sample service", 
     "description": "sample service", 
     "parameters": [ 
      { 
      "name": "Input", 
      "in": "body", 
      "description": "valid input", 

      "schema": { 
       "type": "object", 
       "properties": { 
       "MainAttr-1": { 
        "required": [ "Attr-1" ], 
        "type": "object", 
        "properties": { 
        "Attr-1": { 
         "description": "Attr-1", 
         "required": true, 
         "type": "string" 
        }, 
        "Attr-2": { 
         "description": "Attr-2", 
         "required": false, 
         "type": "string" 
        }, 
        "Attr-3": { 
         "description": "Attr-3", 
         "required": false, 
         "type": "boolean" 
        }, 
        "Attr-4": { 
         "description": "Attr-4", 
         "required": false, 
         "type": "boolean" 
        }, 
        "Attr-5": { 
         "description": "Attr-5", 
         "required": false, 
         "type": "string" 
        } 
        } 
       }, 
       "MainAttr-2": { 
        "type": "array", 
        "items": { 
        "type": "object", 
        "required": [ "Attr-1", "Attr-3", "Attr-5", "Attr-8" ], 
        "properties": { 
         "Attr-1": { 
         "description": "Attr-1", 
         "required": true, 
         "type": "string" 
         }, 
         "Attr-2": { 
         "description": "Attr-2", 
         "required": false, 
         "type": "string" 
         }, 
         "Attr-3": { 
         "description": "Attr-3", 
         "required": true, 
         "type": "boolean" 
         }, 
         "Attr-4": { 
         "description": "Attr-4", 
         "required": false, 
         "type": "boolean" 
         }, 
         "Attr-5": { 
         "description": "Attr-5", 
         "required": true, 
         "type": "string" 
         }, 

         "Attr-6": { 
         "description": "Attr-6", 
         "required": false, 
         "type": "string" 
         }, 
         "Attr-7": { 
         "description": "Attr-7", 
         "required": false, 
         "type": "string" 
         }, 
         "Attr-8": { 
         "description": "Attr-8", 
         "required": true, 
         "type": "string" 
         } 
        } 
        } 
       } 
       } 
      } 
      } 
     ], 
     "responses": { 
      "200": { 
      "description": "success" 
      } 
     } 
     } 
    } 
    } 
} 

enter image description here

Выпуск-1) Предупреждение должно быть удалены

Выпуск-2) атр-3 в "MainAttr-2" является атрибутом логического типа и требуется. Но когда я выбираю «ложь» из раскрывающегося списка, он обрабатывается как недопустимый ввод. Он рассматривает только «истинный» как действительный ввод. (Любой атрибут Boolean, который требуется для такого поведения)

Из-за этого предупреждения я не могу доставить код.

Заранее спасибо.

ответ

1
  1. В начале, измените 'swagger' на "swagger". JSON требует двойных кавычек вокруг строк.

  2. Удалить лишнюю запятую в конце:

    "title": "Sample Service", 
    
  3. Удалить атрибут required из ВСЕХ определений свойств (Attr-1 в Attr-8) и использовать required список на уровне объекта вместо (под MainAttr-1 и MainAttr-2) ,

     "MainAttr-1": { 
          "required": [ "Attr-1" ], <-- list the required properties in this array 
          "type": "object", 
          "properties": { 
          "Attr-1": { 
           "description": "Attr-1", 
           "required": true,  <-- remove this 
           "type": "string" 
          }, 
    

Другие, чем ваша спецификация хорошо.

+0

Благодарим за отзыв. Тем не менее, я получаю такое же предупреждение. – Ganesh

+0

Обязательно удалите атрибут 'required' из ВСЕХ свойств (' Attr-1' - 'Attr-8') и оставьте его только на уровне объекта (списки под' MainAttr-1' и 'MainAttr-2'). – Helen

+0

Спасибо Хелен. Исправлена ​​ошибка – Ganesh

Смежные вопросы