raml-org / raml-typesystem Goto Github PK
View Code? Open in Web Editor NEW(deprecated) Typescript implementation of RAML type system
License: Other
(deprecated) Typescript implementation of RAML type system
License: Other
When type has not example no error are thrown.
But, when example is added type become unvalid.
If fileTypes
is not used, then all is OK again.
const ts = require("raml-typesystem")
const rawType = {
type: 'object',
properties: {
type: {
type: 'string',
description: 'MIME-type of image'
},
data: {
type: 'file',
fileTypes: [
'plain/text'
],
maxLength: 307200,
description: 'Image in Base64'
}
}
};
const typeWithoutError = ts.loadType(rawType)
const isValid_true = typeWithoutError.validateType();
console.log(isValid_true); // there is no error
rawType.example = {
type: 'plain/text',
data: 'dGVzdA=='
};
const typeWithError = ts.loadType(rawType)
const isValid_false = typeWithError.validateType();
console.log(isValid_false); // error FILE_TYPES_SHOULD_BE_AN_ARRAY
const rawTypeWithoutFileTypes = {
type: 'object',
properties: {
type: {
type: 'string',
description: 'MIME-type of image'
},
data: {
type: 'file',
maxLength: 307200,
description: 'Image in Base64'
}
},
example: {
type: 'plain/text',
data: 'dGVzdA=='
}
};
const typeWithoutFileTypes = ts.loadType(rawTypeWithoutFileTypes);
const isValid_withoutFileTypes = typeWithoutFileTypes.validateType();
console.log(isValid_withoutFileTypes); // there is no error
File to reproduce: /src/raml1/test/data/TCK/RAML10/Overlays 001/apigateway-aws-overlay.raml (inside of raml parser repo)
(See overlay example with aws-lib)
Test: commonLibrary/api.raml
One of the errors: Error:should be object data/commonLibrary/common.raml
Consider RAML
#%RAML 1.0
title: Pet shop
version: 1
baseUri: /shop
types:
Pet:
properties:
name: string
Mammal:
type: Pet
Bird:
type: Pet
properties:
wingLength: number
then execute following code for it:
api.types().filter(function(type){
return type.name()=="Pet"
}).forEach(function(type){
console.log("Subtypes of", type.name(), ":");
type.runtimeDefinition().subTypes().forEach(function(st){
console.log(st.nameId());
});
});
The resulting list in the console is empty.
RAML:
#%RAML 1.0
title: A
types:
XX:
type: object
properties:
c: string
y: boolean
example:
c: "A"
y: 3
Error message: "Error:Object freshness warning:unmatched properties:z"
I really prefer the old "Unknown property: XXX".
Both to UI and parser top-level API. For now it looks like it does not.
var ts = require('raml-typesystem').loadType({ type: [ 'string', 'integer' ] })
var result = ts.validate('string')
// result.isOk() is true
result = ts.validate(1)
// but here, result.isOk() is false
It seems like raml-typesystem is capable of resolving json-schema $ref. However an additional step seems to be required in order to make this work. This should either be abstracted (provide a default ContentProvider?) or documented.
Related: raml-org/raml-js-parser-2#481 https://github.com/mulesoft/api-workbench/issues/314
Following sample was ok before introducing null
type, but it seems that now it should flag a error because it is actually impossible to create a valid instance of a Person type
#%RAML 1.0
title: API with Types
types:
Person:
type: object
properties:
firstname:
type: string
description: test
lastname: string
addresses: string[]
age: number
manager:
type: Person
Regards,
Pavel
RAML:
#%RAML 1.0
title: WebOfMe
mediaType: application/json
types:
MM:
type: object
properties:
a: number
items: VV[]
VV:
type: object
properties:
c: number
b?:
c1?:
annotationTypes:
qq:
properties:
z: MM
/test:
get:
responses:
200:
body:
schema: MM
example:
a: 3
items:
-
c: 3
-
b: 4
c1: 3
Result error message:
Error:value of declareProperty items: object should have declared property: c
The whole prefix should be either removed or made more meaningful.
Test to fix: parser/examples/ex6.raml
I'd like to use raml-org/typesystem-ts
for validation of both RAML 0.8 types (previously "named parameters") and RAML 1.0 data types.
I've run some tests and it works fine but maybe I'm overlooking something. Is it same to use it for RAML 0.8 type-validation?
@petrochenko-pavel-a, I have fixed the issue itself:
b6c6e3f
Please, check if my fix makes any of your typesystem tests fail.
I've noticed some strange things about JSON schema validation you've added in 0.0.90
:
Draft4Validator
, you don't actually use it. In fact, you only validate Draft 3 schemas and only its required
property format.$schema
property are assumed to be Draft 3 schemas, which doesn't look like a correct behaviour.Related to raml-org/raml-js-parser-2#862
For feed-example.json I am getting reported missing properties one by one as soon as I make one optional, the next one is reported missing.
It looks like:
Note: newts version of Instagram 1.0 is required, the old version does not have that sample mapped to a type.
We need a handy way to determine for ITypeDefinition
instance if it's object or particular subtipe.
Solution is to create a ITypeDefinition.kind()
method retuning one of the following strings:
RAML:
#%RAML 1.0
title: Products
types:
a: b
b: a[]
Result: Error:recurrent array type definition
reported 3 times.
Whats wrong with it:
Test: parser/typexpressions/tr.raml
types:
Foo:
type: object
additionalProperties: false
properties:
foo: string
For example I have Foo as a runtimeType, but cant seem to get the value of additionalProperties.
type.facets() -> []
type.allFacets() -> []
type.allFixedFacets() -> {}
Any suggestions?
RAML:
#%RAML 1.0
title: test
types:
- TypeBase:
type: object
properties:
id:
type: integer
enum: [txt]
Current error message: all enum values should be valid instances of declaring type
Old error message: Integer is expected
Old error message is better.
It would be nice if the error object (i.e. Status) returned:
error.source.name
, sometimes it's error.vp.name
[1]type
, required
, pattern
, minLength
, etcstring
, true
, [a-z]+
, 1
, etc[1] if the property is not available (i.e. single type), maybe it could be the name of the variable that was assigned to the type, e.g. personType
in the 1st example
parser/externalTypes/eType05.raml
It is not JSON schema
message is duplicated.
It would be nice to also include something coming from JSON schema parser.
It already has allFacets
which collects facets all over the hierarchy. We need a method returning only facets defined by the type itself.
phone: +7-913-111-1111
in this example phone has two facets: minLength and type: string, both reporting violation issue.
Q: should this string be actually parsed as number, and if it should then minLength
facet should not report violation.
Unhandled rejection Error: Cannot find module 'raml-xml-validation'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Object. (/root/app/node_modules/raml-typesystem/src/schemaUtil.ts:3:1)
exampleFromNominal
does not work with https://github.com/ddenisenko/raml-js-parser-2/blob/master/src/raml1/test/data/TCK/RAML10/Traits/Trait%20001/api.raml
See also TCK test "Trait 001" in https://github.com/ddenisenko/raml-js-parser-2/blob/master/src/raml1/test/TCK.ts
This is not something urgent but current template of "object should have declared property: XXX" is something looking worse than the old one of "Required property: XXX is missed".
Type system does not follows to strict:false
option when validating examples
queryParameters:
sort?:
type: string[]
description: |
The sort order in the format `property,property[,asc|desc]`. The default sort direction is ascending.
Can be used multiple times for different properties.
example:
strict: false
value: ?sort=givenName&sort=surname,asc
In the following sample annotation does not passes validation against of its union type options:
Sample: /src/raml1/test/data/TCK/RAML10/Overlays 001/apigateway-aws-overlay.raml
so the result is validating against first union type option and it causes confusing error messages
Currently following RAML
#%RAML 1.0
title: test
annotationTypes:
xz:
allowedTargets: Method
/g:
get:
body:
application/json:
(xz): z
passes validation. This happens because type system did not looks in possible annotation targets while it validates types.
examples:
- content:
As per RAML 0.8, it's possible for property names for headers to have placeholders (Name-{*}
):
#%RAML 0.8
title: ZEncoder API
version: v2
baseUri: https://app.zencoder.com/api/{version}
/jobs:
post:
description: Create a Job
headers:
Zencoder-Api-Key:
displayName: ZEncoder API Key
x-Zencoder-job-metadata-{*}
It'd be helpful if project supported it via feature flag or by default so we don't build extra solution on top of it. Consider it as some kind of backward-compatibility.
given the type:
date: {
type: 'datetime'
}
and the value:
date: 'Sun, 28 Feb 2016 16:41:41 GMT'
error.getSource().facetName()
returns should be datetime-only
. I would expect it to return should be datetime
same thing goes with:
date: {
type: 'datetime',
format: 'rfc2616'
}
and the value:
date: '2016-02-28T16:41:41.090Z'
The validation function needs to be able to return an array of all errors, including vital information such as the path to where the validation failed, the type of the validation failure and the message. For comparison, current JSON schema validation gives enough error information to fulfill all fields in https://github.com/mulesoft-labs/node-request-error-handler#creating-errors.
Sample:
#%RAML 1.0
mediaType: application/json
title: x
types:
Person:
type: object
properties:
name: string
lastName: string
example:
description: 31
value:
name: "2"
lastName: "4"
the same applies to examples. however annotations are validated in context of examples.
Regards,
Pavel
types:
Person:
properties:
friends: string[]
example:
friends: []
This is a list of error messages that needs to be improved:
Required property: <property name> is missed
-> missing required property '<property name>'
Can not parse JSON example:Unexpected token d
-> can not parse JSON example: Unexpected token d
(white space between example:
and Unexpected
Unknown property:z
-> Unknown property: 'z'
value should be one of:aaa,bbb,3
-> value should be one of: 'aaa', 'bbb', '3'
array should have not less then 5 items
-> array should not have less than 5 items
object should have not less then 2 properties
-> object should not have less than 2 properties
(especially here we should check if its 1 that ends with property, or more that ends with properties)... should be not less then ...
-> ... should not be less than ...
; also more then
-> more than
In general, I can see a lot of error messages that have missing spaces between colon :
and the actual error message like here. Lets add some spaces. Also every node name should be enclosed in '<property name>'
so that you can distinguish between the message and the name. Sometimes that is a bit hard. Same for values.
RAML:
#%RAML 1.0
title: WebOfMe
mediaType: application/json
types:
MM:
properties:
a: number
example:
a: 5
/hello:
get:
responses:
200:
body:
properties:
x: number
example: |
{ d":5 ,"r":2 }
Result error: "Error:should be object" reported at body node.
What's wrong with it:
That's because it's the only place of "get" prefix being used in ITypeDefinition method names.
Currently it's version 2.0.0-alpha1.3
because it's the last version which doesn't add breaking changes.
First release to add breaking changes is 2.0.0
: https://github.com/vtrushin/json-to-ast/releases/tag/v2.0.0
To see the difference in generates json-ast:
2.0.0-alpha1.3
and options {verbose: true}
.2.1.0
or 2.0.0
and options {loc: true}
.Currently upgrading to 2.1.0
makes 95 tests in raml-js-parser-2
fail when running them travis-like:
npm run devInstall
npm run buildall && npm run testall
The method must return facets fixed by the type and all of it supertypes.
Hi, I am parsing raml with raml-js-parser-2 load in 1.1.31 version:
#%RAML 1.0 AnnotationTypeDeclaration
displayName: My annotation
description: This is an annotation.
type: array
allowedTargets: TypeDeclaration
items:
properties:
name:
type: wrooong
I expect to receive an error similar to: 'Wrong type name: wrooong'
But it shows only 'Component type has error: ' with no message.
Here is the result of the parser:
{
"specification": {
"displayName": "My annotation",
"type": [
"array"
],
"required": true,
"description": "This is an annotation.",
"allowedTargets": [
"TypeDeclaration"
],
"items": [
{
"name": "items",
"displayName": "items",
"type": [
"object"
],
"properties": {
"name": {
"name": "name",
"displayName": "name",
"type": [
"wrooong"
],
"required": true,
"__METADATA__": {
"primitiveValuesMeta": {
"displayName": {
"calculated": true
},
"required": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
}
},
"__METADATA__": {
"primitiveValuesMeta": {
"displayName": {
"calculated": true
},
"type": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
}
],
"__METADATA__": {
"primitiveValuesMeta": {
"required": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
},
"ramlVersion": "RAML10",
"type": "ArrayTypeDeclaration",
"errors": [
{
"code": "INVALID_COMPONENT_TYPE",
"message": "Component type has error: ",
"path": "annotation.raml",
"range": {
"start": {
"line": 2,
"column": 0,
"position": 38
},
"end": {
"line": 10,
"column": 0,
"position": 196
}
}
}
]
}
I have seen in class restrictions.ts these lines:
if (!typeStatus.isOk()) {
st.addSubStatus(ts.error(messageRegistry.INVALID_COMPONENT_TYPE,
this,{msg: st.getMessage()}));
}
if I replace st.getMessage() with typeStatus.getMessage() it shows the correct error:
{
"specification": {
"displayName": "My annotation",
"type": [
"array"
],
"required": true,
"description": "This is an annotation.",
"allowedTargets": [
"TypeDeclaration"
],
"items": [
{
"name": "items",
"displayName": "items",
"type": [
"object"
],
"properties": {
"name": {
"name": "name",
"displayName": "name",
"type": [
"wrooong"
],
"required": true,
"__METADATA__": {
"primitiveValuesMeta": {
"displayName": {
"calculated": true
},
"required": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
}
},
"__METADATA__": {
"primitiveValuesMeta": {
"displayName": {
"calculated": true
},
"type": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
}
],
"__METADATA__": {
"primitiveValuesMeta": {
"required": {
"insertedAsDefault": true
}
}
},
"mediaType": "application/raml+yaml",
"typePropertyKind": "TYPE_EXPRESSION"
},
"ramlVersion": "RAML10",
"type": "ArrayTypeDeclaration",
"errors": [
{
"code": "INVALID_COMPONENT_TYPE",
"message": "Component type has error: Property 'name' refers to unknown type 'wrooong'",
"path": "annotation.raml",
"range": {
"start": {
"line": 2,
"column": 0,
"position": 38
},
"end": {
"line": 10,
"column": 0,
"position": 196
}
}
}
]
}
This happens to me in any array with items declared in annotations, types or any raml
Thanks
RAML:
#%RAML 1.0
title: WebOfMe
mediaType: application/json
types:
MM:
type: object
properties:
a: number
items: VV[]
examples:
f1:
content:
a: 3
items:
- c: 4
r1: 3
- r2: 3
VV:
type: object
properties:
r2?:
c: number
r1?:
annotationTypes:
qq:
properties:
z: MM
Here we have the following error reported:
Error:value of declareProperty items: value of declareProperty r1: should be string
The issue is that there are 2 more errors in this example: r2 being also a string and c missing in a second item, which are -also- being reported, but only when previous errors are fixed.
We should be reporting all these errors at once.
We already have methods which allow to detect whether the type is an array, union, annotation type, value type or external type.
Purpose of isObject
method is to answer the question whether the type is an object type.
I try to use raml-typesytem
to validate JSON with RAML types in browser app.
But for successful execute, settings of webpack
(I use it for build with @angular/cli
) should be modified to load .json
files without extensions.
Probably, require could be changed to ../../resources/errorMessages.json
to be compatible with browser applications without additional settings.
Proposal: Externals should be allowed in a union if they are not extended or mixed with internals.
#%RAML 1.0
---
types:
A:
type: !include A.schema.json
B:
type: !include B.schema.json
title: externals with union
baseUri: https://example.com
/resource:
post:
body:
application/json:
type: A | B
The above currently receives the following error message:
EXTERNALS_MIX: It is not allowed to mix RAML types with externals
If I alter the above example to use RAML types instead of JSON Schemas, the union works as expected; however, I lose the benefits of extracting and using JSON schemas.
It's also important to note that I'm using raml2html to validate my RAML document.
Would the community be open to allowing this behavior?
RAML:
#%RAML 1.0
title: WebOfMe
mediaType: application/json
types:
MM:
properties:
a: number
/hello:
get:
responses:
200:
body:
schema: |
{
"required": "message",
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"message": {
"required": true,
"type": "string"
}
},
"additionalProperties": false
}
example: |
{ "message":"s" ,"r":2 }
Result:
Error:Example does not conform to schema:Content is not valid according to schema:Expected type object but found type string object,string
What's wrong with it:
Test to change after the issue is fixed: ParserTests , parser/examples/ex2.raml
This is not something urgent but current template of "Error:should be string" is something looking worse than the old one of "String is expected".
Now we have
MyType: StructuredType
object: StructuredType
AnyType: ValueType
ValueType: ValueType
MyType: Array
"": Array
ArrayTypeDeclaration: NodeClass
TypeDeclaration: NodeClass
RAMLLanguageElement: NodeClass
AnyType: ValueType
ValueType: ValueType
MyType: Union
"": Union
Need
MyType: StructuredType
object: StructuredType
any: AnyType
MyType: Array
array: Array
any: AnyType
MyType: Union
union: Union
any: AnyType
2.6.3
to 2.7.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
rimraf is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Source: https://github.com/mulesoft-labs/api-workbench/issues/2503
Example raml:
#%RAML 1.0
title: Example of request bodies
mediaType: application/json
types:
Person: object
q: number
Man:
type: [ "Person | number" ]
C:
type: [ "number | string", Person ]
D:
type: [ q, Person]
E:
type: [ number , Person ]
Problem: API workbench error message is not informative.
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.