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

OPTIONS method returns schema #116

Merged
merged 4 commits into from
Jul 29, 2017
Merged

OPTIONS method returns schema #116

merged 4 commits into from
Jul 29, 2017

Conversation

koriym
Copy link
Member

@koriym koriym commented Jul 29, 2017

Resource class

use BEAR\Resource\Annotation\JsonSchema;
use BEAR\Resource\ResourceObject;

class User extends ResourceObject
{
    /**
     * User
     *
     * Returns a variety of information about the user specified by the required $id parameter
     *
     * @param string $id User ID
     *
     * @JsonSchema(schema="user.json")
     */
    public function onGet($id)
    {
        return $this;
    }
}

Json Schema

user.json

{
  "type": "object",
  "properties": {
    "name": { "$ref": "name.json#/definitions/name"},
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 20
    }
  },
  "required": ["name", "age"]
}

name.json

{
  "title": "Name",
  "definitions": {
    "name": {
      "type": "object",
      "properties": {
        "firstName": {"type": "string"},
        "lastName": {"type": "string"}
      },
      "required": ["firstName", "lastName"]
    }
  }
}

Request

OPTIONS /user

Response returns request and response meta information .

{
    "GET": {
        "summary": "User",
        "description": "Returns a variety of information about the user specified by the required $id parameter",
        "request": {
            "parameters": {
                "id": {
                    "type": "string",
                    "description": "User ID"
                }
            },
            "required": [
                "id"
            ]
        },
        "schema": {
            "type": "object",
            "properties": {
                "name": {
                    "$ref": "name.json#/definitions/name"
                },
                "age": {
                    "type": "integer",
                    "description": "Age in years",
                    "minimum": 20
                }
            },
            "required": [
                "name",
                "age"
            ]
        }
    }
}

Install

$this->install(JsonSchemalModule($jsonSchemaDir, $jsonValidateDir))

@koriym koriym added the Feature label Jul 29, 2017
@koriym koriym merged commit ad6346e into bearsunday:1.x Jul 29, 2017
@koriym koriym deleted the options-schema branch July 29, 2017 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant