-
Notifications
You must be signed in to change notification settings - Fork 2
1.2 transition
==========
Not to be confused with the swagger framework versioning, the swagger specification itself is versioned for compatibility. You can see information about previous versions in the wiki.
Philosophically, any changes to the spec are absorbed into the tools for one-version backwards compatibility. So the swagger-ui will work with both swagger-spec 1.1 and 1.2. It is not tested against older versions (prior to 1.1). Changing a specification typically causes some heartache and pain, so the changes introduced are usually not just for fun--they have a history of issues or confusion behind them, which mandates the change.
You can use the swagger-codegen to migrate your swagger 1.1 spec! Please see HERE for details.
That said, here's a transition guide for the 1.2 specification.
-
The
swaggerVersion
should report1.2
for proper detection. -
The resource listing no longer requires a
basePath
. -
The
path
element now supports relative and absolute paths. Relative paths are considered to be relative to the Resource Listing.
The absolute path allows Resource Listings to easily point to multiple servers, so a Resource Listing can be an "uber directory" of apis. Next, the basePath
at the resource listing was serving a different purpose than at the Api Declaration, causing much confusion. Finally, the basePath
for Resource Listing was an additional configuration to mess up.
-
An
authorizations
section was added to define what authorization schemes were supported for the API. See the authorizations section for details on this section. It is not required for 1.2 compliance. -
An
info
section was added to define metadata about the API. It too is optional but highly recommended--the metadata is also presented directly in the swagger-ui console for easy access. See the API Info section for details.
-
The
swaggerVersion
should report1.2
for proper detection. -
The
resourcePath
now must start with a forward slash "/" -
The
path
inside theapis
array must start with a forward slash -
Each
operation
element can contain an optionalresponseMessages
value. This was renamed fromerrorResponses
. -
The
parameters
has been updated to support JSON-schema v4 format. See theModels
section for details. -
Each element in the
responseMessages
array contains an integercode
and stringmessage
field. Previously, the analogouserrorResponse
attributes were namedcode
andreason
respectively. -
The
responseMessage
element may contain an optionalresponseModel
attribute to indicate a different object type as a return value depending on thecode
which typically maps to http response codes. -
The
dataType
field has been renamed totype
for consistency with the JSON-schema v4 draft spec. See section 2.1 for more details -
The
allowableValues
field has been absorbed into anenum
for LIST type, andminimum
+maximum
for ranges
-
The API Declaration supports a
produces
array, which is an array of strings. These apply to all operations in the API unless overridden at the API level. -
The API Declaration supports a
consumes
array, which is an array of strings. These apply to all operations in the API unless overridden at the API level. -
Elements in the
operations
array can contain the following arrays:consumes
,produces
,authorizations
,protocols
. These values override any existing values at the API Declaration
The path
and resourcePath
attributes were inconsistent with leading slashes, causing unnecessary validations.
For the errorResponses
array, many non-200 response codes are actually not errors. This made the reason
not make sense (reason
implies an error state) and often different response codes need to return different data. Such as a 400 response code might include information as to why in the payload.
- Models are now described with JSON-Schema Draft 4. This creates multiple changes:
- Datatypes now conform to the JSON Schema specification. The use of the
format
attribute is used to make up for the more coarse-grained type specification, as shown after the comma in Swagger spec 1.2 below.
Common name | Swagger spec 1.2 | Swagger spec 1.1 |
---|---|---|
integer | integer, int32 | int |
long | integer, int64 | long |
float | number, float | float |
double | number, double | double |
string | string | string |
byte | string, byte | byte |
boolean | boolean | boolean |
date | string, date | Date |
dateTime | string, date-time | Date |
- Required fields are now annotated at the model-level as opposed to the field level. For example, the
id
andname
fields are required:
"Pet" : {
"id" : "Pet",
"required" : [
"id",
"name"
],
"properties" : {
"name" : {
"type" : "string"
},
- Containers have a slightly different representation from the 1.1 spec, again changed to reflect the JSON-schema draft-4
Common name | Swagger spec 1.2 | Swagger spec 1.1 |
---|---|---|
List | array | List |
Array | array | Array |
Set | array, uniqueItems=true | Set |
-
Models can now contain a
subTypes
attribute which indicate that models are a subtype another. It is assumed that the subclass contains the union of properties between itself and its superclass -
Models can contain a
discriminator
field which, in conjunction with asubTypes
, can be used for polymorphic models.
The model specification as JSON-schema opens the ability for more consistent model descriptions. The previous version of swagger models was based on a JSON-schema draft but it has been brought up to spec with draft-4, which is gaining good adoption.
These changes are introduced largely by the swagger community. They reflect a lot of hard work, convincing, emails, IRC chats, and good intentions. If you use swagger, thank your fellow swagger contributors!