mulesoft / osprey Goto Github PK
View Code? Open in Web Editor NEWGenerate Node.JS API middleware from a RAML definition
License: Other
Generate Node.JS API middleware from a RAML definition
License: Other
Using /
builds invalid urls while an empty string will throw an error.
When using !include (relative paths, included files are in the same folder as the RAML-file), the API Console gets the paths wrong, displaying:
{"context":"while fetching /user.schema.json", [...],
"message":"cannot fetch /user.schema.json (Not Found)" [...]
This has been working until this commit. So if I add the trailing slash in line 14 in dist/assets/console/index.html
back, so that it says
<raml-console src="apiPath/" with-root-documentation></raml-console>
then the console is working again.
To reproduce you can setup a minimal project using osprey-cli utilizing any RAML-file containing an !include directive with a relative path, like e.g.
schemas:
- user: !include user.schema.json
Would adding the slash back break anything?
Possibly Github Pages
Not possible to install via npm install osprey -g
(Linux Mint 16 Petra)
../vendor/libxml/xpath.c: In function ‘xmlXPathNodeCollectAndTest’:
../vendor/libxml/xpath.c:12401:28: warning: comparison between ‘xmlElementType’ and ‘xmlXPathTypeVal’ [-Wenum-compare]
} else if (cur->type == type) {
^
../vendor/libxml/xpath.c:12402:13: warning: comparison between ‘xmlXPathTypeVal’ and ‘enum <anonymous>’ [-Wenum-compare]
if (type == XML_NAMESPACE_DECL)
^
In file included from ../vendor/libxml/xpath.c:185:0:
../vendor/libxml/xpath.c: At top level:
../vendor/libxml/trionan.c:218:1: warning: ‘trio_is_negative’ defined but not used [-Wunused-function]
trio_is_negative
^
CC(target) Release/obj.target/libxml/vendor/libxml/xpointer.o
../vendor/libxml/xpointer.c: In function ‘xmlXPtrNewRangeNodePoint’:
../vendor/libxml/xpointer.c:451:21: warning: comparison between ‘xmlElementType’ and ‘enum <anonymous>’ [-Wenum-compare]
if (start->type != XPATH_POINT)
^
AR(target) Release/obj.target/vendor/libxml/xml.a
COPY Release/xml.a
CXX(target) Release/obj.target/xmljs/src/libxmljs.o
make: g++: Command not found
make: *** [Release/obj.target/xmljs/src/libxmljs.o] Error 127
make: Leaving directory `/home/xxx/dev/osprey/node_modules/osprey-resources/node_modules/osprey-method-handler/node_modules/libxmljs/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.11.0-12-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/xxx/dev/osprey/node_modules/osprey-resources/node_modules/osprey-method-handler/node_modules/libxmljs
gyp ERR! node -v v0.10.15
gyp ERR! node-gyp -v v0.10.9
gyp ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/xxx/dev/osprey/npm-debug.log
npm ERR! not ok code 0
Registering the console triggers express to mount the router middleware, which is occurring before any Osprey middleware is registered since it's async. The best fix for this would be to make Osprey mount "placeholder" middlewares that don't do anything until the async raml is loaded.
It doesn't matter what the express app is configured, osprey always serves the paths in the console with http://localhost:3000/
The protocol could be http or https.
The host may or may not be localhost.
The port may or may not be 3000.
But at least the base path is respected.
If I throw an exception* (ie: call null.a.b
) in a method of one of my controllers that gets called on a route defined inside osprey api wrapper, that exception isn't shown on the terminal and a 404 response is returned to the client.
One probable cause is that exception are not re-thrown inside .catch
handler on osprey promise chain.
This will warn through logging if the response is correct. Example: if a response header is ok based on RAML or if all the required headers are being send on response.
Osprey does not provide validation for nested resources that have URI validation. For example, the below resource will validate apiVersionId
if the path is /abc/123
, while apiId
will only validate when the path is /123
.
/{apiId}:
uriParameters:
apiId:
type: integer
minimum: 1
/{apiVersionId}:
uriParameters:
apiVersionId:
type: integer
minimum: 1
Trying to load console with the project generated from example league.raml, I see the following content from http://localhost:3000/api/console:
{"context":"while fetching /api/","context_mark":null,"message":"cannot fetch /api/ (while fetching /api/\ncannot fetch /api/ (NetworkError: A network error occurred.), check that the server is up and that CORS is enabled)","problem_mark":null}
From the command line I see the following output:
local:~/sites/raml-workshop/osprey_test/leagues-app (master)$ node src/app.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Osprey: Osprey::APIConsole has been initialized successfully listening at /api/console
listening on port 3000
GET /api/console 200 19ms - 605b
GET /api/console/styles/app.css 304 9ms
GET /api/console/scripts/vendor.js 304 9ms
GET /api/console/scripts/app.js 304 6ms
/home/gimballock/sites/raml-workshop/osprey_test/leagues-app/node_modules/osprey/dist/osprey.js:78
data = data.toString().replace(/^baseUri:.*$/gmi, "baseUri: " + ap
^
TypeError: Cannot call method 'toString' of undefined
at /home/gimballock/sites/raml-workshop/osprey_test/leagues-app/node_modules/osprey/dist/osprey.js:78:25
at fs.js:207:20
at Object.oncomplete (fs.js:107:15)
Hi!
I was wondering if there was some code somewhere I could hack on with the beginnings of the mock data cli module for osprey 0.2.0-alpha.
I'm starting to use that app I have and could REALLY REALLY use the ability to serve the example json responses as mock data based on the baseUrl and defined routes in the raml.
If there isn't anything hacked out yet, any pointers would be most helpful.
Thanks for all of your help. I'll try not to be too impatient. :)
if you have a RAML like:
#%RAML 0.8
title: sample
/resource:
patch:
Osprey silently fails
There's an osprey-router error that crashes [email protected] node_modules/osprey
when running with expressJS v4+ and latest version of nodeJS
Here are the details:
mulesoft-labs/osprey-router#1
Thanks for all of your hard work with this!
The passed in exception handlers override the defaults, which means any future Osprey instances will inherit from the first one and any future exception handlers will override past ones.
libxml is not working on Windows environment. So, it would be great to make it configurable.
it appears osprey.create does some async stuff and so a caller should be able to pass a done function and be called when this async process completes -- i.e. setting up routes, etc. without the callback, we have to put waits in our code
https://github.com/mulesoft/osprey/blob/master/src/middlewares/validation.coffee#L63 doesn't check it can actually parse JSON before crashing
the baseUri property of the raml file should be updated with the servers actual full path (protocol, host, [port,] path).
This does not happen at all for the raml served at //api.raml.
The incorrect url is substituted for the raml served at / (It always puts http://localhost:3000/). The protocol and port are ignored and probably the host as well.
See details here: mulesoft-labs/osprey-mock-service#2
Running my integration tests involves having to initialize osprey multiple times, but it fails to overwrite the resources on subsequent test runs (I’m not seeing the ‘RAML successfully loaded’ message and the ‘Overwritten resource’ messages anymore after the first test). This causes the tests to fail since supertest start getting mocked results. It looks like the file is being cached based on the code, so is there a way to turn off the cache or have osprey overwrite the endpoints every time?
Osprey serves the raml file with
Content-type: application/octet-stream
this causes the file to be downloaded instead of being viewed in the browser.
How about using the following?
Content-type: text/yaml
If I were using osprey, I would expect that it would create a express application which I could then use however I see fit. This means I could mount it to my normal application or use it as the base of the application. There are also a lot of benefits to this approach:
Basic usage:
app.use('/api', osprey.create({
ramlFile: path.join(__dirname, '/assets/raml/api.raml')
}));
Example:
var api = osprey.create({
ramlFile: path.join(__dirname, '/assets/raml/api.raml')
});
api.get('/resource', function(req, res) {
//// Your business logic here!
});
app.use('/api', api);
Both the / and //api.raml serve the raml file. Shouldn't only one of them do this?
I'd imagine //api.raml is the correct path.
When using the required: false
flag, it will still attempt to validate the type even when it's empty.
Given the following code which integrate osprey with express4. It returns Cannot GET /api/xxx
for every path.
var express = require('express');
var path = require('path');
var osprey = require('osprey');
var app = module.exports = express();
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compress());
app.use(express.logger('dev'));
app.set('port', process.env.PORT || 3000);
api = osprey.create('/1', app, {
ramlFile: path.join(__dirname, 'api.raml'),
enableValidations: false,
logLevel: 'debug' // logLevel: off->No logs | info->Show Osprey modules initializations | debug->Show all
});
if (!module.parent) {
var port = app.get('port');
app.listen(port);
console.log('listening on port ' + port);
}
Running "clean:build" (clean) task
Cleaning dist...OK
Running "watch:development" (watch) task
Waiting...
Running "coffeelint:app" (coffeelint) task
src/middlewares/validation.coffee
✖ line 58 Line contains a trailing semicolon
✖ 1 error
Warning: Task "coffeelint:app" failed. Use --force to continue.
Aborted due to warnings.
It doesn't matter what I do, trying any of the API calls returns 404 and even calling the api directly from the browser returns 404. I even tried your example on github and it return 404 as well... any ideas?
For example, /{userId}{mediaTypeExtension}
can't be used. The route generated is invalid.
Because of the way route generation is happening, you can't define a route like /{param}test
.
It appears the validation service is privately held by the Osprey object. If it is made public then service call implementer won't need to re-implement validation.
I need to define authenticated apis using passport authentication method and a custom object that handle permissions.
If I define this api example against express app
, it work as well. But with the object that osprey.create
returns, it always gives me 404
:
var api = osprey.create('/api', app, {
ramlFile: path.join(__dirname, '../raml_spec/api_spec.raml'),
logLevel: app.get('env') !== 'test' ? 'debug' : 'off'
});
api.describe(function (api) {
api.put(
'/templates/:id',
accountController.ensureAuthenticated,
permissions.can('edit'),
templatesController.edit);
})
.then(function() {
app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
})
Thanks!
When a validation error is thrown, no information is provided. It'd be useful if the property, value, validation, etc. was passed with the error message.
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.