Code Monkey home page Code Monkey logo

raml-typesystem's Introduction

RAML.org Website

This repository contains the source code for the raml.org website written in Jekyll

Requirements

Running locally

Pull the code locally:

$ git clone [email protected]:raml-org/raml-org.git

Enter directory:

$ cd raml-org

Install all dependencies:

$ bundle install

Build & run the site:

$ bundle exec jekyll serve

How to add projects to the projects page?

RAML.org includes a projects page that lists tools around RAML that either are community or commercial driven. If you think, your project should be in this list, please fork this repository, add it into the projects.yml file, and send us a PR. We will review and let you know if we will be able to list it.

Another way to make sure your project is linked to our projects page is through assigning topics to your Github project. Links to each topics are below the list of projects on the projects page. The following topics are available:

Topic Description
raml-design Includes projects that specifically support people with the design of RAML documents.
raml-document Includes projects that focus on the documentation of APIs using RAML documents.
raml-build Includes projects that focus on build client or server code based on RAML documents.
raml-parser Includes projects that parses/validates RAML documents.
raml-test Includes projects that support people testing APIs based on RAML documents.
raml-utilities Includes other projects that do not fall into the other topics like converters.

Topics need to be assigned and managed by the owner of a project. Additionally, we still recommend people to search on Github for more projects that might not have these topics assigned.

Contribution

RAML's website is in fact an open source project and your contribution is very much appreciated. Before you start, you should check for open issues or open a fresh issue to start a discussion around an idea that you'd like to see on our website or a bug. If you want to support us fixing issues, please follow the steps below:

  1. Fork the repository on Github and make your changes on the develop branch (or branch off of it).
  2. Run the website to see if you fixed the issue.
  3. Send a pull request (with the develop branch as the target).

We will review your PR, comment if necessary, and merge it into our staging branch stg.

You can contribute to the following:

  • spelling mistakes
  • new projects
  • blog posts
  • and others, after carefully reviewing the issue you created

raml-typesystem's People

Contributors

ddenisenko avatar dependabot[bot] avatar dreamflyer avatar greenkeeper[bot] avatar ivangoncharov avatar jstoiko avatar konstantinsviridov avatar petrochenko-pavel-a avatar postatum avatar sichvoge avatar svc-scm avatar vasiliylysokobylko avatar

Stargazers

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

Watchers

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

raml-typesystem's Issues

exampleFromNominal failure

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

Very strange JSON schema validation

I've noticed some strange things about JSON schema validation you've added in 0.0.90:

  • Though you've implemented Draft4Validator, you don't actually use it. In fact, you only validate Draft 3 schemas and only its required property format.
  • All schemas without $schema property are assumed to be Draft 3 schemas, which doesn't look like a correct behaviour.
  • Validation explicitly check for Draft 4 schemas, so anything else is assumed to be in Draft 3.

Related to raml-org/raml-js-parser-2#862

Extra properties of examples facet are not validated properly

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

Wrong type error message

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".

Error message text and position for JSON sample validation 2

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:

  1. Wrong error target node
  2. Error prefix "Error:Example does not conform to schema:Content is not valid according to schema:" should not contain "Error" word and should not repeat about schema twice.
  3. The meaningful part "Expected type object but found type string object,string" looks strange. We've got more meaningful error mentioning additionalProperties earlier. What has changed?

Test to change after the issue is fixed: ParserTests , parser/examples/ex2.raml

Upgrade json-to-ast to a stable release

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:

  1. Generate json-ast with version 2.0.0-alpha1.3 and options {verbose: true}.
  2. Generate json-ast with version 2.1.0 or 2.0.0 and options {loc: true}.
  3. Compare.

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

Annotation targets should be taken in account by type system

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.

ITypeDefinition.subTypes() always returns empty list

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.

Weird error message for missing property in array

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

Improve error messages for 'example' validation

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)
  • in general: ... 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.

Unknown property error message

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".

`datetime` validation errors return wrong type name

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'

RAML 0.8 types (named parameters) support?

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?

An in-range update of rimraf is breaking the build 🚨

The devDependency rimraf was updated from 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.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 2 commits.

  • 250ee15 2.7.0
  • dc1682d feat: make it possible to omit glob dependency

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ITypeDefinition get additionalProperties value

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?

We need an ITypeDefinition.kind() method

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:

  • array
  • annotation
  • external
  • object
  • union
  • value

Instagram 1.0 array of union

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:

  1. The type is not actually matching
  2. It wants to report -all- required properties, but all errors but one are hidden.

Note: newts version of Instagram 1.0 is required, the old version does not have that sample mapped to a type.

User types hierarchy inconsistency

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

Can't resolve '../../resources/errorMessages'

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.

Wrong number of recurrent validation messages

RAML:

#%RAML 1.0
title: Products
types:
  a: b
  b: a[]

Result: Error:recurrent array type definition reported 3 times.
Whats wrong with it:

  1. it should be reported 2 times: for a and for b
  2. Not quite sure we should treat -both- as array types here.

Test: parser/typexpressions/tr.raml

Allowing externals in unions

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?

Error message text and position for JSON sample validation

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:

  1. The error target node should be at least example itself.
  2. Error message itself should mention that this is JSON validation error.

properties with in-line types does not validate

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

Missed property error message

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".

Optional dependency raml-xml-validation causes errors

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)

Add useful properties to error object

It would be nice if the error object (i.e. Status) returned:

  • the property on which the error occurred. currently it is not consistent, sometimes it's error.source.name, sometimes it's error.vp.name [1]
  • the constrain key that triggered the error. e.g. type, required, pattern, minLength, etc
  • the constrain value, e.g. string, 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

Consider being compliant with RAML 0.8 property name placeholders ({*})

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.

Errors inside 'items' show invalid message 'Component type has error: '

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

Recurrent type passes validation

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

FILE_TYPES_SHOULD_BE_AN_ARRAY, thrown for type with example

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

Several errors in a sample at once

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 need ITypeDefinition.isObject method

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.

Validation message in case of no union type options passes validation

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

Type system does not follows to `strict:false` option when validating examples

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

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.