Code Monkey home page Code Monkey logo

ramlev's Introduction

ramlev's People

Contributors

andrenpaes avatar bitdeli-chef avatar cybertk avatar greenkeeperio-bot avatar pateketrueke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ramlev's Issues

release new ramlev version

Hi,

working together with @andrenpaes on the same project, where we would like to use ramlev. Actually we need a version that includes his latest accepted PR.

Tried to reference this repo as snapshot in our package.json (i am not really an node/npm expert ;)) but due to the .npmignore file it doesn't include the sources.

Could you release a new version or give me a hint how i easily could reference a snapshot version?

Thx!

Can't include sub schemas from separate files

I'm having trouble including sub schemas from different files.

Here's an example.

git clone https://github.com/thebinarypenguin/raml-example.git
cd raml-example
ramlev spec/api.raml

Cannot test correctly when there are multiple invalid endpoints

Given a raml contains multiple invalid endpoints like following, ramlev tells that all endpoints are invalid

#%RAML 0.8

title: World Music API
baseUri: http://example.api.com/{version}
version: v1
mediaType: application/json

traits:
  - paged:
      queryParameters:
        pages:
          description: The number of pages to return
          type: number
/songs:
  is: [ paged ]
  get:
    queryParameters:
      genre:
        description: filter the songs by genre

  /{songId}:
    get:
      responses:
        200:
          body:
            schema: |
              { "$schema": "http://json-schema.org/schema",
                "type": "object",
                "properties": {
                  "title":  { "type": "string" }
                }
              }
            example: |
              {"title": "foo"}

  /search:
    get:
      responses:
        200:
          body:
            schema: |
              { "$schema": "http://json-schema.org/schema",
                "type": "object",
                "properties": {
                  "foo":  { "type": "integer" }
                }
              }
            example: |
              {"foo": "bar"}

  /authors:
    get:
      responses:
        200:
          body:
            schema: |
              { "$schema": "http://json-schema.org/schema",
                "type": "object",
                "properties": {
                  "bar":  { "type": "string" }
                }
              }
            example: |
              {"bar": 1}

Missing properties not caught?

Here's a raml file (adapted from the RAML 200 tutorial example):

#%RAML 0.8

---
title: Jukebox API


/songs:
  get:
    responses:
      200:
        body:
          application/json:
            schema: |
              {
                "type": "object",
                "$schema": "http://json-schema.org/draft-03/schema",
                "id": "http://jsonschema.net",
                "required": true,
                "properties": {
                  "songTitle": {
                    "type": "string",
                    "required": true
                  }
                }
              }
            example: |
              {
                "foo": "Get Lucky"
              }

And here's what happens when I test my example against the schema.

./dev_deps/node_modules/.bin/ramlev ./test.raml 


  /songs
    ✓ GET response 200 


  1 passing (11ms)

I would have expected the test to fail because:

  1. the required property "songTitle" isn't in the example
  2. there's an unexpected property named "foo" in the example

Any idea what I'm doing wrong?

improve output on invalid JSON in an example

When an example isn't valid JSON, the error you get looks like this:
AssertionError: Invalid JSON:
undefined
Error: expected [Function] to not throw an error but 'SyntaxError: Unexpected string' was thrown

Followed by a stack trace. It would be nice if:
a) the error identified that it was the example and not the json schema that was invalid.
b) the error provided more information about what was invalid, perhaps via something like json-lint

This seems in the same vein as issue #19.

Method::getExampleByType is broken (beyond repair?)

  1. Method::getExampleByType uses $this->body which doesn't exist. It should use $this->bodyList instead.
  2. $this->bodyList contains BodyInterface elements, but unfortunately BodyInterface is rather limited, so it's impossible to check if it has an example without widening the interface.

Since the same thing can be achieved without using this helper method, I suggest this method is removed (or fixed).

Clean up validation outputs

Currently, the outputs of validation is raw mocha results, it's a bit verbose.

Like,

  21) /repos/{ownerId}/{repoId}/milestones POST response 201:
     AssertionError: Got unexpected response body:
{
    "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
    "number": 1,
    "state": "open",
    "title": "v1.0",
    "description": "",
    "creator": {
        "login": "octocat",
        "id": 1,
        "avatar_url": "https://github.com/images/error/octocat_happy.gif",
        "gravatar_id": "somehexcode",
        "url": "https://api.github.com/users/octocat"
    },
    "open_issues": 4,
    "closed_issues": 8,
    "created_at": "2011-04-10T20:09:31Z",
    "due_on": null
}
Error: expected value to match json-schema '{"$schema":"http://json-schema...' -> '{"url":"https://api.github.com...'
      invalid type: null (expected string)
          schema: {"$schema":"http://json-schema.org/draft-03/schema","type":"...
          rule:   /properties/due_on/type -> "string"
          field:  /due_on -> null: null
      at Function.assert.jsonSchema (/usr/local/lib/node_modules/ramlev/node_modules/chai-json-schema/index.js:176:40)
      at Test.assertExample (/usr/local/lib/node_modules/ramlev/lib/test.js:77:21)
      at Test.assertExample (/usr/local/lib/node_modules/ramlev/lib/test.js:3:61)
      at Test.run (/usr/local/lib/node_modules/ramlev/lib/test.js:56:21)
      at Object.suite.addTest.Mocha.Test._.bind.test (/usr/local/lib/node_modules/ramlev/lib/test-runner.js:37:19)
      at Test.Runnable.run (/usr/local/lib/node_modules/ramlev/node_modules/mocha/lib/runnable.js:217:15)
      at Runner.runTest (/usr/local/lib/node_modules/ramlev/node_modules/mocha/lib/runner.js:373:10)
      at /usr/local/lib/node_modules/ramlev/node_modules/mocha/lib/runner.js:451:12
      at next (/usr/local/lib/node_modules/ramlev/node_modules/mocha/lib/runner.js:298:14)
      at /usr/local/lib/node_modules/ramlev/node_modules/mocha/lib/runner.js:308:7

Places can improve:

  • Remove error stack
  • Locate the line # of invalid example in RAML
  • Better error output for json

Cannot read relative paths?

Hi, I'm playing with ramlev to write a grunt-plugin but it can't load any relative file.

new Ramlev({
  ramlPath: path.resolve(__dirname + '/../example/index.raml')
}).run();

Output:

{ [Error: cannot read ./people/collection/index.raml (Error: ENOENT, open './people/collection/index.raml')]
  context: 'while reading ./people/collection/index.raml',
  context_mark: null,
  message: 'cannot read ./people/collection/index.raml (Error: ENOENT, open \'./people/collection/index.raml\')',
  problem_mark:
   { name: undefined,
     line: 5,
     column: 9,
     buffer: '#%RAML 0.8\n\ntitle: My API\nversion: 0.1.0\n\n/people: !include ./people/collection/index.raml\n\u0000',
     pointer: 51 },
  note: undefined }
cannot read ./people/collection/index.raml (Error: ENOENT, open './people/collection/index.raml')

I did the same with raml4js and works perfectly.

Schema reference not found with -f option

I only discovered this by using these patches, but if $ref is used to refer to another schema file, and the -f and -d options are used, the schema file is opened but for some reason, is still reported as missing. At least, on my machine.

ramlev validation challenge

I am looking to use ramlev in my project

Have uploaded a working sample project in
https://github.com/eswarantg/sampleRestIf_RAML

The goal here is to organize the Interface and schema files across folders.
using commandline : ramlev $1 -f $BASE_URL -d "$SCHEMA_DIR"

I get the following output
/doctors
✓ GET response 200
✓ GET response 204
✓ POST request
✓ POST response 209

/doctors/{doctorId}
✓ GET response 200
✓ GET response 404
✓ POST request
✓ POST response 200
✓ POST response 209
✓ POST response 404
✓ DELETE response 200
✓ DELETE response 404

/patients
✓ GET response 200
✓ GET response 204

/patients/{patientId}
✓ GET response 200
✓ GET response 404

16 passing (16ms)

I expect the GET "/patients/{patientId}" to fail due to the wrong data
{
"ID" : "ERR",
"name" : "PQRS",
"sex" : "Male",
"diagnosis" : [
"Fracture in left leg"
,"15 days rest"
]
}

ID is integer type.

I bet i am missing something here.

TypeError: Cannot read property 'body' of null

When executing command ramlev a.raml, it failed with

TypeError: Cannot read property 'body' of null
      at Context.<anonymous> (/Users/quanlong/projects/raml-example-validator/lib/generate-tests.js:67:53)
      at callFn (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runnable.js:250:21)
      at Test.Runnable.run (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runnable.js:243:7)
      at Runner.runTest (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:373:10)
      at /Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:451:12
      at next (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:298:14)
      at /Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:308:7
      at next (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:246:23)
      at Object._onImmediate (/Users/quanlong/projects/raml-example-validator/node_modules/mocha/lib/runner.js:275:5)
      at processImmediate [as _immediateCallback] (timers.js:336:15)

Better way to support various schema types

In current design, ramlev detects schema type by scanning the content of schema, it's not good and accurate if ramlev is used to support any kind of schema.

Proposal,

  • Make ramelv un-aware of specific schema type, let specific schema validator pluggable.
  • Provide a CLI options --schema-type to specify schema type, which will used to select the underling schema validator, and delegate the validating job to pluggable schema validator

Failed to deploy to npm

Failed to deploy to npm for v0.4.0 on Travis CI

NPM API key format changed recently. If your deployment fails, check your API key in ~/.npmrc.
http://docs.travis-ci.com/user/deployment/npm/
npm ERR! need auth auth and email required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! System Linux 3.13.0-40-generic
npm ERR! command "/home/travis/.nvm/v0.10.40/bin/node" "/home/travis/.nvm/v0.10.40/bin/npm" "publish"
npm ERR! cwd /home/travis/build/cybertk/ramlev
npm ERR! node -v v0.10.40
npm ERR! npm -v 1.4.28
npm ERR! code ENEEDAUTH
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/travis/build/cybertk/ramlev/npm-debug.log
npm ERR! not ok code 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.