Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dredd-transactions

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dredd-transactions

Compiles HTTP Transactions (Request-Response pairs) from an API description document

  • 10.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.7K
increased by29.64%
Maintainers
1
Weekly downloads
 
Created
Source

Dredd Transactions

npm version

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.

Keywords

FAQs

Package last updated on 16 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc