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

Automating testing, documentation and validation with JSON schema in hapi #131

Closed
ptte opened this issue Nov 21, 2014 · 4 comments
Closed
Labels

Comments

@ptte
Copy link

ptte commented Nov 21, 2014

At bloglovin, we have started building services on top of hapi, which is a beautiful framework.

One of the things we wanted to achieve however was to automatically generate documentation for our different endpoints/services.

Starting with a routes file we realized that we we're missing more information about the incoming and outgoing data, and we did not see how we could get there with JOI.

By writing schemas in json/yaml, we allow for the whole range of validation structures that's supported by the JSON schema standard. It also makes it possible to add meta data around the data we're describing, so as to make automatic documentation of endpoints more elaborate, and easier.

We have also worked with allowing validation of outgoing data, so as to be able to automate/heavily simplify (turns out it's really hard to fully automate the creation of the tests) integration testing. This also really improves the documentation abilities.

On top of this, we support versioning of schemas, which is useful if you want to have multiple versions of an api running at the same time.

An example of a schema (not used in production).

id: PROJECT://schemas/search/requests/create-user-1.0.0
$schema: "http://json-schema.org/draft-03/schema#"
definitions:
  path:
    type: object
    additionalProperties: false
    properties:
      id:
        type: number
        description: The id of the user to create.
  payload:
    type: object
    additionalProperties: false
    properties:
      name:
        type: string
        description: A users full name
        required: true
      username:
        type: string
        description: "Username for user, A-z only"
        required: true
      avatar:
        type: boolean
        description: We want to know if a user has an avatar or not
        required: true
      location:
        type: string
        description: "Simple comma separated string of locations (Stockholm, Sweden)"
        required: true
      about:
        type: string
        description: The users description
        required: true
@hueniverse
Copy link

Hey @ptte can you rework the title and abstract to make is clear this is a different talk from the one @reid is planning #117

@ptte ptte changed the title json/yaml schema validation and documentation using hapi Automating testing, documentation and validation with JSON schema in hapi Dec 1, 2014
@ptte
Copy link
Author

ptte commented Dec 1, 2014

@hueniverse I've updated the description and title. Hope it's a bit more clear.

Does accepted mean that I should plan to go to oakland? :)

@mikeal
Copy link
Member

mikeal commented Dec 1, 2014

yes ;)

@hueniverse
Copy link

Close due to speak change in availability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants