Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link schema required property #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions example/doc/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,80 @@
"object"
],
"definitions": {
"coupon": {
"$schema": "http://json-schema.org/draft-04/hyper-schema",
"title": "User",
"description": "This resource represents coupon",
"stability": "prototype",
"strictProperties": true,
"type": [
"object"
],
"definitions": {
"id": {
"description": "coupon id",
"example": "ec0a1edc-062e-11e7-8b1e-040ccee2aa06",
"readOnly": true,
"format": "uuid",
"type": [
"string"
]
},
"name": {
"description": "coupon name",
"example": "first time task complete",
"readOnly": true,
"type": [
"string"
]
},
"code": {
"description": "coupon code",
"example": "1234abcd",
"readOnly": true,
"type": [
"string"
]
}
},
"links": [
{
"description": "Redeem coupon",
"href": "/coupon/redeem",
"title": "redeem",
"method": "POST",
"rel": "create",
"schema": {
"properties": {
"code": {
"$ref": "#/definitions/coupon/definitions/code"
}
},
"required": [
"code"
],
"type": [
"object"
]
}
}
],
"properties": {
"id": {
"$ref": "#/definitions/coupon/definitions/id"
},
"name": {
"$ref": "#/definitions/coupon/definitions/name"
},
"code": {
"$ref": "#/definitions/coupon/definitions/code"
}
},
"required": [
"id",
"name"
]
},
"error": {
"$schema": "http://json-schema.org/draft-04/hyper-schema",
"title": "Error",
Expand Down Expand Up @@ -350,6 +424,9 @@
}
},
"properties": {
"coupon": {
"$ref": "#/definitions/coupon"
},
"error": {
"$ref": "#/definitions/error"
},
Expand Down
58 changes: 58 additions & 0 deletions example/doc/schema/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Tasky-App-Version 1.0.0

## The table of contents

- <a href="#resource-coupon">User</a>
- <a href="#link-POST-coupon-/coupon/redeem">POST /coupon/redeem</a>
- <a href="#resource-error">Error</a>
- <a href="#resource-task">Task</a>
- <a href="#link-GET-task-/tasks/{(%23%2Fdefinitions%2Ftask%2Fdefinitions%2Fidentity)}">GET /tasks/{task_id}</a>
Expand All @@ -31,6 +33,62 @@ Tasky-App-Version 1.0.0
- <a href="#resource-user">User</a>
- <a href="#link-GET-user-/me">GET /me</a>

## <a name="resource-coupon">User</a>

Stability: `prototype`

This resource represents coupon

### Attributes

| Name | Type | Description | Example |
| ------- | ------- | ------- | ------- |
| **code** | *string* | coupon code | `"1234abcd"` |
| **id** | *uuid* | coupon id | `"ec0a1edc-062e-11e7-8b1e-040ccee2aa06"` |
| **name** | *string* | coupon name | `"first time task complete"` |

### <a name="link-POST-coupon-/coupon/redeem">User redeem</a>

Redeem coupon

```
POST /coupon/redeem
```

#### Required Parameters

| Name | Type | Description | Example |
| ------- | ------- | ------- | ------- |
| **code** | *string* | coupon code | `"1234abcd"` |



#### Curl Example

```bash
$ curl -n -X POST https://tasky.io/v1/coupon/redeem \
-d '{
"code": "1234abcd"
}' \
-H "Content-Type: application/json"
```


#### Response Example

```
HTTP/1.1 201 Created
```

```json
{
"id": "ec0a1edc-062e-11e7-8b1e-040ccee2aa06",
"name": "first time task complete",
"code": "1234abcd"
}
```


## <a name="resource-error">Error</a>

Stability: `prototype`
Expand Down
53 changes: 53 additions & 0 deletions example/doc/schema/schemata/coupon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
"$schema": http://json-schema.org/draft-04/hyper-schema
title: User
description: This resource represents coupon
stability: prototype
strictProperties: true
type:
- object
definitions:
id:
description: coupon id
example: "ec0a1edc-062e-11e7-8b1e-040ccee2aa06"
readOnly: true
format: uuid
type:
- string
name:
description: coupon name
example: "first time task complete"
readOnly: true
type:
- string
code:
description: coupon code
example: "1234abcd"
readOnly: true
type:
- string
links:
- description: "Redeem coupon"
href: "/coupon/redeem"
title: redeem
method: POST
rel: create
schema:
properties:
code:
$ref: "/schemata/coupon#/definitions/code"
required:
- code
type:
- object
properties:
id:
$ref: "/schemata/coupon#/definitions/id"
name:
$ref: "/schemata/coupon#/definitions/name"
code:
$ref: "/schemata/coupon#/definitions/code"
required:
- id
- name
id: schemata/coupon
19 changes: 18 additions & 1 deletion example/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package taskyapi

import "time"

// Coupon struct for coupon resource
type Coupon struct {
Code string `json:"code,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
}

// Error struct for error resource
type Error struct {
Code string `json:"code"`
Expand Down Expand Up @@ -31,6 +38,16 @@ type User struct {
Name string `json:"name"`
}

// CouponCreateRequest struct for coupon
// POST: /coupon/redeem
type CouponCreateRequest struct {
Code string `json:"code"`
}

// CouponCreateResponse struct for coupon
// POST: /coupon/redeem
type CouponCreateResponse Coupon

// TaskInstancesRequest struct for task
// GET: /tasks
type TaskInstancesRequest struct {
Expand All @@ -49,7 +66,7 @@ type TaskSelfResponse Task
// TaskCreateRequest struct for task
// POST: /tasks
type TaskCreateRequest struct {
Tags []string `json:"tags"`
Tags []string `json:"tags,omitempty"`
Title string `json:"title"`
}

Expand Down
Loading