|
| 1 | +# Swagger Extensions |
| 2 | + |
| 3 | +The Swagger 2.0 specification allows for custom properties to be added at several places within a Swagger definition, allowing |
| 4 | +API providers to extend the meta-data provided for their REST APIs as needed. Extension properties are always |
| 5 | +prefixed by "x-" and can have any valid JSON format value. |
| 6 | + |
| 7 | +Currently extension properties are supported in the following definition objects: |
| 8 | + |
| 9 | +* within the [info object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#info-object) |
| 10 | +* within the [paths object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#paths-object) |
| 11 | +* within the [path-item object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#path-item-object) |
| 12 | +* within the [operation object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operationObject) |
| 13 | +* within the [parameter object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameterObject) |
| 14 | +* within the [responses object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responses-object) |
| 15 | +* within the [tag object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#tag-object) |
| 16 | +* within the [security-scheme object](https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-scheme-object) |
| 17 | + |
| 18 | +For example, a vendor extension that adds apis.json specific metadata a Swagger definition might look as follows: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "swagger": "2.0", |
| 23 | + "info": { |
| 24 | + "version": "1.0", |
| 25 | + "title": "Analysis", |
| 26 | + "description" : "Provides access to blog posts and analysis across the API Evangelist network.", |
| 27 | + "x-apis-json-image": "https://s3.amazonaws.com/kinlane-productions/api-evangelist/t-shirts/KL_InApiWeTrust-1000.png", |
| 28 | + "x-apis-json-humanURL": "http://developer.apievangelist.com", |
| 29 | + "x-apis-json-baseURL": "http://api.apievangelist.com/definitions/Analysis", |
| 30 | + "x-apis-json-tags": [ |
| 31 | + "blog", |
| 32 | + "industry", |
| 33 | + "analysis", |
| 34 | + "new", |
| 35 | + "API", |
| 36 | + "Application Programming Interface" |
| 37 | + ], |
| 38 | + "x-apis-json-properties": [ |
| 39 | + { |
| 40 | + "type": "X-signup", |
| 41 | + "url": "https://apievangelist.3scale.net/" |
| 42 | + }, |
| 43 | + { |
| 44 | + "type": "X-blog", |
| 45 | + "url": "http://developer.apievangelist.com/blog/" |
| 46 | + }, |
| 47 | + { |
| 48 | + "type": "X-apicommonsmanifest", |
| 49 | + "url": "https://raw.githubusercontent.com/kinlane/analysis-api/master/api-commons-manifest.json" |
| 50 | + } |
| 51 | + ], |
| 52 | + }, |
| 53 | + "basePath": "/", |
| 54 | + "paths": { |
| 55 | + ... |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +This could be used by corresponding tooling that builds apis.json files for swagger definitions, the advantage being that all metadata |
| 61 | +for a Swagger API is within one definition instead of spread out amongst multiple files. |
| 62 | + |
| 63 | +Another (simplified) example could be how to specify a [JWE encryption](http://hdknr.github.io/docs/identity/jwe.html) policy to parameters, |
| 64 | + for example as follows: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + ... |
| 69 | + "socialSecurityNumber": { |
| 70 | + "name": "socialSecurityNumber", |
| 71 | + "in": "query", |
| 72 | + "description": "a social security number", |
| 73 | + "required": false, |
| 74 | + "type": "string", |
| 75 | + "x-jwe-encryption" : { |
| 76 | + "algorithm" : "RSA-OAEP", |
| 77 | + "encryption" : "A256GCM" |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + ... |
| 82 | +} |
| 83 | + |
| 84 | +``` |
| 85 | +An API consumer reading these parameter definitions could interpret this as having to encrypt the skip parameter in line |
| 86 | + with the JWE standard. |
| 87 | + |
| 88 | +## Annotations |
| 89 | + |
| 90 | +The Swagger specific annotations currently available for jax-rs APIs do not support the addition of extension data. |
0 commit comments