mulesoft-labs / osprey-method-handler Goto Github PK
View Code? Open in Web Editor NEWMiddleware for validating requests and responses based on a RAML method object
License: Other
Middleware for validating requests and responses based on a RAML method object
License: Other
The current errors only provide an error message and status code. It needs to provide the array of errors that occurred and all other information in a standardised format for error output on the server.
Currently breaks when passing charsets with the media type.
RAML 1.0 and AML-AMF WebApi allow query string parameters to be defined as either queryParameters xor queryString.
RAML 1.0 defines queryParameters as a properties declaration list and queryString as a type or type expression.
https://nicedoc.io/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#query-strings-and-query-parameters
AML AMF WebApi models a request with properties queryParameters: Parameter[]
and queryString: Shape
.
https://github.com/aml-org/amf/blob/develop/documentation/model.md#request
webapi-parser.Operation.Request
has properties queryParameters: Parameter[]
and queryString: Shape
.
https://github.com/raml-org/webapi-parser/blob/494156d904f813cc5edfa6215b0a265e7589d9c5/js/module/typings/amf-client-js.d.ts#L1333-L1343
ospreyMethodHandler
does not handle method.request.queryString
.
This can cause all query string parameters to be discarded if the original RAML used the queryString node.
osprey-method-handler/osprey-method-handler.js
Lines 116 to 129 in c938df2
6.11.0
to 6.12.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ajv is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
Improved hostname validation (@sambauers, #1143)
Option keywords
to add custom keywords (@franciscomorais, #1137)
Types fixes (@boenrobot, @MattiAstedrone)
Docs:
The new version differs by 33 commits.
03d0012
6.12.0
1021a00
Merge branch 'RadiationSickness-patch-1'
0163e5c
docs: error logging code sample
52adde5
Merge branch 'patch-1' of git://github.com/RadiationSickness/ajv into RadiationSickness-patch-1
8fd1e44
Merge branch 'franciscomorais-feature/keywords-options'
e5bed30
test: update option keywords test
c90c189
Merge branch 'feature/keywords-options' of git://github.com/franciscomorais/ajv into franciscomorais-feature/keywords-options
38191c2
Update readme with keywords option
f94db48
Update options validation spec
367527c
Merge branch 'master' into patch-1
c1c0ba7
Merge pull request #1091 from thetric/typescript-usage-note
75aa5fd
Merge pull request #1143 from sambauers/master
120748c
Only use regex for hostname checks.
384eec4
Merge branch 'master' into master
4d9dd8c
docs: link to $data reference proposal, closes #51
There are 33 commits in total.
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Validate responses match the RAML schemas for methods.
Some things don't need to be logged out as publicly, such as "parameters missing", but others like choosing to discard the body should be logged loudly when debugging.
Hello,
I'm facing an issue with osprey-mock-service and I tracked it down to this library.
When I'm loading a a RAML (0.8) with only an example in the body property:
put:
is: [userSecured]
description: |
Update member's contact information
body:
application/json:
example: !include ../examples-fixtures/request/200-put-account-contact-information.json
I'm having an error: TypeError: Cannot read property 'constructor' of undefined at jsonBodyHandler osprey-method-handler.js:347:26
And this seems legit regarding this so called line:
var schema = body && (body.properties || body.type || body.schema) || undefined
var isRAMLType = schema.constructor === {}.constructor
Ive looked back at the RAML 1.0 spec and type OR schema seems to be mandatory but it's not in 0.8.
Is this parser only compatible with RAML 1.0 and I'm missing a conf in the parent lib in order to use a 0.8 compatible parser or is this an error in this parser ?
Thanks !
Branch | Build failing π¨ |
---|---|
Dependency | debug |
Current Version | 3.1.0 |
Type | dependency |
This version is covered by your current version range and after updating it in your project the build failed.
debug is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
A long-awaited release to debug
is available now: 3.2.0
.
chrome.storage
(or make the storage backend pluggable): 71d2aa7supports-color@5
: 285dfe1enable()
(#517): ab5083fHuge thanks to @DanielRuf, @EirikBirkeland, @KyleStay, @Qix-, @abenhamdine, @alexey-pelykh, @DiegoRBaquero, @febbraro, @kwolfy, and @TooTallNate for their help!
The new version differs by 25 commits.
dec4b15
3.2.0
3ca2331
clean up builds
9f4f8f5
remove needless command aliases in makefile
623c08e
no longer checking for BROWSER=1
57cde56
fix tests
62822f1
clean up makefile
833b6f8
fix tests
ba8a424
move to XO (closes #397)
2d2509e
add .editorconfig
853853f
bump vulnerable packages
7e1d5d9
add yarn-error.log to .gitignore
e43e5fe
add instance extends feature (#524)
207a6a2
Fix nwjs support (#569)
05b0ceb
add Node.js 10, remove Node.js 4 (#583)
02b9ea9
Add TVMLKit support (#579)
There are 25 commits in total.
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
E.g.
#%RAML 1.0
title: My api
baseUri: http://localhost:3000
types:
Foo: !include schemas/foo.json
/foo:
post:
body:
application/json:
type: Foo
Either replacing foo.json
by an equivalent RAML datatype foo.raml
or replacing type: Foo
by schema: !include schemas/foo.json
works.
--
originally submitted here: mulesoft/osprey#151
I have a raml file for a JSON REST API :
RAML example
If I read the documentation , it is OPTIONAL ... so any idea ?
Currently we only use the path.
While updating dependencies I ran into an issue going from version 0.4.1 --> 0.5.0.
It looks like in the latest version in the acceptHandler it requires that responses contain a body. Where as previous versions did not require a body, is this an intended change?
Object.keys(responses || {})
.filter(function (code) {
return code >= 200 && code < 300
})
.forEach(function (code) {
var response = responses[code]
var body = response ? response.body : {}
Object.keys(body).forEach(function (type) {
accepts[type] = true
})
})
Root Cause
This line in particular is assuming if there is a response that there is a body nested within that response, and if there is not a body in the response, the body variable is set to null or undefined
var body = response ? response.body : {}
and then the body gets here and then fails
Object.keys(body).forEach(function (type) {
Problem
/Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey-method-handler/osprey-method-handler.js:167
Object.keys(body).forEach(function (type) {
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at /Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey-method-handler/osprey-method-handler.js:167:14
at Array.forEach (<anonymous>)
at acceptsHandler (/Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey-method-handler/osprey-method-handler.js:163:6)
at ospreyMethodHandler (/Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey-method-handler/osprey-method-handler.js:127:21)
at /Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey/lib/server.js:30:12
at /Users/jlofton/Desktop/goBalto/bloodhound/node_modules/osprey-resources/osprey-resources.js:58:20
at Array.forEach (<anonymous>)
Suggested Fix
The previous version of this line works
var body = response && response.body || {}
Again not sure if this is an intended change or not, thanks!
Currently, cloning this repository, running npm install && npm test
produces errors. Looks like they are related to node-raml-validate
changing the default RAML-version to 0.8 in mulesoft-labs/node-raml-validate@b9ce7cf. Manually passing { RAMLVersion: 'RAML10' }
to the validate
calls in the failing test cases makes the tests go green again. (PR pending)
ajv
currently fails validating draft-06 JSONSchema, but can be extended to support this by bumping to 5.0.0
Backwards compatibility with draft-04 can be maintained as well; see https://github.com/epoberezkin/ajv#using-version-5
Currently ajv
throws a warning (and will throw an error from ajv@5
) for unknown formats, such as etag
, long
, etc. They can be silenced using unknownFormats
flag.
UnsupportedMediaTypeError: No body sent with request for PUT /api/something with content-type "undefined"
Seems that there is no way to handle such error ?
err object appears to be empty for this case.
Please advise
Thanks
When I started the server :
When I tried a request , with the content of validation, if it could help
Here is all my raml files :
Api.raml
title: My api
baseUri: htttp://admin.secret.eu/{version}
version: v1
mediaType: application/json
uses:
Answers: libraries/answers.raml
Requests: libraries/requests.raml
/webhook:
/registeredUser:
post:
description: Register a new call log for a registered user
headers:
Content-Type:
enum: ["application/json"]
required: true
body:
application/json:
type: Requests.RegisteredUserCallRequest
responses:
200:
body:
application/json:
type: Answers.APIAnswer
400:
body:
application/json:
type: Answers.APIAnswer
requests.raml
#%RAML 1.0 Library
types:
RegisteredUserCallRequest:
properties:
phoneNumberUsed:
type: string
description: The phone number used to call us
example: "+55151151515"
maxLength: 20
required: true
dateTime:
type: datetime
description: A datetime with timezone
example: 2016-02-28T16:41:41.090Z
format: rfc3339 # the default, so no need to specify
required: true
userId:
required: true
type: integer
description: The customer Id from another Bepark database
example: 12357
userName:
type: string
description: The name and first name of the caller
example: temporary account (partner)
required: true
maxLength: 100
IvrNumber:
description: Interactive voice response number
type: number
example: 444521414545
required: false
IvrRef:
description: Interactive voice response reference
type: string
example: "44645486546546845486"
required: false
maxLength: 25
answers.raml
#%RAML 1.0 Library
types:
APIAnswer:
properties:
message: string
status: integer
PS: Sorry for the red color for date : Linguist doesn't seem to like RAML 1.0 : https://help.github.com/articles/creating-and-highlighting-code-blocks/
In cases where the schema field of a request body declaration for application/json
type refers to a named schema declared in the root section of the RAML content as in the following example, I have observed that an unexpected error is thrown when creating the ospreyMethodHandler
for the associated RAML.
Example RAML snippet
schemas:
- newBooking: !include schemas/createEventBooking.json
/createEventBooking:
post:
body:
application/json:
schema: newBooking
Problem
This results in the following unexpected error when attempting to create the associated ospreyMethodHandler.
Error: Unable to compile JSON schema for post /pps/v3/core/createEventBooking: Unexpected token e in JSON at position 1
Root Cause
Here is the offending code I found in the jsonBodyHandler()
function that causes this error.
var schema = body && (body.properties || body.type) || undefined
var isRAMLType = schema ? schema.constructor === {}.constructor : false
// This is most likely a JSON schema
if (!schema) {
schema = body.schema
The body.schema
in the example RAML shown above is "newBooking"
while the actual JSON schema content is in body.schemaContent
. The value "newBooking"
assigned to the schema
variable is then passed as input to jsonBodyValidationHandler()
which then attempts to perform JSON.parse()
on this value resulting in the observed error. In cases where the schema
field in the RAML definition of a request/response body for a given media type is an inline JSON schema or refers to an external schema via an include statement, the logic above works fine because the schema content in these cases is populated in both body.schema
and body.schemaContent
by the raml-1-parser
that is being used to parse the RAML.
Suggested Fix
Change the assignment statement from schema = body.schema
to schema = body.schemaContent || body.schema
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.