cybertk / ramlev Goto Github PK
View Code? Open in Web Editor NEWValidate/Verify examples in RAML
License: Other
Validate/Verify examples in RAML
License: Other
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!
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
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}
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:
Any idea what I'm doing wrong?
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.
$this->body
which doesn't exist. It should use $this->bodyList
instead.$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).
Doesn't seem to work for RAML 1.0. I notice that you have to use raml-js-parser-2 to get 1.0 parsing.
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:
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.
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.
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.
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)
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,
--schema-type
to specify schema type, which will used to select the underling schema validator, and delegate the validating job to pluggable schema validatorFailed 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.