From 235d9fedf82409f2bc73c6f82888ac01d98a08b8 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Mon, 8 Jun 2015 16:47:18 +0300 Subject: [PATCH 01/20] Define response for /stories --- example.raml | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/example.raml b/example.raml index 9673611..3dab5d9 100644 --- a/example.raml +++ b/example.raml @@ -45,10 +45,53 @@ securitySchemes: securedBy: [x_ticket_auth] /stories: - securedBy: [read_only_users] + # securedBy: [read_only_users] displayName: All stories get: description: Get all stories + queryParameters: + q: + displayName: "Search query" + type: string + required: false + example: "foobar" + responses: + 200: + body: + application/json: + schema: | + { + "id": "storiesGetSchema", + "type": "object", + "title": "Users response schema", + "$schema": "http://json-schema.org/draft-03/schema", + "properties": { + "count": { + "type": "integer", + "required": true + }, + "fields": { + "type": "string", + "required": true + }, + "took": { + "type": "integer" + }, + "start": { + "type": "integer", + "required": true + }, + "total": { + "type": "integer", + "required": true + }, + "data": { + "type": "array", + "required": true + } + } + } + post: description: Create a new story body: @@ -69,7 +112,7 @@ securedBy: [x_ticket_auth] description: Update a particular story /users: - securedBy: [read_only_useritem_everyone] + # securedBy: [read_only_useritem_everyone] displayName: All users get: description: Get all users From f8fc3cbe625cc417ae5a81cdedef47d6fdbb4aed Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 23 Jul 2015 12:15:27 +0300 Subject: [PATCH 02/20] Add Ra tests runner file --- ra_test.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ra_test.py diff --git a/ra_test.py b/ra_test.py new file mode 100644 index 0000000..775bf70 --- /dev/null +++ b/ra_test.py @@ -0,0 +1,9 @@ +from ra import Tester +from pyramid.paster import bootstrap + + +def main(): + application = bootstrap('local.ini')['app'] + Tester(application, 'example.raml').run() + +main() From 15fa5619ad359a383340e50f6e2330b2d8ea394b Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 23 Jul 2015 14:35:23 +0300 Subject: [PATCH 03/20] Use new api of Ra --- ra_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ra_test.py b/ra_test.py index 775bf70..2cee340 100644 --- a/ra_test.py +++ b/ra_test.py @@ -1,9 +1,9 @@ -from ra import Tester +from ra import RAMLTester from pyramid.paster import bootstrap def main(): application = bootstrap('local.ini')['app'] - Tester(application, 'example.raml').run() + RAMLTester(application, 'example.raml').test() main() From 6bf0244904ea45ef0d0fcde74c231a87938f2b02 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Thu, 23 Jul 2015 17:07:05 +0300 Subject: [PATCH 04/20] Define correct baseUri --- example.raml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example.raml b/example.raml index 058cc1a..51acc34 100644 --- a/example.raml +++ b/example.raml @@ -5,7 +5,7 @@ documentation: - title: Home content: | Welcome to the example API. -baseUri: http://{host}:{port}/{version} +baseUri: http://localhost:6543/api version: v1 mediaType: application/json protocols: [HTTP, HTTPS] @@ -63,7 +63,7 @@ securedBy: [x_ticket_auth] { "id": "storiesGetSchema", "type": "object", - "title": "Users response schema", + "title": "Stories response schema", "$schema": "http://json-schema.org/draft-03/schema", "properties": { "count": { From 925d10902b38b76567fdd458e8fd9f9450a5e7a3 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 24 Jul 2015 15:07:41 +0300 Subject: [PATCH 05/20] Add Content-Length header to /stories --- example.raml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/example.raml b/example.raml index 51acc34..0cde224 100644 --- a/example.raml +++ b/example.raml @@ -91,6 +91,14 @@ securedBy: [x_ticket_auth] } } } + headers: + Content-Length: + displayName: Content length + description: Demo content length header + type: integer + required: true + minimum: 1 + post: description: Create a new story From 59b1f1e17eac4aa668f02e27c9a4f84adfdce13e Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 24 Jul 2015 18:01:02 +0300 Subject: [PATCH 06/20] Add query params definition --- example.raml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/example.raml b/example.raml index 0cde224..97c215c 100644 --- a/example.raml +++ b/example.raml @@ -51,10 +51,25 @@ securedBy: [x_ticket_auth] description: Get all stories queryParameters: q: - displayName: "Search query" + displayName: Query type: string required: false - example: "foobar" + example: foobar + minLength: 1 + _limit: + displayName: Limit + type: integer + required: false + minimum: 1 + _sort: + displayName: Start + type: string + required: false + enum: ["name", "description"] + _count: + displayName: Count + type: boolean + required: false responses: 200: body: From d789aedd9f7a9c243122d78dbfeab8f655f588ea Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Mon, 27 Jul 2015 15:12:25 +0300 Subject: [PATCH 07/20] Define schemas for POST --- example.raml | 69 ++++++++--------- schemas/collection_response.json | 34 ++++++++ schemas/story_body_example.json | 17 ++++ schemas/story_item_response.json | 128 +++++++++++++++++++++++++++++++ 4 files changed, 212 insertions(+), 36 deletions(-) create mode 100644 schemas/collection_response.json create mode 100644 schemas/story_body_example.json create mode 100644 schemas/story_item_response.json diff --git a/example.raml b/example.raml index 97c215c..3626b5c 100644 --- a/example.raml +++ b/example.raml @@ -45,7 +45,7 @@ securitySchemes: securedBy: [x_ticket_auth] /stories: - # securedBy: [read_only_users] + securedBy: [read_only_users] displayName: All stories get: description: Get all stories @@ -74,38 +74,7 @@ securedBy: [x_ticket_auth] 200: body: application/json: - schema: | - { - "id": "storiesGetSchema", - "type": "object", - "title": "Stories response schema", - "$schema": "http://json-schema.org/draft-03/schema", - "properties": { - "count": { - "type": "integer", - "required": true - }, - "fields": { - "type": "string", - "required": true - }, - "took": { - "type": "integer" - }, - "start": { - "type": "integer", - "required": true - }, - "total": { - "type": "integer", - "required": true - }, - "data": { - "type": "array", - "required": true - } - } - } + schema: !include schemas/collection_response.json headers: Content-Length: displayName: Content length @@ -113,13 +82,29 @@ securedBy: [x_ticket_auth] type: integer required: true minimum: 1 - - post: description: Create a new story + queryParameters: + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false body: application/json: schema: !include schemas/story.json + example: !include schemas/story_body_example.json + responses: + 201: + body: + application/json: + schema: !include schemas/story_item_response.json + headers: + Content-Length: + displayName: Content length + description: Demo content length header + type: integer + required: true + minimum: 1 patch: description: Update multiple stories delete: @@ -144,10 +129,22 @@ securedBy: [x_ticket_auth] description: Retrieve the available HTTP verbs for a given resource /users: - # securedBy: [read_only_useritem_everyone] + securedBy: [read_only_useritem_everyone] displayName: All users get: description: Get all users + responses: + 200: + body: + application/json: + schema: !include schemas/collection_response.json + headers: + Content-Length: + displayName: Content length + description: Demo content length header + type: integer + required: true + minimum: 1 post: description: Create a new user body: diff --git a/schemas/collection_response.json b/schemas/collection_response.json new file mode 100644 index 0000000..27e01d2 --- /dev/null +++ b/schemas/collection_response.json @@ -0,0 +1,34 @@ +{ + "id": "collectionGetSchema", + "type": "object", + "title": "Collection response schema", + "$schema": "http://json-schema.org/draft-03/schema", + "properties": { + "count": { + "type": "integer", + "required": true, + "minumum": 0 + }, + "fields": { + "type": "string", + "required": true + }, + "took": { + "type": "integer" + }, + "start": { + "type": "integer", + "required": true, + "minumum": 0 + }, + "total": { + "type": "integer", + "required": true, + "minumum": 0 + }, + "data": { + "type": "array", + "required": true + } + } +} \ No newline at end of file diff --git a/schemas/story_body_example.json b/schemas/story_body_example.json new file mode 100644 index 0000000..0354f6c --- /dev/null +++ b/schemas/story_body_example.json @@ -0,0 +1,17 @@ +{ + "due_date": "2015-03-07T10:00:00Z", + "description": "desc1", + "completed": false, + "start_date": "2015-03-04T10:00:00Z", + "progress": 1.0, + "name": "name1", + "signs_number": 12312313123123123, + "valid_date": "2015-03-04", + "valid_time": "14:32:00", + "reads": 10, + "rating": 9, + "available_for": 36000, + "price": 32.99, + "unicode_name": "name2", + "unicode_description": "desc2" +} \ No newline at end of file diff --git a/schemas/story_item_response.json b/schemas/story_item_response.json new file mode 100644 index 0000000..caa431c --- /dev/null +++ b/schemas/story_item_response.json @@ -0,0 +1,128 @@ +{ + "type": "object", + "title": "Story schema", + "$schema": "http://json-schema.org/draft-03/schema", + "auth_fields": ["id", "start_date", "due_date", "name", "description", "progress"], + "public_fields": ["id", "start_date", "due_date", "name"], + "properties": { + "_self": { + "type": "string", + "required": true, + "pattern": "http(s?)://" + }, + "rating": { + "type": "integer", + "required": true + }, + "signs_number": { + "type": "integer", + "required": true + }, + "available_for": { + "type": "integer", + "required": true + }, + "updated_at": { + "type": ["string", "null"], + "required": true, + "format": "date-time" + }, + "assignee_id": { + "type": ["string", "null"], + "required": true + }, + "assignee": { + "type": ["string", "null"], + "required": true + }, + "reads": { + "type": "integer", + "required": true + }, + "owner": { + "type": ["string", "null"], + "required": true + }, + "valid_date": { + "type": "string", + "required": true, + "format": "date-time" + }, + "id": { + "type": ["integer", "string"], + "required": true, + "minimum": 1 + }, + "_pk": { + "type": "string", + "required": true + }, + "attachment": { + "type": ["string", "null"], + "required": true + }, + "progress": { + "type": "number", + "required": true + }, + "price": { + "type": "number", + "required": true + }, + "owner_id": { + "type": ["string", "null"], + "required": true + }, + "due_date": { + "type": "string", + "required": true, + "format": "date-time" + }, + "_type": { + "type": "string", + "required": true + }, + "arbitrary_object": { + "type": ["object", "null"], + "required": true + }, + "description": { + "type": "string", + "required": true + }, + "valid_time": { + "type": "string", + "required": true + }, + "unicode_description": { + "type": "string", + "required": true + }, + "completed": { + "type": "boolean", + "required": true + }, + "name": { + "type": "string", + "required": true + }, + "created_at": { + "type": "string", + "required": true, + "format": "date-time" + }, + "_version": { + "type": "integer", + "required": true + }, + "start_date": { + "type": "string", + "required": true, + "format": "date-time" + }, + "unicode_name": { + "type": "string", + "required": true + }, + } +} From 7ebb6c39ad7a9810dc190b54b68e5f32f69da7b1 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Mon, 27 Jul 2015 17:31:53 +0300 Subject: [PATCH 08/20] Add stories PATCH definitions --- example.raml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/example.raml b/example.raml index 3626b5c..b48147a 100644 --- a/example.raml +++ b/example.raml @@ -61,6 +61,7 @@ securedBy: [x_ticket_auth] type: integer required: false minimum: 1 + example: 10 _sort: displayName: Start type: string @@ -107,6 +108,32 @@ securedBy: [x_ticket_auth] minimum: 1 patch: description: Update multiple stories + queryParameters: + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false + _limit: + displayName: Limit + type: integer + required: true + example: 5 + body: + application/json: + schema: !include schemas/story.json + example: !include schemas/story_body_example.json + responses: + 201: + body: + application/json: + schema: !include schemas/story_item_response.json + headers: + Content-Length: + displayName: Content length + description: Demo content length header + type: integer + required: true + minimum: 1 delete: description: Delete multiple stories head: From 52cba8feb8c3e4760d16f4dd6a6f88fed7f0f243 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 28 Jul 2015 12:05:10 +0300 Subject: [PATCH 09/20] Define schema for collection level actions --- example.raml | 4 +-- schemas/collection_action_response.json | 33 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 schemas/collection_action_response.json diff --git a/example.raml b/example.raml index b48147a..bd12ca4 100644 --- a/example.raml +++ b/example.raml @@ -123,10 +123,10 @@ securedBy: [x_ticket_auth] schema: !include schemas/story.json example: !include schemas/story_body_example.json responses: - 201: + 200: body: application/json: - schema: !include schemas/story_item_response.json + schema: !include schemas/collection_action_response.json headers: Content-Length: displayName: Content length diff --git a/schemas/collection_action_response.json b/schemas/collection_action_response.json new file mode 100644 index 0000000..e1b3ec8 --- /dev/null +++ b/schemas/collection_action_response.json @@ -0,0 +1,33 @@ +{ + "id": "collectionGetSchema", + "type": "object", + "title": "Collection response schema", + "$schema": "http://json-schema.org/draft-03/schema", + "properties": { + "explanation": { + "type": "string", + "required": true + }, + "message": { + "type": "string", + "required": true + }, + "request_url": { + "type": "string", + "required": true + }, + "status_code": { + "type": "integer", + "required": true + }, + "timestamp": { + "type": "string", + "required": true, + "format": "date-time" + }, + "title": { + "type": "string", + "required": true + } + } +} \ No newline at end of file From d6d19d2cfd4008fa4777041dccc1875ed4717343 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 28 Jul 2015 12:52:28 +0300 Subject: [PATCH 10/20] Define HEAD/OPTIONS headers --- example.raml | 58 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/example.raml b/example.raml index bd12ca4..811b7c7 100644 --- a/example.raml +++ b/example.raml @@ -78,7 +78,7 @@ securedBy: [x_ticket_auth] schema: !include schemas/collection_response.json headers: Content-Length: - displayName: Content length + displayName: ContentLength description: Demo content length header type: integer required: true @@ -101,7 +101,7 @@ securedBy: [x_ticket_auth] schema: !include schemas/story_item_response.json headers: Content-Length: - displayName: Content length + displayName: ContentLength description: Demo content length header type: integer required: true @@ -129,17 +129,63 @@ securedBy: [x_ticket_auth] schema: !include schemas/collection_action_response.json headers: Content-Length: - displayName: Content length + displayName: ContentLength description: Demo content length header type: integer required: true minimum: 1 - delete: - description: Delete multiple stories head: description: Determine whether a given resource is available + queryParameters: + q: + displayName: Query + type: string + required: false + example: foobar + minLength: 1 + _limit: + displayName: Limit + type: integer + required: false + minimum: 1 + example: 10 + _sort: + displayName: Start + type: string + required: false + enum: ["name", "description"] + _count: + displayName: Count + type: boolean + required: false + responses: + 200: + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 options: description: Retrieve the available HTTP verbs for a given resource + responses: + 200: + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 0 + maximum: 0 + Allow: + displayName: AllowedMethods + description: Allowed methods + type: string + required: true + delete: + description: Delete multiple stories /{id}: displayName: One story @@ -167,7 +213,7 @@ securedBy: [x_ticket_auth] schema: !include schemas/collection_response.json headers: Content-Length: - displayName: Content length + displayName: ContentLength description: Demo content length header type: integer required: true From bf96bccc0929e26fcb6504425f9ff53414e1fc81 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 28 Jul 2015 13:23:48 +0300 Subject: [PATCH 11/20] Rename schemas. Add DELETE setup --- example.raml | 28 ++++++++++- schemas/collection_delete_response.json | 48 +++++++++++++++++++ ...se.json => collection_patch_response.json} | 0 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 schemas/collection_delete_response.json rename schemas/{collection_action_response.json => collection_patch_response.json} (100%) diff --git a/example.raml b/example.raml index 811b7c7..2c4648e 100644 --- a/example.raml +++ b/example.raml @@ -126,7 +126,7 @@ securedBy: [x_ticket_auth] 200: body: application/json: - schema: !include schemas/collection_action_response.json + schema: !include schemas/collection_patch_response.json headers: Content-Length: displayName: ContentLength @@ -186,7 +186,31 @@ securedBy: [x_ticket_auth] required: true delete: description: Delete multiple stories - + queryParameters: + q: + displayName: Query + type: string + required: false + example: foobar + minLength: 1 + _limit: + displayName: Limit + type: integer + required: true + minimum: 1 + example: 10 + responses: + 200: + body: + application/json: + schema: !include schemas/collection_delete_response.json + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 /{id}: displayName: One story get: diff --git a/schemas/collection_delete_response.json b/schemas/collection_delete_response.json new file mode 100644 index 0000000..9b5c2c5 --- /dev/null +++ b/schemas/collection_delete_response.json @@ -0,0 +1,48 @@ +{ + "id": "collectionGetSchema", + "type": "object", + "title": "Collection response schema", + "$schema": "http://json-schema.org/draft-03/schema", + "properties": { + "timestamp": { + "type": "string", + "required": true, + "format": "date-time" + }, + "title": { + "type": "string", + "required": true + }, + "status_code": { + "type": "integer", + "required": true + }, + "explanation": { + "type": "string", + "required": true + }, + "message": { + "type": ["string", "null"], + "required": true + }, + "extra": { + "type": "object", + "properties": { + "count": { + "type": "integer", + "required": true + }, + "confirmation_url": { + "type": "string", + "pattern": "http(s?)://", + "required": true + }, + "method": { + "type": "string", + "enum": ["delete", "DELETE"], + "required": true + } + } + } + } +} diff --git a/schemas/collection_action_response.json b/schemas/collection_patch_response.json similarity index 100% rename from schemas/collection_action_response.json rename to schemas/collection_patch_response.json From 66ee98d7d731b45a4a27158fcddb4a62e3458d1f Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Tue, 28 Jul 2015 15:02:57 +0300 Subject: [PATCH 12/20] Define non-DB schemas using draft04 of json schema --- example.raml | 16 +++- {schemas => examples}/story_body_example.json | 0 schemas/collection_delete_response.json | 33 ++++---- schemas/collection_patch_response.json | 24 +++--- schemas/collection_response.json | 14 ++-- schemas/story_item_response.json | 84 +++++++------------ 6 files changed, 77 insertions(+), 94 deletions(-) rename {schemas => examples}/story_body_example.json (100%) diff --git a/example.raml b/example.raml index 2c4648e..63a566f 100644 --- a/example.raml +++ b/example.raml @@ -93,7 +93,7 @@ securedBy: [x_ticket_auth] body: application/json: schema: !include schemas/story.json - example: !include schemas/story_body_example.json + example: !include examples/story_body_example.json responses: 201: body: @@ -121,7 +121,7 @@ securedBy: [x_ticket_auth] body: application/json: schema: !include schemas/story.json - example: !include schemas/story_body_example.json + example: !include examples/story_body_example.json responses: 200: body: @@ -215,6 +215,18 @@ securedBy: [x_ticket_auth] displayName: One story get: description: Get a particular story + responses: + 201: + body: + application/json: + schema: !include schemas/story_item_response.json + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 delete: description: Delete a particular story patch: diff --git a/schemas/story_body_example.json b/examples/story_body_example.json similarity index 100% rename from schemas/story_body_example.json rename to examples/story_body_example.json diff --git a/schemas/collection_delete_response.json b/schemas/collection_delete_response.json index 9b5c2c5..8f31378 100644 --- a/schemas/collection_delete_response.json +++ b/schemas/collection_delete_response.json @@ -2,47 +2,44 @@ "id": "collectionGetSchema", "type": "object", "title": "Collection response schema", - "$schema": "http://json-schema.org/draft-03/schema", + "$schema": "http://json-schema.org/draft-04/schema", "properties": { "timestamp": { "type": "string", - "required": true, "format": "date-time" }, "title": { - "type": "string", - "required": true + "type": "string" }, "status_code": { - "type": "integer", - "required": true + "type": "integer" }, "explanation": { - "type": "string", - "required": true + "type": "string" }, "message": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "extra": { "type": "object", "properties": { "count": { - "type": "integer", - "required": true + "type": "integer" }, "confirmation_url": { "type": "string", - "pattern": "http(s?)://", - "required": true + "pattern": "http(s?)://" }, "method": { "type": "string", - "enum": ["delete", "DELETE"], - "required": true + "enum": ["delete", "DELETE"] } - } + }, + "required": ["count", "confirmation_url", "method"] } - } + }, + "required": [ + "timestamp", "title", "status_code", "explanation", + "message", "extra" + ] } diff --git a/schemas/collection_patch_response.json b/schemas/collection_patch_response.json index e1b3ec8..bd807de 100644 --- a/schemas/collection_patch_response.json +++ b/schemas/collection_patch_response.json @@ -2,32 +2,30 @@ "id": "collectionGetSchema", "type": "object", "title": "Collection response schema", - "$schema": "http://json-schema.org/draft-03/schema", + "$schema": "http://json-schema.org/draft-04/schema", "properties": { "explanation": { - "type": "string", - "required": true + "type": "string" }, "message": { - "type": "string", - "required": true + "type": "string" }, "request_url": { - "type": "string", - "required": true + "type": "string" }, "status_code": { - "type": "integer", - "required": true + "type": "integer" }, "timestamp": { "type": "string", - "required": true, "format": "date-time" }, "title": { - "type": "string", - "required": true + "type": "string" } - } + }, + "required": [ + "explanation", "message", "request_url", "status_code", + "timestamp", "title" + ] } \ No newline at end of file diff --git a/schemas/collection_response.json b/schemas/collection_response.json index 27e01d2..5927802 100644 --- a/schemas/collection_response.json +++ b/schemas/collection_response.json @@ -2,33 +2,29 @@ "id": "collectionGetSchema", "type": "object", "title": "Collection response schema", - "$schema": "http://json-schema.org/draft-03/schema", + "$schema": "http://json-schema.org/draft-04/schema", "properties": { "count": { "type": "integer", - "required": true, "minumum": 0 }, "fields": { - "type": "string", - "required": true + "type": "string" }, "took": { "type": "integer" }, "start": { "type": "integer", - "required": true, "minumum": 0 }, "total": { "type": "integer", - "required": true, "minumum": 0 }, "data": { - "type": "array", - "required": true + "type": "array" } - } + }, + "required": ["count", "fields", "start", "total", "data"] } \ No newline at end of file diff --git a/schemas/story_item_response.json b/schemas/story_item_response.json index caa431c..6bb269d 100644 --- a/schemas/story_item_response.json +++ b/schemas/story_item_response.json @@ -1,128 +1,108 @@ { "type": "object", "title": "Story schema", - "$schema": "http://json-schema.org/draft-03/schema", + "$schema": "http://json-schema.org/draft-04/schema", "auth_fields": ["id", "start_date", "due_date", "name", "description", "progress"], "public_fields": ["id", "start_date", "due_date", "name"], "properties": { "_self": { "type": "string", - "required": true, "pattern": "http(s?)://" }, "rating": { - "type": "integer", - "required": true + "type": "integer" }, "signs_number": { - "type": "integer", - "required": true + "type": "integer" }, "available_for": { - "type": "integer", - "required": true + "type": "integer" }, "updated_at": { "type": ["string", "null"], - "required": true, "format": "date-time" }, "assignee_id": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "assignee": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "reads": { - "type": "integer", - "required": true + "type": "integer" }, "owner": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "valid_date": { "type": "string", - "required": true, "format": "date-time" }, "id": { "type": ["integer", "string"], - "required": true, "minimum": 1 }, "_pk": { - "type": "string", - "required": true + "type": "string" }, "attachment": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "progress": { - "type": "number", - "required": true + "type": "number" }, "price": { - "type": "number", - "required": true + "type": "number" }, "owner_id": { - "type": ["string", "null"], - "required": true + "type": ["string", "null"] }, "due_date": { "type": "string", - "required": true, "format": "date-time" }, "_type": { - "type": "string", - "required": true + "type": "string" }, "arbitrary_object": { - "type": ["object", "null"], - "required": true + "type": ["object", "null"] }, "description": { - "type": "string", - "required": true + "type": "string" }, "valid_time": { - "type": "string", - "required": true + "type": "string" }, "unicode_description": { - "type": "string", - "required": true + "type": "string" }, "completed": { - "type": "boolean", - "required": true + "type": "boolean" }, "name": { - "type": "string", - "required": true + "type": "string" }, "created_at": { "type": "string", - "required": true, "format": "date-time" }, "_version": { - "type": "integer", - "required": true + "type": "integer" }, "start_date": { "type": "string", - "required": true, "format": "date-time" }, "unicode_name": { - "type": "string", - "required": true - }, - } + "type": "string" + }, + }, + "required": [ + "_self", "rating", "signs_number", "available_for", "updated_at", + "assignee_id", "assignee", "reads", "owner", "valid_date", "id", + "_pk", "attachment", "progress", "price", "owner_id", "due_date", + "_type", "arbitrary_object", "description", "valid_time", + "unicode_description", "completed", "name", "created_at", + "_version", "start_date", "unicode_name" + ] } From 4bd1d0b0398642866e0cfb0b07c339575f6c95a4 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jul 2015 12:48:23 +0300 Subject: [PATCH 13/20] Define uri param for stories --- example.raml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example.raml b/example.raml index 63a566f..9fa0ce3 100644 --- a/example.raml +++ b/example.raml @@ -213,6 +213,11 @@ securedBy: [x_ticket_auth] minimum: 1 /{id}: displayName: One story + uriParameters: + id: + displayName: User ID + type: integer + example: 1 get: description: Get a particular story responses: From 8e0c881b7f6bafb7e8a8afed4b8ce228e8328ec0 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jul 2015 14:20:53 +0300 Subject: [PATCH 14/20] Define stories/id raml --- example.raml | 93 +++++++++++++++++++++++-- schemas/collection_delete_response.json | 2 +- schemas/collection_patch_response.json | 2 +- schemas/item_delete_response.json | 31 +++++++++ schemas/story_item_response.json | 28 ++++---- 5 files changed, 135 insertions(+), 21 deletions(-) create mode 100644 schemas/item_delete_response.json diff --git a/example.raml b/example.raml index 9fa0ce3..12a94ea 100644 --- a/example.raml +++ b/example.raml @@ -120,7 +120,6 @@ securedBy: [x_ticket_auth] example: 5 body: application/json: - schema: !include schemas/story.json example: !include examples/story_body_example.json responses: 200: @@ -199,6 +198,10 @@ securedBy: [x_ticket_auth] required: true minimum: 1 example: 10 + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false responses: 200: body: @@ -217,11 +220,10 @@ securedBy: [x_ticket_auth] id: displayName: User ID type: integer - example: 1 get: description: Get a particular story responses: - 201: + 200: body: application/json: schema: !include schemas/story_item_response.json @@ -234,14 +236,95 @@ securedBy: [x_ticket_auth] minimum: 1 delete: description: Delete a particular story + queryParameters: + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false + responses: + 200: + body: + application/json: + schema: !include schemas/item_delete_response.json + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 patch: - put: description: Update a particular story + queryParameters: + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false + body: + application/json: + example: !include examples/story_body_example.json + responses: + 200: + body: + application/json: + schema: !include schemas/story_item_response.json + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 + put: + description: Replace a particular story + queryParameters: + _refresh_index: + displayName: RefreshIndex + type: boolean + required: false + body: + application/json: + example: !include examples/story_body_example.json + responses: + 200: + body: + application/json: + schema: !include schemas/story_item_response.json + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 head: description: Determine whether a given resource is available + responses: + 200: + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 options: description: Retrieve the available HTTP verbs for a given resource - + responses: + 200: + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 0 + maximum: 0 + Allow: + displayName: AllowedMethods + description: Allowed methods + type: string + required: true /users: securedBy: [read_only_useritem_everyone] displayName: All users diff --git a/schemas/collection_delete_response.json b/schemas/collection_delete_response.json index 8f31378..beed084 100644 --- a/schemas/collection_delete_response.json +++ b/schemas/collection_delete_response.json @@ -1,5 +1,5 @@ { - "id": "collectionGetSchema", + "id": "collectionDeleteResponseSchema", "type": "object", "title": "Collection response schema", "$schema": "http://json-schema.org/draft-04/schema", diff --git a/schemas/collection_patch_response.json b/schemas/collection_patch_response.json index bd807de..2b31647 100644 --- a/schemas/collection_patch_response.json +++ b/schemas/collection_patch_response.json @@ -1,5 +1,5 @@ { - "id": "collectionGetSchema", + "id": "collectionPatchResponseSchema", "type": "object", "title": "Collection response schema", "$schema": "http://json-schema.org/draft-04/schema", diff --git a/schemas/item_delete_response.json b/schemas/item_delete_response.json new file mode 100644 index 0000000..a6a1133 --- /dev/null +++ b/schemas/item_delete_response.json @@ -0,0 +1,31 @@ +{ + "id": "itemDeleteResponseSchema", + "type": "object", + "title": "Collection response schema", + "$schema": "http://json-schema.org/draft-04/schema", + "properties": { + "explanation": { + "type": "string" + }, + "message": { + "type": ["string", "null"] + }, + "request_url": { + "type": "string" + }, + "status_code": { + "type": "integer" + }, + "timestamp": { + "type": "string", + "format": "date-time" + }, + "title": { + "type": "string" + } + }, + "required": [ + "timestamp", "title", "status_code", "explanation", + "message" + ] +} diff --git a/schemas/story_item_response.json b/schemas/story_item_response.json index 6bb269d..4b54932 100644 --- a/schemas/story_item_response.json +++ b/schemas/story_item_response.json @@ -10,13 +10,13 @@ "pattern": "http(s?)://" }, "rating": { - "type": "integer" + "type": ["integer", "null"] }, "signs_number": { - "type": "integer" + "type": ["integer", "null"] }, "available_for": { - "type": "integer" + "type": ["integer", "null"] }, "updated_at": { "type": ["string", "null"], @@ -29,13 +29,13 @@ "type": ["string", "null"] }, "reads": { - "type": "integer" + "type": ["integer", "null"] }, "owner": { "type": ["string", "null"] }, "valid_date": { - "type": "string", + "type": ["string", "null"], "format": "date-time" }, "id": { @@ -49,16 +49,16 @@ "type": ["string", "null"] }, "progress": { - "type": "number" + "type": ["number", "null"] }, "price": { - "type": "number" + "type": ["number", "null"] }, "owner_id": { "type": ["string", "null"] }, "due_date": { - "type": "string", + "type": ["string", "null"], "format": "date-time" }, "_type": { @@ -71,30 +71,30 @@ "type": "string" }, "valid_time": { - "type": "string" + "type": ["string", "null"] }, "unicode_description": { - "type": "string" + "type": ["string", "null"] }, "completed": { - "type": "boolean" + "type": ["boolean", "null"] }, "name": { "type": "string" }, "created_at": { - "type": "string", + "type": ["string", "null"], "format": "date-time" }, "_version": { "type": "integer" }, "start_date": { - "type": "string", + "type": ["string", "null"], "format": "date-time" }, "unicode_name": { - "type": "string" + "type": ["string", "null"] }, }, "required": [ From 70d8b08bc51c9b7bcb7c60890e2046b45dc248c4 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jul 2015 14:58:25 +0300 Subject: [PATCH 15/20] Refactor out RAML parts to yaml --- example.raml | 262 +++--------------- .../examples}/story_body_example.json | 0 .../schemas}/collection_delete_response.json | 0 .../schemas}/collection_patch_response.json | 0 .../schemas}/collection_response.json | 0 .../schemas}/item_delete_response.json | 0 {schemas => inclusions/schemas}/profile.json | 0 {schemas => inclusions/schemas}/story.json | 0 .../schemas}/story_item_response.json | 0 {schemas => inclusions/schemas}/user.json | 0 inclusions/yaml/collection_query_params.yaml | 21 ++ inclusions/yaml/demo_headers.yaml | 6 + inclusions/yaml/options_responses.yaml | 14 + inclusions/yaml/refresh_index_param.yaml | 3 + inclusions/yaml/security_schemes.yaml | 35 +++ 15 files changed, 117 insertions(+), 224 deletions(-) rename {examples => inclusions/examples}/story_body_example.json (100%) rename {schemas => inclusions/schemas}/collection_delete_response.json (100%) rename {schemas => inclusions/schemas}/collection_patch_response.json (100%) rename {schemas => inclusions/schemas}/collection_response.json (100%) rename {schemas => inclusions/schemas}/item_delete_response.json (100%) rename {schemas => inclusions/schemas}/profile.json (100%) rename {schemas => inclusions/schemas}/story.json (100%) rename {schemas => inclusions/schemas}/story_item_response.json (100%) rename {schemas => inclusions/schemas}/user.json (100%) create mode 100644 inclusions/yaml/collection_query_params.yaml create mode 100644 inclusions/yaml/demo_headers.yaml create mode 100644 inclusions/yaml/options_responses.yaml create mode 100644 inclusions/yaml/refresh_index_param.yaml create mode 100644 inclusions/yaml/security_schemes.yaml diff --git a/example.raml b/example.raml index 12a94ea..9a0c80c 100644 --- a/example.raml +++ b/example.raml @@ -9,39 +9,7 @@ baseUri: http://localhost:6543/api version: v1 mediaType: application/json protocols: [HTTP, HTTPS] -securitySchemes: - - x_token_auth: - description: Authorization header token policy - type: x-ApiKey - - x_ticket_auth: - description: Standard Pyramid Auth Ticket policy - type: x-Ticket - settings: - secret: auth_tkt_secret - hashalg: sha512 - cookie_name: ramses_auth_tkt - http_only: true - - read_only_users: - description: ACL that allows authenticated users to read collection - type: x-ACL - settings: - collection: | - allow admin all - allow authenticated get - item: | - allow admin all - allow authenticated get - - read_only_useritem_everyone: - description: ACL that allows everyone to read item, authenticated users to read collection - type: x-ACL - settings: - collection: | - allow admin all - allow authenticated get - item: | - allow admin all - allow everyone get - allow {{user_self}} patch +securitySchemes: !include inclusions/yaml/security_schemes.yaml securedBy: [x_ticket_auth] /stories: @@ -49,70 +17,31 @@ securedBy: [x_ticket_auth] displayName: All stories get: description: Get all stories - queryParameters: - q: - displayName: Query - type: string - required: false - example: foobar - minLength: 1 - _limit: - displayName: Limit - type: integer - required: false - minimum: 1 - example: 10 - _sort: - displayName: Start - type: string - required: false - enum: ["name", "description"] - _count: - displayName: Count - type: boolean - required: false + queryParameters: !include inclusions/yaml/collection_query_params.yaml responses: 200: body: application/json: - schema: !include schemas/collection_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/collection_response.json + headers: !include inclusions/yaml/demo_headers.yaml post: description: Create a new story queryParameters: - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: - schema: !include schemas/story.json - example: !include examples/story_body_example.json + schema: !include inclusions/schemas/story.json + example: !include inclusions/examples/story_body_example.json responses: 201: body: application/json: - schema: !include schemas/story_item_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/story_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml patch: description: Update multiple stories queryParameters: - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml _limit: displayName: Limit type: integer @@ -120,69 +49,22 @@ securedBy: [x_ticket_auth] example: 5 body: application/json: - example: !include examples/story_body_example.json + example: !include inclusions/examples/story_body_example.json responses: 200: body: application/json: - schema: !include schemas/collection_patch_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/collection_patch_response.json + headers: !include inclusions/yaml/demo_headers.yaml head: description: Determine whether a given resource is available - queryParameters: - q: - displayName: Query - type: string - required: false - example: foobar - minLength: 1 - _limit: - displayName: Limit - type: integer - required: false - minimum: 1 - example: 10 - _sort: - displayName: Start - type: string - required: false - enum: ["name", "description"] - _count: - displayName: Count - type: boolean - required: false + queryParameters: !include inclusions/yaml/collection_query_params.yaml responses: 200: - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + headers: !include inclusions/yaml/demo_headers.yaml options: description: Retrieve the available HTTP verbs for a given resource - responses: - 200: - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 0 - maximum: 0 - Allow: - displayName: AllowedMethods - description: Allowed methods - type: string - required: true + responses: !include inclusions/yaml/options_responses.yaml delete: description: Delete multiple stories queryParameters: @@ -198,22 +80,13 @@ securedBy: [x_ticket_auth] required: true minimum: 1 example: 10 - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml responses: 200: body: application/json: - schema: !include schemas/collection_delete_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/collection_delete_response.json + headers: !include inclusions/yaml/demo_headers.yaml /{id}: displayName: One story uriParameters: @@ -226,105 +99,52 @@ securedBy: [x_ticket_auth] 200: body: application/json: - schema: !include schemas/story_item_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/story_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml delete: description: Delete a particular story queryParameters: - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml responses: 200: body: application/json: - schema: !include schemas/item_delete_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/item_delete_response.json + headers: !include inclusions/yaml/demo_headers.yaml patch: description: Update a particular story queryParameters: - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: - example: !include examples/story_body_example.json + example: !include inclusions/examples/story_body_example.json responses: 200: body: application/json: - schema: !include schemas/story_item_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/story_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml put: description: Replace a particular story queryParameters: - _refresh_index: - displayName: RefreshIndex - type: boolean - required: false + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: - example: !include examples/story_body_example.json + example: !include inclusions/examples/story_body_example.json responses: 200: body: application/json: - schema: !include schemas/story_item_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/story_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml head: description: Determine whether a given resource is available responses: 200: - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + headers: !include inclusions/yaml/demo_headers.yaml options: description: Retrieve the available HTTP verbs for a given resource - responses: - 200: - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 0 - maximum: 0 - Allow: - displayName: AllowedMethods - description: Allowed methods - type: string - required: true + responses: !include inclusions/yaml/options_responses.yaml /users: securedBy: [read_only_useritem_everyone] displayName: All users @@ -334,19 +154,13 @@ securedBy: [x_ticket_auth] 200: body: application/json: - schema: !include schemas/collection_response.json - headers: - Content-Length: - displayName: ContentLength - description: Demo content length header - type: integer - required: true - minimum: 1 + schema: !include inclusions/schemas/collection_response.json + headers: !include inclusions/yaml/demo_headers.yaml post: description: Create a new user body: application/json: - schema: !include schemas/user.json + schema: !include inclusions/schemas/user.json patch: description: Update multiple users head: @@ -386,6 +200,6 @@ securedBy: [x_ticket_auth] description: Create a user's profile body: application/json: - schema: !include schemas/profile.json + schema: !include inclusions/schemas/profile.json patch: description: Update a user's profile diff --git a/examples/story_body_example.json b/inclusions/examples/story_body_example.json similarity index 100% rename from examples/story_body_example.json rename to inclusions/examples/story_body_example.json diff --git a/schemas/collection_delete_response.json b/inclusions/schemas/collection_delete_response.json similarity index 100% rename from schemas/collection_delete_response.json rename to inclusions/schemas/collection_delete_response.json diff --git a/schemas/collection_patch_response.json b/inclusions/schemas/collection_patch_response.json similarity index 100% rename from schemas/collection_patch_response.json rename to inclusions/schemas/collection_patch_response.json diff --git a/schemas/collection_response.json b/inclusions/schemas/collection_response.json similarity index 100% rename from schemas/collection_response.json rename to inclusions/schemas/collection_response.json diff --git a/schemas/item_delete_response.json b/inclusions/schemas/item_delete_response.json similarity index 100% rename from schemas/item_delete_response.json rename to inclusions/schemas/item_delete_response.json diff --git a/schemas/profile.json b/inclusions/schemas/profile.json similarity index 100% rename from schemas/profile.json rename to inclusions/schemas/profile.json diff --git a/schemas/story.json b/inclusions/schemas/story.json similarity index 100% rename from schemas/story.json rename to inclusions/schemas/story.json diff --git a/schemas/story_item_response.json b/inclusions/schemas/story_item_response.json similarity index 100% rename from schemas/story_item_response.json rename to inclusions/schemas/story_item_response.json diff --git a/schemas/user.json b/inclusions/schemas/user.json similarity index 100% rename from schemas/user.json rename to inclusions/schemas/user.json diff --git a/inclusions/yaml/collection_query_params.yaml b/inclusions/yaml/collection_query_params.yaml new file mode 100644 index 0000000..0775e4e --- /dev/null +++ b/inclusions/yaml/collection_query_params.yaml @@ -0,0 +1,21 @@ +q: + displayName: Query + type: string + required: false + example: foobar + minLength: 1 +_limit: + displayName: Limit + type: integer + required: false + minimum: 1 + example: 10 +_sort: + displayName: Start + type: string + required: false + enum: ["name", "description"] +_count: + displayName: Count + type: boolean + required: false \ No newline at end of file diff --git a/inclusions/yaml/demo_headers.yaml b/inclusions/yaml/demo_headers.yaml new file mode 100644 index 0000000..d94dac6 --- /dev/null +++ b/inclusions/yaml/demo_headers.yaml @@ -0,0 +1,6 @@ +Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 1 \ No newline at end of file diff --git a/inclusions/yaml/options_responses.yaml b/inclusions/yaml/options_responses.yaml new file mode 100644 index 0000000..db9c121 --- /dev/null +++ b/inclusions/yaml/options_responses.yaml @@ -0,0 +1,14 @@ +200: + headers: + Content-Length: + displayName: ContentLength + description: Demo content length header + type: integer + required: true + minimum: 0 + maximum: 0 + Allow: + displayName: AllowedMethods + description: Allowed methods + type: string + required: true \ No newline at end of file diff --git a/inclusions/yaml/refresh_index_param.yaml b/inclusions/yaml/refresh_index_param.yaml new file mode 100644 index 0000000..72ace41 --- /dev/null +++ b/inclusions/yaml/refresh_index_param.yaml @@ -0,0 +1,3 @@ +displayName: RefreshIndex +type: boolean +required: false \ No newline at end of file diff --git a/inclusions/yaml/security_schemes.yaml b/inclusions/yaml/security_schemes.yaml new file mode 100644 index 0000000..b35c79f --- /dev/null +++ b/inclusions/yaml/security_schemes.yaml @@ -0,0 +1,35 @@ +- x_token_auth: + description: Authorization header token policy + type: x-ApiKey + +- x_ticket_auth: + description: Standard Pyramid Auth Ticket policy + type: x-Ticket + settings: + secret: auth_tkt_secret + hashalg: sha512 + cookie_name: ramses_auth_tkt + http_only: true + +- read_only_users: + description: ACL that allows authenticated users to read collection + type: x-ACL + settings: + collection: | + allow admin all + allow authenticated get + item: | + allow admin all + allow authenticated get + +- read_only_useritem_everyone: + description: ACL that allows everyone to read item, authenticated users to read collection + type: x-ACL + settings: + collection: | + allow admin all + allow authenticated get + item: | + allow admin all + allow everyone get + allow {{user_self}} patch \ No newline at end of file From 7df572708d576bbf249e41b2b37d5299b3ad590e Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Wed, 29 Jul 2015 16:18:50 +0300 Subject: [PATCH 16/20] Define schemas for all resources --- example.raml | 134 +++++++++++++++++- inclusions/examples/groups_body_example.json | 1 + inclusions/examples/profile_body_example.json | 1 + .../examples/settings_body_example.json | 1 + inclusions/examples/user_body_example.json | 10 ++ inclusions/schemas/profile_item_response.json | 45 ++++++ inclusions/schemas/settings_response.json | 12 ++ inclusions/schemas/story_item_response.json | 4 +- inclusions/schemas/user_item_response.json | 75 ++++++++++ inclusions/yaml/collection_query_params.yaml | 7 +- 10 files changed, 280 insertions(+), 10 deletions(-) create mode 100644 inclusions/examples/groups_body_example.json create mode 100644 inclusions/examples/profile_body_example.json create mode 100644 inclusions/examples/settings_body_example.json create mode 100644 inclusions/examples/user_body_example.json create mode 100644 inclusions/schemas/profile_item_response.json create mode 100644 inclusions/schemas/settings_response.json create mode 100644 inclusions/schemas/user_item_response.json diff --git a/example.raml b/example.raml index 9a0c80c..28e26ad 100644 --- a/example.raml +++ b/example.raml @@ -91,7 +91,7 @@ securedBy: [x_ticket_auth] displayName: One story uriParameters: id: - displayName: User ID + displayName: StoryID type: integer get: description: Get a particular story @@ -145,11 +145,13 @@ securedBy: [x_ticket_auth] options: description: Retrieve the available HTTP verbs for a given resource responses: !include inclusions/yaml/options_responses.yaml + /users: securedBy: [read_only_useritem_everyone] displayName: All users get: description: Get all users + queryParameters: !include inclusions/yaml/collection_query_params.yaml responses: 200: body: @@ -158,48 +160,172 @@ securedBy: [x_ticket_auth] headers: !include inclusions/yaml/demo_headers.yaml post: description: Create a new user + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: schema: !include inclusions/schemas/user.json + example: !include inclusions/examples/user_body_example.json + responses: + 201: + body: + application/json: + schema: !include inclusions/schemas/user_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml patch: description: Update multiple users + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + _limit: + displayName: Limit + type: integer + required: true + example: 5 + body: + application/json: + example: !include inclusions/examples/user_body_example.json + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/collection_patch_response.json + headers: !include inclusions/yaml/demo_headers.yaml head: description: Determine whether a given resource is available + queryParameters: !include inclusions/yaml/collection_query_params.yaml + responses: + 200: + headers: !include inclusions/yaml/demo_headers.yaml options: description: Retrieve the available HTTP verbs for a given resource + responses: !include inclusions/yaml/options_responses.yaml /{username}: displayName: One user + uriParameters: + id: + displayName: Username + type: string get: description: Get a particular user + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/user_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml patch: - put: description: Update a particular user + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + body: + application/json: + example: !include inclusions/examples/user_body_example.json + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/user_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml + put: + description: Replace a particular user + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + body: + application/json: + example: !include inclusions/examples/user_body_example.json + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/user_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml delete: description: Delete a particular user - + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/item_delete_response.json + headers: !include inclusions/yaml/demo_headers.yaml /settings: displayName: User settings get: description: Get all settings of a particular user + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/settings_response.json + headers: !include inclusions/yaml/demo_headers.yaml post: description: Change a user's settings - + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + body: + application/json: + example: !include inclusions/examples/settings_body_example.json + responses: + 201: + body: + application/json: + schema: !include inclusions/schemas/settings_response.json + headers: !include inclusions/yaml/demo_headers.yaml /groups: displayName: User groups get: description: Get all groups of a particular user + responses: + 200: + headers: !include inclusions/yaml/demo_headers.yaml post: description: Change a user's groups + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + body: + application/json: + example: !include inclusions/examples/groups_body_example.json + responses: + 201: + headers: !include inclusions/yaml/demo_headers.yaml /profile: displayName: User profile get: description: Get a user's profile + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/profile_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml post: description: Create a user's profile + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: schema: !include inclusions/schemas/profile.json + example: !include inclusions/examples/profile_body_example.json + responses: + 201: + body: + application/json: + schema: !include inclusions/schemas/profile_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml + patch: description: Update a user's profile + queryParameters: + _refresh_index: !include inclusions/yaml/refresh_index_param.yaml + body: + application/json: + example: !include inclusions/examples/profile_body_example.json + responses: + 200: + body: + application/json: + schema: !include inclusions/schemas/profile_item_response.json + headers: !include inclusions/yaml/demo_headers.yaml diff --git a/inclusions/examples/groups_body_example.json b/inclusions/examples/groups_body_example.json new file mode 100644 index 0000000..710e732 --- /dev/null +++ b/inclusions/examples/groups_body_example.json @@ -0,0 +1 @@ +{"user": "bar", "admin": "foo"} \ No newline at end of file diff --git a/inclusions/examples/profile_body_example.json b/inclusions/examples/profile_body_example.json new file mode 100644 index 0000000..9b0e8ca --- /dev/null +++ b/inclusions/examples/profile_body_example.json @@ -0,0 +1 @@ +{"address": "Earth, Milky Way"} \ No newline at end of file diff --git a/inclusions/examples/settings_body_example.json b/inclusions/examples/settings_body_example.json new file mode 100644 index 0000000..18d7acf --- /dev/null +++ b/inclusions/examples/settings_body_example.json @@ -0,0 +1 @@ +{"foo": "bar"} \ No newline at end of file diff --git a/inclusions/examples/user_body_example.json b/inclusions/examples/user_body_example.json new file mode 100644 index 0000000..572844f --- /dev/null +++ b/inclusions/examples/user_body_example.json @@ -0,0 +1,10 @@ +{ + "username": "user12", + "password": "123456", + "email": "user12@domain.com", + "first_name": "John", + "last_name": "Doe", + "last_login": "2015-03-04T14:32:00Z", + "groups": ["user"], + "settings": {"foo": "bar"} +} \ No newline at end of file diff --git a/inclusions/schemas/profile_item_response.json b/inclusions/schemas/profile_item_response.json new file mode 100644 index 0000000..7d637d9 --- /dev/null +++ b/inclusions/schemas/profile_item_response.json @@ -0,0 +1,45 @@ +{ + "type": "object", + "title": "Story schema", + "$schema": "http://json-schema.org/draft-04/schema", + "properties": { + "_self": { + "type": "string", + "pattern": "http(s?)://" + }, + "id": { + "type": ["string", "integer"], + "minimum": 1 + }, + "_pk": { + "type": "string" + }, + "_type": { + "type": "string" + }, + "user_id": { + "type": "string" + }, + "user": { + "type": "string" + }, + "address": { + "type": "string" + }, + "created_at": { + "type": ["string", "null"], + "format": "date-time" + }, + "_version": { + "type": "integer" + }, + "updated_at": { + "type": ["string", "null"], + "format": "date-time" + } + }, + "required": [ + "_self", "id", "_pk", "_type", "user_id", "user", "address", + "created_at", "_version", "updated_at" + ] +} diff --git a/inclusions/schemas/settings_response.json b/inclusions/schemas/settings_response.json new file mode 100644 index 0000000..22fe881 --- /dev/null +++ b/inclusions/schemas/settings_response.json @@ -0,0 +1,12 @@ +{ + "id": "objectGetSchema", + "type": "object", + "title": "Collection response schema", + "$schema": "http://json-schema.org/draft-04/schema", + "properties": { + "foo": { + "type": "string" + } + }, + "required": ["foo"] +} \ No newline at end of file diff --git a/inclusions/schemas/story_item_response.json b/inclusions/schemas/story_item_response.json index 4b54932..b6f8baf 100644 --- a/inclusions/schemas/story_item_response.json +++ b/inclusions/schemas/story_item_response.json @@ -2,8 +2,6 @@ "type": "object", "title": "Story schema", "$schema": "http://json-schema.org/draft-04/schema", - "auth_fields": ["id", "start_date", "due_date", "name", "description", "progress"], - "public_fields": ["id", "start_date", "due_date", "name"], "properties": { "_self": { "type": "string", @@ -39,7 +37,7 @@ "format": "date-time" }, "id": { - "type": ["integer", "string"], + "type": ["string", "integer"], "minimum": 1 }, "_pk": { diff --git a/inclusions/schemas/user_item_response.json b/inclusions/schemas/user_item_response.json new file mode 100644 index 0000000..0fe96d7 --- /dev/null +++ b/inclusions/schemas/user_item_response.json @@ -0,0 +1,75 @@ +{ + "type": "object", + "title": "Story schema", + "$schema": "http://json-schema.org/draft-04/schema", + "properties": { + "_self": { + "type": "string", + "pattern": "http(s?)://" + }, + "_pk": { + "type": "string" + }, + "username": { + "type": "string" + }, + "password": { + "type": "string" + }, + "email": { + "type": "string", + "format": "email" + }, + "status": { + "type": ["string", "null"] + }, + "id": { + "type": ["string", "integer", "null"] + }, + "first_name": { + "type": ["string", "null"] + }, + "last_name": { + "type": ["string", "null"] + }, + "assigned_stories": { + "type": ["array", "null"] + }, + "stories": { + "type": ["array", "null"] + }, + "settings": { + "type": ["object", "null"] + }, + "created_at": { + "type": ["string", "null"], + "format": "date-time" + }, + "last_login": { + "type": ["string", "null"], + "format": "date-time" + }, + "_version": { + "type": "integer" + }, + "_type": { + "type": "string" + }, + "updated_at": { + "type": ["string", "null"], + "format": "date-time" + }, + "profile": { + "type": ["object", "null"] + }, + "groups": { + "type": ["array", "null"], + } + }, + "required": [ + "_self", "_pk", "username", "password", "email", "status", "id", + "first_name", "last_name", "assigned_stories", "stories", + "settings", "created_at", "last_login", "_version", "_type", + "updated_at", "profile", "groups" + ] +} diff --git a/inclusions/yaml/collection_query_params.yaml b/inclusions/yaml/collection_query_params.yaml index 0775e4e..d7c0baf 100644 --- a/inclusions/yaml/collection_query_params.yaml +++ b/inclusions/yaml/collection_query_params.yaml @@ -10,11 +10,12 @@ _limit: required: false minimum: 1 example: 10 -_sort: +_start: displayName: Start - type: string + type: integer required: false - enum: ["name", "description"] + minimum: 1 + example: 12 _count: displayName: Count type: boolean From a423cf8a72d4fd9f268cc174d8a78bd4c4a2c1e9 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 31 Jul 2015 11:43:29 +0300 Subject: [PATCH 17/20] Add schemas to stories PUT, user PUT. Remove fields from user body example' --- example.raml | 2 ++ inclusions/examples/user_body_example.json | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example.raml b/example.raml index 28e26ad..eb68464 100644 --- a/example.raml +++ b/example.raml @@ -130,6 +130,7 @@ securedBy: [x_ticket_auth] _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: + schema: !include inclusions/schemas/story.json example: !include inclusions/examples/story_body_example.json responses: 200: @@ -233,6 +234,7 @@ securedBy: [x_ticket_auth] _refresh_index: !include inclusions/yaml/refresh_index_param.yaml body: application/json: + schema: !include inclusions/schemas/user.json example: !include inclusions/examples/user_body_example.json responses: 200: diff --git a/inclusions/examples/user_body_example.json b/inclusions/examples/user_body_example.json index 572844f..e0ee7fa 100644 --- a/inclusions/examples/user_body_example.json +++ b/inclusions/examples/user_body_example.json @@ -1,7 +1,5 @@ { - "username": "user12", "password": "123456", - "email": "user12@domain.com", "first_name": "John", "last_name": "Doe", "last_login": "2015-03-04T14:32:00Z", From 26ba9504c2cf9e74651a0cfb0de9d763647f9183 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 31 Jul 2015 12:35:27 +0300 Subject: [PATCH 18/20] Fix profile body example tab --- example.raml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.raml b/example.raml index eb68464..5c2ed8b 100644 --- a/example.raml +++ b/example.raml @@ -310,7 +310,7 @@ securedBy: [x_ticket_auth] body: application/json: schema: !include inclusions/schemas/profile.json - example: !include inclusions/examples/profile_body_example.json + example: !include inclusions/examples/profile_body_example.json responses: 201: body: From 0ff83157af92e806a8b3d6854dbbcfbcb7c1d95f Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 31 Jul 2015 12:44:51 +0300 Subject: [PATCH 19/20] Fix required fields in schemas --- inclusions/schemas/profile_item_response.json | 2 +- inclusions/schemas/story_item_response.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inclusions/schemas/profile_item_response.json b/inclusions/schemas/profile_item_response.json index 7d637d9..df7965c 100644 --- a/inclusions/schemas/profile_item_response.json +++ b/inclusions/schemas/profile_item_response.json @@ -39,7 +39,7 @@ } }, "required": [ - "_self", "id", "_pk", "_type", "user_id", "user", "address", + "_self", "id", "_pk", "_type", "user", "address", "created_at", "_version", "updated_at" ] } diff --git a/inclusions/schemas/story_item_response.json b/inclusions/schemas/story_item_response.json index b6f8baf..32ccc3b 100644 --- a/inclusions/schemas/story_item_response.json +++ b/inclusions/schemas/story_item_response.json @@ -97,8 +97,8 @@ }, "required": [ "_self", "rating", "signs_number", "available_for", "updated_at", - "assignee_id", "assignee", "reads", "owner", "valid_date", "id", - "_pk", "attachment", "progress", "price", "owner_id", "due_date", + "assignee", "reads", "owner", "valid_date", "id", + "_pk", "attachment", "progress", "price", "due_date", "_type", "arbitrary_object", "description", "valid_time", "unicode_description", "completed", "name", "created_at", "_version", "start_date", "unicode_name" From dcf8489bca365fefbac0f5047a091964e73eab86 Mon Sep 17 00:00:00 2001 From: Artem Kostiuk Date: Fri, 31 Jul 2015 15:59:47 +0300 Subject: [PATCH 20/20] Remove id definition in user schemas --- inclusions/schemas/user_item_response.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/inclusions/schemas/user_item_response.json b/inclusions/schemas/user_item_response.json index 0fe96d7..47288bc 100644 --- a/inclusions/schemas/user_item_response.json +++ b/inclusions/schemas/user_item_response.json @@ -23,9 +23,6 @@ "status": { "type": ["string", "null"] }, - "id": { - "type": ["string", "integer", "null"] - }, "first_name": { "type": ["string", "null"] }, @@ -67,7 +64,7 @@ } }, "required": [ - "_self", "_pk", "username", "password", "email", "status", "id", + "_self", "_pk", "username", "password", "email", "status", "first_name", "last_name", "assigned_stories", "stories", "settings", "created_at", "last_login", "_version", "_type", "updated_at", "profile", "groups"