大招3.0定义模式以防止重复

时间:2018-08-03 12:19:35

标签: swagger

嗨,我尝试定义这样的字符串模式:

components:
    patterns:
        unsigned: ^\d+$

使用
properties:
    somePropertyName:
        type: integer:
        pattern: 
            $ref: '#/components/patterns/unsigned

无法找到正确的语法来定义一些字符串变量 / const 。 有可能的?

某些示例具有相同模式的两次重复:

    paths:
        /location:
            get:
              summary: Get location label by lat/lng
              parameters:
                - name: latitude
                  in: query
                  required: true
                  schema:
                    type: number
                    format: float
                    pattern: '^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$'
                - name: longitude
                  in: query
                  required: true
                  schema:
                    type: number
                    format: float
                    pattern: '^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$'
              ...
    components:   
        schemas:    
            Location:
              type: object
              properties:
                ...
                latitude:
                  type: number
                  format: float
                  pattern: '^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$'
                longitude:
                  type: number
                  format: float
                  pattern: '^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$'
                ...

我还有X个查询,我想在其中重复使用此模式,并且在将来可能更改模式后,我不想重构X个位置。

或者这个:

OpenHours:
      type: object
      properties:
        MondayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        MondayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        TuesdayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        TuesdayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        WednesdayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        WednesdayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        ThursdayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        ThursdayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        FridayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        FridayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        SaturdayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        SaturdayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        SundayOpen:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'
        SundayClose:
          type: string
          pattern: '([01]?\d|2[0-3]):([0-5]?\d)'

0 个答案:

没有答案