-
Notifications
You must be signed in to change notification settings - Fork 1
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
swaggerVersionshould report1.2for proper detection. -
The resource listing no longer requires a
basePath. -
The
pathelement 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
authorizationssection 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
infosection 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
swaggerVersionshould report1.2for proper detection. -
The
resourcePathnow must start with a forward slash "/" -
The
pathinside theapisarray must start with a forward slash -
Each
operationelement can contain an optionalresponseMessagesvalue. This was renamed fromerrorResponses. -
The
parametershas been updated to support JSON-schema v4 format. See theModelssection for details. -
Each element in the
responseMessagesarray contains an integercodeand stringmessagefield. Previously, the analogouserrorResponseattributes were namedcodeandreasonrespectively. -
The
responseMessageelement may contain an optionalresponseModelattribute to indicate a different object type as a return value depending on thecodewhich typically maps to http response codes. -
The
dataTypefield has been renamed totypefor consistency with the JSON-schema v4 draft spec. See section 2.1 for more details -
The
allowableValuesfield has been absorbed into anenumfor LIST type, andminimum+maximumfor ranges
-
The API Declaration supports a
producesarray, 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
consumesarray, which is an array of strings. These apply to all operations in the API unless overridden at the API level. -
Elements in the
operationsarray 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
formatattribute 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
idandnamefields 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
subTypesattribute 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
discriminatorfield 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!