Git Product home page Git Product logo

dredd-transactions's Introduction

Dredd Transactions

npm version Build Status Build status Known Vulnerabilities

Dredd Transactions library compiles HTTP Transactions (simple Request-Response pairs) from API description document.

Note: To better understand emphasized terms in this documentation, please refer to the Glossary of Terms. All data structures are described using the MSON format.

This project supersedes Blueprint Transactions library.

Features

  • Inherits parameters from parent Resource and Action sections.
  • Expands URI Templates.
  • Warns on undefined placeholders in URI Templates (both query and path).
  • Validates URI parameter types.
  • Selects first Request and first Response if multiple are specified in the API description document.

Deprecated Features

Note: These features are to be superseded by whatever comes out of the proposal in apiaryio/dredd#227.

Installation

npm install dredd-transactions

Development

Dredd Transactions library is written in JavaScript (ES2015+).

Usage

parse

Parses given API description document into API Elements with options specific to Dredd. Assumes that documents with unrecognizable format are API Blueprint. Turns any parser failures, including the unexpected ones, into API Elements annotations.

const parse = require('dredd-transactions/parse');
// const { parse } = require('dredd-transactions');

parse('# My API\n...', (error, parseResult) => {
  // ...
});

compile

Compiles HTTP Transactions from given API Elements. HTTP Transactions are a backbone data structure to Dredd.

const compile = require('dredd-transactions/compile');
// const { compile } = require('dredd-transactions');

const compileResult = compile(mediaType, apiElements, filename);

Note: The filename argument is optional and about to get deprecated, see #6

Data Structures

Parse Result (object)

Result of parsing.

  • mediaType: text/vnd.apiblueprint (string, default, nullable) - Media type of the input format, can be empty in case of some fatal errors
  • apiElements (API Elements) - API Elements parse result

Compile Result (object)

Result of compilation. Alongside compiled Transaction objects contains also errors and warnings, mainly from API description parser.

  • mediaType: text/vnd.apiblueprint (string, default, nullable) - Media type of the input format, defaults to API Blueprint format. Can be empty in case of some fatal errors.
  • transactions (array[Transaction]) - Compiled HTTP Transactions.
  • annotations (array[Annotation]) - Errors and warnings which occurred during parsing of the API description or during compilation of transactions.

Transaction (object)

Represents a single HTTP Transaction (Request-Response pair) and its location in the API description document. The location is provided in two forms, both deprecated as of now:

  • name - String representation, both human- and machine-readable.
  • origin - Object of references to nodes of API Elements derived from the original API description document.

Note: These two forms of locating HTTP Transactions are to be superseded by whatever comes out of the proposal in apiaryio/dredd#227.

Properties

  • request (object) - HTTP Request as described in API description document.
    • method
    • uri: /message (string) - Informative URI of the Request.
    • headers (array) - List of HTTP headers in their original order, with the original casing of the header name, including multiple headers of the same name.
      • (object)
        • name: Content-Type (string)
        • value: text/plain (string)
    • body: Hello world!\n (string)
  • response (object) - Expected HTTP Response as described in API description document.
    • status: 200 (string)
    • headers (array) - List of HTTP headers in their original order, with the original casing of the header name, including multiple headers of the same name.
      • (object)
        • name: Content-Type (string)
        • value: text/plain (string)
    • body (string, optional)
    • schema (string, optional)

Deprecated Properties

  • name: Hello world! > Retrieve Message (string) - Transaction Name, non-deterministic breadcrumb location of the HTTP Transaction within the API description document.
  • origin (object) - Object of references to nodes of API Elements derived from the original API description document.
    • filename: ./api-description.apib (string)
    • apiName: My Api (string)
    • resourceGroupName: Greetings (string)
    • resourceName: Hello, world! (string)
    • actionName: Retrieve Message (string)
    • exampleName: First example (string)

Note: These properties are to be superseded by whatever comes out of the proposal in apiaryio/dredd#227.

Annotation (object)

Description of an error or warning which occurred during parsing of the API description or during compilation of transactions.

Properties

  • type (enum[string])
    • error
    • warning
  • component (enum[string]) - In which component of the compilation process the annotation occurred
    • apiDescriptionParser
    • parametersValidation
    • uriTemplateExpansion
  • message (string) - Textual annotation. This is – in most cases – a human-readable message to be displayed to user
  • location (array, fixed, nullable) - Location of the annotation in the source file, represented by a single range of line and column number pairs if available, or by null otherwise
    • (array) - Start location
      • (number) - Line number
      • (number) - Column number
    • (array) - End location
      • (number) - Line number
      • (number) - Column number

Deprecated Properties

  • name: Hello world! > Retrieve Message (string) - Transaction Name, non-deterministic breadcrumb location of the relevant HTTP Transaction within the API description document.
  • origin (object) - Object of references to nodes of API Elements derived from the original API description document.
    • filename: ./api-description.apib (string)
    • apiName: My Api (string)
    • resourceGroupName: Greetings (string)
    • resourceName: Hello, world! (string)
    • actionName: Retrieve Message (string)
    • exampleName: First example (string)

Note: These properties are to be superseded by whatever comes out of the proposal in apiaryio/dredd#227.

dredd-transactions's People

Contributors

artem-zakharchenko avatar coord-e avatar dependabot-preview[bot] avatar freaz avatar greenkeeper[bot] avatar honzajavorek avatar jackub avatar kylef avatar miiila avatar motemen avatar pksunkara avatar realityking avatar w-vi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dredd-transactions's Issues

Reformat all "it" blocks in the test suite to be readable

Currently the tests are suffering terrible formatting caused by decaffeination in the past. It should be pretty simple to make the it blocks a bit more readable by adding brackets and newlines.

This should also resolve deprecation warnings which came with the latest Mocha.

fury-adapter-swagger upgrade causes Type Error

The most recent release included an upgrade to fury and minim dependencies. With those changes I get the following error when trying to run dredd.

/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:52
      element.parent = this;
                     ^

TypeError: Cannot assign to read only property 'parent' of object '#<AuthScheme>'
    at constructor.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:52:22)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at constructor.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at constructor.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at constructor.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at constructor.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at constructor.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at HttpTransaction.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:48:23)
    at Transition.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at Transition.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at Resource.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at Resource.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at Category.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at Category.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at ParseResult.<anonymous> (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:53:15)
    at Array.forEach (<anonymous>:null:null)
    at constructor.forEach (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/array-slice.js:58:19)
    at ParseResult.freeze (/usr/local/lib/node_modules/dredd/node_modules/minim/lib/primitives/element.js:51:19)
    at /usr/local/lib/node_modules/dredd/node_modules/dredd-transactions/lib/parse.js:42:19
    at /usr/local/lib/node_modules/dredd/node_modules/fury/lib/fury.js:169:13
    at complete (/usr/local/lib/node_modules/dredd/node_modules/fury-adapter-swagger/lib/parser.js:258:20)
    at /usr/local/lib/node_modules/dredd/node_modules/fury-adapter-swagger/lib/parser.js:280:17
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

To reproduce, simply do a fresh install of dredd as outlined here
http://dredd.readthedocs.io/en/latest/installation.html and run dredd against a swagger.yaml file.

To work around the issue, manually update dredd/packages.json restricting the version.

I believe the commit introducing the issue is ea91dc6

An in-range update of coffee-script is breaking the build 🚨

Version 1.12.8 of coffee-script was just published.

Branch Build failing 🚨
Dependency coffee-script
Current Version 1.12.7
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

coffee-script 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 is in progress Details
  • continuous-integration/appveyor/branch AppVeyor build failed Details

Commits

The new version differs by 11 commits ahead by 11, behind by 7.

  • 943579a 1.12.8 (#4801)
  • 8bb89d8 Backport #4783, fix for export default followed by an implicit object (#4800)
  • f301b04 [CS1] Add postinstall message for direct installs of ‘coffee-script’ (#4759)
  • c5f4314 [CS1] Travis CI for 1.x (#4797)
  • 1ad9c61 Revise v1 docs to reflect that v2 is out; update paths to reflect that the v2 docs are now the primary docs, and the v1 docs only live under /v1/
  • 249cc59 Remove v2 docs
  • e7073bc Update CS2 docs per #4688
  • 458440e 2.0.0-beta5 docs
  • 6cea181 [CS1] fix #4260 and #1349: splat error with soak properties or expressions (#4643)
  • e3c2c03 2.0.0-beta4 docs
  • 27f21a3 1.12.7 (#4617)

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 🌴

Remove Coverage

We have long-term issues with Coveralls and there no replacement we could use. CodeCov is nice, but it integrates with GitHub in a way which doesn't allow not to give it access to private repositories, which is a problem with our company policies.

Since today Coveralls started to fail our builds, I propose removing Coverage altogether from the repository for now and to reintroduce it once we have a viable solution, as I don't believe Coverage is worth our immediate focus in following days.

Distinguish public 'compile' from internal 'compile'

Since #26 the public interface of the library is called the same way as internal compile function used to compile HTTP transactions from API Elements.

We should find two distinct names (due to backward compatibility of the public interface the public compile should stay) and name both parts differently and consistently.

Different detection of default URI parameter value

It seems (not verified properly yet) that following

## Search [/search/{?order}]

### GET

+ Parameters
    + order: `asc` (string, optional) - Order to search

        Description...

        + Default: `desc`

        + Members
            + `desc` - Descendant...
            + `asc` - Ascendant...

will produce

/search/?order=desc

with the new Dredd Transactions, instead of

/search/?order=asc

That's change of behavior. At the same time, it looks like fix of wrong behavior, not regression. Will leave this open for the record until confirmed.

Remove completely processing of API Blueprint AST

Processing of API Blueprint AST is still kept in the codebase for regression testing purposes. Once we're comfortable with the new implementation, we should remove the API Blueprint AST branch of the code completely.

Arrays in parameters don't get their example values extracted correctly

When you have a swagger spec which requires an array in the parameters, this doesn't work.
Check this simple swaggerfile.
If you run dredd against this file none of the two x-example are taken. Instead, the url will look like this:
/hello?aggregates=%5Bobject%20Object%5D

The full dredd log:

info: Configuration './dredd.yml' found, ignoring other arguments.
info: Starting server with command: node index.js
info: Waiting 3 seconds for server command to start...
info: Backend server exited
info: Beginning Dredd testing...
error: GET /hello?aggregates=%5Bobject%20Object%5D duration: 8ms
error: Error connecting to server under test!
info: Displaying failed tests...
fail: GET /hello?aggregates=%5Bobject%20Object%5D duration: 8ms
fail: Error connecting to server under test!
request:
method: GET
uri: /hello?aggregates=%5Bobject%20Object%5D
headers:
User-Agent: Dredd/2.0.0 (Darwin 15.6.0; x64)

body:

expected:
headers:

body:

statusCode: 200
bodySchema: {"type":"string"}

Provide transaction name for compiler annotations

Unline errors and warnings (annotations) coming from the parser, the ones coming from the compiler currently don't provide line/column numbers. Instead, they provide at least the origin of the relevant transaction.

It would be nice to provide line numbers as well - see https://github.com/apiaryio/dredd-transactions/issues/275. Until that's done, we are showing users the transaction name of the relevant transaction in Dredd's logging. However, since the annotations coming from Dredd Transactions don't contain the transaction name, it needs to be reconstructed in Dredd. This is error-prone and unnecessary duplication. We should add name to the interface of compiler annotations Dredd Transactions provide.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


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 🌴

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

Version 4.1.4 of sinon was just published.

Branch Build failing 🚨
Dependency sinon
Current Version 4.1.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

sinon 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/appveyor/branch AppVeyor build succeeded Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes Minor fix for Symbol names and deprecation of spy.reset
  • Fix: assertion error messages did not handle Symbol names (#1640)
  • Deprecate spy.reset(), use spy.resetHistory() instead (#1446)
Commits

The new version differs by 36 commits.

  • 1ea2749 Update docs/changelog.md and set new release id in docs/_config.yml
  • 078c082 Add release documentation for v4.1.4
  • 571263e 4.1.4
  • f2ee9f1 Update History.md and AUTHORS for new release
  • a8262dd Assertion error messages handle symbolic method names
  • 8fa1e14 Merge pull request #1641 from mroderick/point-to-stack-overflow
  • 7c1ebd0 Update issue links to point to sinonjs/sinon
  • 93418f6 Update documentation to emphasize Stack Overflow
  • ca9e2fa Merge pull request #1636 from fearphage/fix-headless-chrome-in-circle
  • 39186f4 use google-chrome-unstable for tests
  • 6315621 invalidate cache
  • d078af9 try using default chrome install
  • 177c4b6 upgraded to the lastest official version of mochify
  • ecdc4e0 test with updated mochify
  • 360c2e7 added more details and notes

There are 36 commits in total.

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 🌴

Merge test folders

We should consider merging the integration and unit folders of tests since most of the inputs for unit tests are now parsed on the fly and the border between integration and unit tests became quite blurred. I suspect some tests to be even duplicates and that we're keeping them just because they live in various folders.

Tests shouldn't use drafter directly

The only blocker now is detect-transaction-examples-test.coffee. To remove drafter with ast option and any dependency on API Blueprint AST, we need to turn the regression check to static fixtures and assert against those fixtures.

Also, there could be a script or at least a tutorial on how to generate the fixtures using old version of drafter which still supports AST, if regressions are found and new fixtures are needed.

Make refract lib part of the minim project

Make refract.coffee a part of the refract-query or minim projects. Requirements:

Ability to add additional information to nodes in the Refract tree

When processing the Refract tree, I find out some information specific to certain elements and I want to save the information back to the tree as attribute or meta value.

Get parent elements (or first parent element) of certain type of given node

Usually I'm interested in certain elements deep in the Refract structure. I can do sth like:

for transition in <find all transitions>
    for transaction in <find all transactions within transition>
        for request in <find all requests within transaction>
            for x in <find all elements x within request>
                <now I can work with element x and with it's parents>

...but that makes my code ugly. What I want to do:

for x in <find all elements x>
    <now I can work with element x>
    transaction = <find first transaction in x's parents>
    <now I can work with element x's parents>

Recognize what is content of given node

Now I have function:

content = (node) ->
  if node?.element then content(node.content) else node

Find recursively any children elements (or first child element) of certain type within given node (although it's in attributes)

I want to find all subelements of type "source map" for given element (e.g. request). Then I want to manually go through found source maps and do some arithmetic on top of their contents.

messageBody = child(httpResponse, {element: 'asset', 'meta.classes': 'messageBody'})

httpResponse = child(httpTransaction, {element: 'httpResponse'})

for httpTransaction in children(parseResult, {element: 'httpTransaction'})
    ...

E.g. refract-query looks for elements only in content, but source maps are in attributes.

Get me the first sample value of the enum element (in samples)

Get me the first value of the enum element

Manually add annotation to the parse result

Split parsing and compilation

As discussed in apiaryio/dredd#600, I think it would be beneficial to split parsing and compilation. As a first step, I propose this library to export two functions instead of just one:

  • parse
  • compile

That would solve #27 as well. Dredd would then use these two functions separately.

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.