swagger-api / validator-badge

Validate your Swagger JSON/YAML today!
http://swagger.io
Apache License 2.0
210 stars 84 forks source link

Editor generated YAML is invalid but JSON is valid #43

Open webron opened 9 years ago

webron commented 9 years ago

From @zenexius on August 6, 2015 10:38

OK so I generated YAML and JSON using the online editor at http://editor.swagger.io/ with no errors. But when I use these files with swagger-ui deployed on my server , YAML file validation fails while JSON file loads without any problem. A live example if you would like to check json that is valid http://54.169.44.104/swagger-ui/?url=/chirashi/fr-chirashi-api-spec.json yaml that is invalid http://54.169.44.104/swagger-ui/?url=/chirashi/fr-chirashi-api-spec.yaml any hint?

Copied from original issue: swagger-api/swagger-ui#1518

webron commented 9 years ago

This is definitely an odd issue. The problem is with the parameter name being no. Changing it to anything else validates the YAML properly.

To make sure the original YAML is available for testing, here's a copy:

# FR-Chirashi-API documentation
# This document provides details of the Chirashi-API specifications
# First created on 2015-08-04 using http://editor.swagger.io/
# © Yumemi corporation Tokyo Japan.
swagger: '2.0'
info:
  title: Uniqlo Fast Retailing Chirashi API
  description: Complete specification of Uniqlo (Fast Retailing) global chirashi module 
  version: "1.0.0"
# Primary domain of the service
# host: chirashi.uniqlo.com
host: uq-chirashi-api-global.d.yumemi.jp
# Array of all schemes that this API supports
schemes:
# Available through https only
  - https
# Will be prefixed to all paths
basePath: /
produces:
  - application/json
paths:
  /chirashi/{version}/{brand}/{locale}/normal:
    get:
      summary: Primary endpoint to get normal type of chirashi for current device
      description: 
        This endpoint returns an object with the data necessary to
        retrieve chirashi image from the server alongwith some metadata such as date &
        title.
      parameters:
        - name: version
          in: path
          description: A number representing the API revision to be used
          required: true
          type: integer
          enum:
            - 200
            - 100
        - name: brand
          in: path
          description: Brand code for which chirashi is to be retrieved
          required: true
          type: string
          enum:
            - uq
            - gu    
        - name: locale
          in: path
          description: Two letter country name for which to fetch the chirashi
          required: true
          type: string
          enum:
            - JP
            - GB
            - US
            - CN
            - DE
            - SG
            - HK
            - TH
            - FR
            - KR
            - PH
            - ID
            - MY
        - name: client_id    
          in: query
          description: A string representing the type of device to get a customized version for that specific device
          required: true
          type: string
          enum:
            - browser
            - mobileapp
            - smartphone
            - tablet
      tags:
        - normal chirashi
      responses:
        200:
          description: An object of chirashi metadata & URL to retrieve the chirashi image
          examples:
            application/json: |-
              {
                "id": 90,
                "title": "\u901a\u5e38\u30c1\u30e9\u30b7",
                "start_datetime": 1438182000,
                "end_datetime": 1439045940,
                "updatetime": 1438843337,
                "urls": {
                  "ec": {
                    "front": {
                      "img": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_A",
                      "map": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_A?req=set,json,UTF-8",
                      "xml": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_A?req=map,xml&scl=1"
                    },
                    "back": {
                      "img": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_B",
                      "map": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_B?req=set,json,UTF-8",
                      "xml": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Online_B?req=map,xml&scl=1"
                    }
                  },
                  "catalog": {
                  "front": {
                    "img": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_A",
                    "map": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_A?req=set,json,UTF-8",
                    "xml": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_A?req=map,xml&scl=1"
                  },
                  "back": {
                    "img": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_B",
                    "map": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_B?req=set,json,UTF-8",
                    "xml": "http:\/\/uniqlo.scene7.com\/is\/image\/UNIQLO\/ViewerTest_Catalog_B?req=map,xml&scl=1"
                  }
                  }
                },
                "notice": {
                  "app": "Notice comment for app",
                  "web": "Notice comment for browser"
                }
              }
          schema:
            type: object
            $ref: '#/definitions/Chirashi'
        default:
          description: Unexpected error
          schema:
            type: object
            $ref: '#/definitions/Error'
  /chirashi/{version}/{brand}/{locale}/large:
    get:
      summary: Primary endpoint to get large type of chirashi for current device
      description: 
        This endpoint returns an object with the data necessary to
        retrieve chirashi image from the server alongwith some metadata such as date &
        title.
      parameters:
        - name: version
          in: path
          description: A number representing the API revision to be used
          required: true
          type: integer
          enum:
            - 200
            - 100
        - name: brand
          in: path
          description: Brand code for which chirashi is to be retrieved
          required: true
          type: string
          enum:
            - uq
            - gu    
        - name: locale
          in: path
          description: Two letter country name for which to fetch the chirashi
          required: true
          type: string
          enum:
            - JP
            - GB
            - US
            - CN
            - DE
            - SG
            - HK
            - TH
            - FR
            - KR
            - PH
            - ID
            - MY
        - name: client_id    
          in: query
          description: A string representing the type of device to get a customized version for that specific device
          required: true
          type: string
          enum:
            - browser
            - mobileapp
            - smartphone
            - tablet
      tags:
        - large chirashi
      responses:
        200:
          description: An array of chirashi metadata & URL to retrieve the chirashi image
          schema:
            type: object
            $ref: '#/definitions/Chirashi'
        default:
          description: Unexpected error
          schema:
            type: object
            $ref: '#/definitions/Error'          
  /chirashi/{version}/{brand}/{locale}/store:
    get:
      summary: Primary endpoint to get store specific chirashi for current device
      description: 
        This endpoint returns an object with the data necessary to
        retrieve chirashi image from the server alongwith some metadata such as date &  title.
      parameters:
        - name: version
          in: path
          description: A number representing the API revision to be used
          required: true
          type: integer
          enum:
            - 200
            - 100
        - name: brand
          in: path
          description: Brand code for which chirashi is to be retrieved
          required: true
          type: string
          enum:
            - uq
            - gu    
        - name: locale
          in: path
          description: Two letter country name for which to fetch the chirashi
          required: true
          type: string
          enum:
            - JP
            - GB
            - US
            - CN
            - DE
            - SG
            - HK
            - TH
            - FR
            - KR
            - PH
            - ID
            - MY
        - name: client_id    
          in: query
          description: A string representing the type of chirashi to be retrieved
          required: true
          type: string
          enum:
            - browser
            - mobileapp
            - smartphone
            - tablet
        - name: no    
          in: query
          description: A string representing the type of chirashi to be retrieved
          required: true
          type: integer
          enum:
            - 10100479
      tags:
        - store chirashi
      responses:
        200:
          description: An array of chirashi metadata & URL to retrieve the chirashi image
          schema:
            type: object
            $ref: '#/definitions/Chirashi'
        default:
          description: Unexpected error
          schema:
            type: object
            $ref: '#/definitions/Error'
  /chirashi/{version}/{brand}/{locale}/special:
    get:
      summary: Primary endpoint to get special chirashi for current device
      description: 
        This endpoint returns an object with the data necessary to
        retrieve chirashi image from the server alongwith some metadata such as date &
        title.
      parameters:
        - name: version
          in: path
          description: A number representing the API revision to be used
          required: true
          type: integer
          enum:
            - 200
            - 100
        - name: brand
          in: path
          description: Brand code for which chirashi is to be retrieved
          required: true
          type: string
          enum:
            - uq
            - gu    
        - name: locale
          in: path
          description: Two letter country name for which to fetch the chirashi
          required: true
          type: string
          enum:
            - JP
            - GB
            - US
            - CN
            - DE
            - SG
            - HK
            - TH
            - FR
            - KR
            - PH
            - ID
            - MY
        - name: client_id    
          in: query
          description: A string representing the type of chirashi to be retrieved
          required: true
          type: string
          enum:
            - browser
            - mobileapp
            - smartphone
            - tablet
        - name: content    
          in: query
          description: A string representing the type of chirashi to be retrieved
          required: true
          type: string
      tags:
        - special chirashi
      responses:
        200:
          description: An array of chirashi metadata & URL to retrieve the chirashi image
          schema:
            type: object
            $ref: '#/definitions/Chirashi'
        default:
          description: Unexpected error
          schema:
            type: object
            $ref: '#/definitions/Error'

definitions:

  Chirashi:
    type: object
    properties:
      id:
        type: integer
        description: id of the chirashi
        example: 90
      title:
        type: string
        description: Chirashi title.
        example: "UTがお買い得!夏満喫特別号"
      start_datetime:
        type: string
        description: A unix time stamp for the start date of Chirashi
      end_datetime:
        type: string
        description: A unix time stamp for the ending date of Chirashi
      updatetime:
        type: string
        description: A unix time stamp representing the date chirashi was last updated.
      urls:
        type: object
        description: Chirashi properties that can be used to fetch the real data from the server.
        $ref: '#/definitions/ChirashiURLs'
      notice:
        type: object
        description: A descriptive notice related to the current request
        $ref: '#/definitions/Notice'
  ChirashiURLs:
    properties:
      ec:
        type: object
        description: Object representing the E-Commerece Chirashi links
        $ref: '#/definitions/URLs'
      catalog:
        type: object
        description: Object representing the Catalog Chirashi links
        $ref: '#/definitions/URLs'
  URLs:
    properties:
      front:
        type: object
        description: A collection of links for front side of the chirashi
        $ref: '#/definitions/SideURLs'
      back:
        type: object
        description: A collection of links for the back side of the chirashi
        $ref: '#/definitions/SideURLs'
  SideURLs:
    properties:
      img:
        type: string
        description: A URL for the primary image of chirashi
      map:
        type: string
        description: A URL for image map of the chirashi
      xml:
        type: string
        description: A URL for image map XML of the chirashi
  Notice:
    properties:
      app:
        type: string
        description: Some descriptive detail about app related request of chirashi
      web:
        type: string
        description: Provides detail of chirashi related message for web 
  Error:
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      fields:
        type: string
fehguy commented 8 years ago

eww. Yes, this looks like a bug in the underlying json schema validator. For quick reference, the original here:

http://online.swagger.io/validator/debug?url=https://gist.githubusercontent.com/fehguy/0307aac09458fd7c6692/raw/237ec9e7d44ce682ca18f30ad71e16ea4c06fd01/gistfile1.txt

does not validate, as @webron said, changing to no for the parameter name does:

http://online.swagger.io/validator/debug?url=https://gist.githubusercontent.com/fehguy/0307aac09458fd7c6692/raw/240b1e097576f07de2f3641184f07e216fe6c445/gistfile1.txt