Can a schema just have an example but not the actual schema definition?

43 views
Skip to first unread message

Impish Bhattacharya

unread,
Mar 25, 2015, 4:57:11 PM3/25/15
to swagger-sw...@googlegroups.com
Can I define a schema as:

{
    "example" : <json example here>
}

Without containing fields like 'type'?

This example:

# this is an example of the Uber API
# as a demonstration of an API spec in YAML
swagger: '2.0'
info:
  title: Uber API
  description: Move your app forward with the Uber API
  version: "1.0.0"
# the domain of the service
host: api.uber.com
# array of all schemes that your API supports
schemes:
  - https
# will be prefixed to all paths
basePath: /v1
produces:
  - application/json
paths:
  /products:
    get:
      summary: Product Types
      description: |
        The Products endpoint returns information about the *Uber* products
        offered at a given location. The response includes the display name
        and other details about each product, and lists the products in the
        proper display order.
      parameters:
        - name: latitude
          in: query
          description: Latitude component of location.
          required: true
          type: number
          format: double
        - name: longitude
          in: query
          description: Longitude component of location.
          required: true
          type: number
          format: double
      tags:
        - Products
      responses:
        200:
          description: An array of products
          schema:
            type: array
            items:
              $ref: '#/definitions/DummyDef'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/DummyDef'
definitions:
  DummyDef:
    example:
      "ss"


...passes at http://editor.swagger.io/#/ which suggests that such a thing should be valid, but I just wanted to double check.

Ron Ratovsky

unread,
Mar 25, 2015, 4:59:43 PM3/25/15
to swagger-sw...@googlegroups.com
example is free-form, so anything should work.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

tony tam

unread,
Mar 25, 2015, 5:03:01 PM3/25/15
to swagger-sw...@googlegroups.com
I do suggest that you at least use "type": "object".  And also that, without a schema, you're short-changing your consumers considerably.  But it is technically doable and legal.

Ron Ratovsky

unread,
Mar 25, 2015, 5:04:25 PM3/25/15
to swagger-sw...@googlegroups.com
Oh, you mean define a schema just with an example? I missed that part. That's pretty much like saying nothing at all.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Impish Bhattacharya

unread,
Mar 25, 2015, 5:14:21 PM3/25/15
to swagger-sw...@googlegroups.com
Yeah, I realize that. In our case, we sort of consume the customers' APIs and I was trying to figure if they have something like this then will it be valid. So, I take it as yes. Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Mar 25, 2015, 5:15:59 PM3/25/15
to swagger-sw...@googlegroups.com
Well, if you mean valid in terms of technical validation, it'll pass. If you mean valid in terms of the specification's point of view, while it doesn't prohibit it, it's pretty much meaningless and you shouldn't expect any tooling support for it.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages