Giter VIP home page Giter VIP logo

metamorphoses's Introduction

Metamorphoses

In nova fert animus mutatas dicere formas / corpora;

Transforms API Blueprint AST or Refract API Description Namespace into Apiary Application AST.

Use

Do not use this library. You do not need it.

Really! We needed to create it for internal use within Apiary, but it is going to be deprecated and removed even internally as soon as we fully migrate to API Description Parse Result Namespace.

You ended up here for some reason though:

Purpose

Apiary supports three API description formats as of now:

API Blueprint - text/vnd.apiblueprint

  • Status: recommended, heavily used and under active development
  • Parser: Drafter
  • Parser Outputs:

Swagger - application/swagger+json or +yaml

To be able to work with both of these formats through some sort of uniform interface, Apiary internally transforms ASTs to a so-called Application AST. The Metamorphoses library does exactly this job, i.e. transforms any AST to the internal Apiary Application AST.

Note: The information above is simplified for the context of the Metamorphoses library. As noted in the introduction, API Blueprint AST is about to be slowly replaced by API Description Parse Result Namespace as the parser output. Once Fury has adapters to both API Blueprint and the legacy Apiary Blueprint, producing API Description Parse Result Namespace for both, and once Apiary starts to use the API Description API Description Namespace exclusively, this library becomes redundant.

Interface

var metamorphoses = require('metamorphoses');


// Blueprint source
var source = '# Sample API...';


// Select adapter by mime type:
// -   API Blueprint AST: 'application/vnd.apiblueprint.ast'
// -   Legacy Apiary Blueprint AST: 'application/vnd.legacyblueprint.ast'
var mimeType = 'application/vnd.apiblueprint.ast';
var adapter = metamorphoses.createAdapter(mimeType);


// You can also import the adapter directly:
// -   API Blueprint AST: apiBlueprintAdapter
var adapter = metamorphoses.apiBlueprintAdapter;


// Pseudo-code parse function. It is a placeholder for parser
// interface of either Drafter (https://github.com/apiaryio/drafter)
// or the legacy Blueprint Parser (https://github.com/apiaryio/blueprint-parser)
parse(source, ..., function (err, result) {

  // transform the error parse result into an error
  var err = adapter.transformError(source, parseResult);
  console.log(err); // transformed error object

  // transform the AST
  var ast = adapter.transformAst(result.ast);
  console.log(ast); // transformed AST (application AST)
  console.log(result.warnings); // parser warnings
  ...

});


// Blueprint API (Application AST)
metamorphoses.blueprintApi.Blueprint.fromJSON({
  ...
});

transformError

Transforming an error accepts the source API Description Document and the resultant parse result. The method returns an error if there was an error in the parse result, the error will be a JSON object as follows:

  • message - Error message
  • code - Error code
  • location (array) - Error source map
    • (object)
      • index (number)
      • length (number)
  • line - The line producing the error from the source API Description Document derived from the source map

Name

Wikipedia: The Metamorphoses (Latin: Metamorphōseōn librī: "Books of Transformations") is a Latin narrative poem by the Roman poet Ovid.

metamorphoses's People

Contributors

abtris avatar almad avatar danielgtaylor avatar freaz avatar honzajavorek avatar kuba-kubula avatar kylef avatar nadade avatar pksunkara avatar smizell avatar w-vi avatar

Stargazers

 avatar

Watchers

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

metamorphoses's Issues

TypeError: Object #<Object> has no method 'replace'

This shows up in logs:

error: [index] EXCEPTION_UNCAUGHT:  TypeError: Object #<Object> has no method 'replace' 
Nov 30 17:28:24 apiary app/web.1:   at Function.fixNewLines (/app/node_modules/@apiaryio/metamorphoses/lib/adapters/refract/helper.js:12:14) 
Nov 30 17:28:24 apiary app/web.1:   at baseWrapperValue (/app/node_modules/@apiaryio/metamorphoses/node_modules/lodash/index.js:2768:30) 
Nov 30 17:28:24 apiary app/web.1:   at LodashWrapper.wrapperValue (/app/node_modules/@apiaryio/metamorphoses/node_modules/lodash/index.js:6124:14) 
Nov 30 17:28:24 apiary app/web.1:   at Object.transformAst (/app/node_modules/@apiaryio/metamorphoses/lib/adapters/refract-adapter.js:15:64) 
Nov 30 17:28:24 apiary app/web.1:   at transformSuccessResponse (/app/lib/parser.coffee:227:25) 
Nov 30 17:28:24 apiary app/web.1:   at transformParsingServiceResponse (/app/lib/parser.coffee:199:17) 
Nov 30 17:28:24 apiary app/web.1:   at /app/lib/parser.coffee:83:7 
Nov 30 17:28:24 apiary app/web.1:   at fn (/app/node_modules/async/lib/async.js:741:34) 
Nov 30 17:28:24 apiary app/web.1:   at /app/node_modules/async/lib/async.js:1208:16 
Nov 30 17:28:24 apiary app/web.1:   at /app/node_modules/async/lib/async.js:166:37 
Nov 30 17:28:24 apiary app/web.1:   at /app/node_modules/async/lib/async.js:701:43 
Nov 30 17:28:24 apiary app/web.1:   at /app/node_modules/async/lib/async.js:167:37 
Nov 30 17:28:24 apiary app/web.1:   at /app/node_modules/async/lib/async.js:1204:30 
Nov 30 17:28:24 apiary app/web.1:   at Request._callback (/app/lib/parser.coffee:185:12) 
Nov 30 17:28:24 apiary app/web.1:   at Request.self.callback (/app/node_modules/request/request.js:198:22) 
Nov 30 17:28:24 apiary app/web.1:   at Request.emit (events.js:98:17) 
Nov 30 17:28:24 apiary app/web.1:   at Request.<anonymous> (/app/node_modules/request/request.js:1035:10) 
Nov 30 17:28:24 apiary app/web.1:   at Request.emit (events.js:117:20) 
Nov 30 17:28:24 apiary app/web.1:   at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:962:12) 
Nov 30 17:28:24 apiary app/web.1:   at IncomingMessage.emit (events.js:117:20) 
Nov 30 17:28:24 apiary app/web.1:   at IncomingMessage.wrapped (/app/node_modules/newrelic/lib/transaction/tracer/index.js:157:28) 
Nov 30 17:28:24 apiary app/web.1:   at IncomingMessage.wrappedEmit [as emit] (/app/node_modules/newrelic/lib/transaction/tracer/index.js:197:46) 
Nov 30 17:28:24 apiary app/web.1:   at _stream_readable.js:944:16 
Nov 30 17:28:24 apiary app/web.1:   at wrapped (/app/node_modules/newrelic/lib/transaction/tracer/index.js:157:28) 
Nov 30 17:28:24 apiary app/web.1:   at wrapped (/app/node_modules/newrelic/lib/transaction/tracer/index.js:157:28) 
Nov 30 17:28:24 apiary app/web.1:   at process._tickDomainCallback (node.js:492:13) 
Nov 30 17:28:24 apiary app/web.1:   at process.wrappedFunction (/app/node_modules/newrelic/lib/transaction/tracer/index.js:262:51) 

Cannot require Metamorphoses

Interestingly, I can install the module, but trying to use it fails because of a missing lib folder in the package:

npm install @apiaryio/metamorphoses
var metamorphoses = require('@apiaryio/metamorphoses');

WTF? Can't find the module?! It's right there!!!
╯°□°)╯︵ ┻━┻

cd node_modules/@apiaryio/metamorphoses
coffee -b -c -o lib/ src/
cd ../..

Try again and now it works, because the lib folder is there. Weird. 😏

cc @Baggz

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.