// // BlueprintSourcemap.h // snowcrash // // Created by Pavan Kumar Sunkara on 26/8/14. // Copyright (c) 2014 Apiary Inc. All rights reserved. // #ifndef SNOWCRASH_BLUEPRINT_SOURCEMAP_H #define SNOWCRASH_BLUEPRINT_SOURCEMAP_H #include "Blueprint.h" #include "MSONSourcemap.h" /** * API Blueprint Sourcemap Abstract Syntax Tree * --------------------------------------------- * * Data types in this documents define the API Blueprint Sourcemap AST. */ namespace snowcrash { /** Source Map of Metadata Collection */ SOURCE_MAP_COLLECTION(Metadata, MetadataCollection) /** Source Map of Headers */ // 'Metadata' type is same as 'Header' /** Source Map of Collection of Parameter values */ SOURCE_MAP_COLLECTION(Value, Values) /** * Source Map Structure for Parameter */ template<> struct SourceMap : public SourceMapBase { /** Source Map of Parameter Name */ SourceMap name; /** Source Map of Parameter Description */ SourceMap description; /** Source Map of Parameter Type */ SourceMap type; /** Source Map of Required flag */ SourceMap use; /** Source Map of Default Value, applicable only when `required == false` */ SourceMap defaultValue; /** Source Map of Example Value */ SourceMap exampleValue; /** Enumeration of possible values */ SourceMap values; }; /** * Source Map Structure for MSON Parameter */ template<> struct SourceMap : public SourceMap { }; /** Source Map of Collection of Parameters */ SOURCE_MAP_COLLECTION(Parameter, Parameters) /** * Source Map Structure for DataStructure */ template<> struct SourceMap : public SourceMap { }; /** Source Map Structure for Attributes */ // 'Attributes' is the same as 'DataStructure' /** * Source Map Structure for Payload */ template<> struct SourceMap : public SourceMapBase { /** Source Map of a Payload Name */ SourceMap name; /** Source Map of Payload Description */ SourceMap description; /** Source Map of Payload-specific Parameters */ SourceMap parameters; /** Source Map of Payload-specific Headers */ SourceMap headers; /** Source Map of Payload-specific Attributes (THIS SHOULD NOT BE HERE - should be under content) */ SourceMap attributes; /** Source Map of Body (THIS SHOULD NOT BE HERE - should be under content) */ SourceMap body; /** Source Map of Schema (THIS SHOULD NOT BE HERE - should be under content) */ SourceMap schema; /** Source Map of Model Reference */ SourceMap reference; }; /** Source Map of Collection of Requests */ SOURCE_MAP_COLLECTION(Request, Requests) /** Source Map of Collection of Responses */ // 'Response' type is same as 'Request' /** * Source Map Structure for an HTTP transaction example. */ template<> struct SourceMap : public SourceMapBase { /** Source Map of an example name */ SourceMap name; /** Source Map of Description */ SourceMap description; /** Requests */ SourceMap requests; /** Responses */ SourceMap responses; }; /** Source Map of Collection of Transaction examples */ SOURCE_MAP_COLLECTION(TransactionExample, TransactionExamples) /** * Source Map Structure for Action */ template<> struct SourceMap : public SourceMapBase { /** Source Map of HTTP method */ SourceMap method; /** Source Map of an Action name */ SourceMap name; /** Source Map of Description */ SourceMap description; /** Action-specific Parameters */ SourceMap parameters; /** Action-specific Attributes (THIS SHOULD NOT BE HERE - should be under content) */ SourceMap attributes; /** Source Map of URI Template (THIS SHOULD NOT BE HERE - should be under element attributes) */ SourceMap uriTemplate; /** Source Map of Link Relation (THIS SHOULD NOT BE HERE - should be under element attributes) */ SourceMap relation; /** * \brief Action-specific HTTP headers * * DEPRECATION WARNING: * -------------------- * * This AST node is build for deprecated API Blueprint syntax * and as such it will be removed in a future version of * Snow Crash. * * Use respective payload's header collection instead. */ DEPRECATED SourceMap headers; /** Transactions examples */ SourceMap examples; }; /** Source Map of Collection of Actions */ SOURCE_MAP_COLLECTION(Action, Actions) /** * Source Map Structure for API Resource */ template<> struct SourceMap : public SourceMapBase { /** Source Map of URI template */ SourceMap uriTemplate; /** Source Map of a Resource Name */ SourceMap name; /** Source Map of Description of the resource */ SourceMap description; /** Model representing this Resource */ SourceMap model; /** Source Map of Resource-specific Attributes (THIS SHOULD NOT BE HERE - should be under content) */ SourceMap attributes; /** Parameters */ SourceMap parameters; /** * \brief Resource-specific HTTP Headers * * DEPRECATION WARNING: * -------------------- * * This AST node is build for deprecated API Blueprint syntax * and as such it will be removed in a future version of * Snow Crash. * * Use respective payload's header collection instead. */ DEPRECATED SourceMap headers; /** A set of Actions specified for this Resource */ SourceMap actions; }; /** Source Map of Collection of Resources */ SOURCE_MAP_COLLECTION(Resource, Resources) /** Forward Declaration for Source Map of Element */ template<> struct SourceMap; /** Source Map of Collection of Elements */ SOURCE_MAP_COLLECTION(Element, Elements) /** * Source Map Structure for Element */ template<> struct SourceMap : public SourceMapBase { /** Source Map Structure for Attributes of the Element */ struct Attributes { /** Source Map of a Element Name */ SourceMap name; }; /** Source Map Structure for Content of the Element */ struct Content { /** EITHER Source Map of Copy */ SourceMap copy; /** OR Source Map of Resource */ SourceMap resource; /** OR Source Map of Data Structure */ SourceMap dataStructure; /** OR Source Map of Collection of elements */ SourceMap& elements(); const SourceMap& elements() const; /** Constructor */ Content(); /** Copy constructor */ Content(const SourceMap::Content& rhs); /** Assignment operator */ SourceMap::Content& operator=(const SourceMap::Content& rhs); /** Destructor */ ~Content(); private: std::unique_ptr > m_elements; }; /** Class of the Element (to be used internally only) */ Element::Class element; /** Source Map of Attributes of the Element */ Attributes attributes; /** Source Map of Content of the Element */ Content content; /** Type of the Category element (to be used internally only) */ Element::Category category; /** Constructor */ SourceMap(const Element::Class& element_ = Element::UndefinedElement); /** Copy constructor */ SourceMap(const SourceMap& rhs); /** Assignment operator */ SourceMap& operator=(const SourceMap& rhs); /** Destructor */ ~SourceMap(); }; /** * Source Map Structure for Group of API Resources (Category Element) */ template<> struct SourceMap : public SourceMap { }; /** * Source Map Structure for Group of Data Structures (Category Element) */ template<> struct SourceMap : public SourceMap { }; /** * \brief API Blueprint Sourcemap AST * * This is top-level (or root if you prefer) of API Blueprint Sourcemap abstract syntax tree. * Start reading a parsed API here. */ template<> struct SourceMap : public SourceMap { /** Source Map of the API Name */ SourceMap name; /** Source Map of API Blueprint metadata */ SourceMap metadata; /** Source Map of an API Overview description */ SourceMap description; }; } #undef SOURCE_MAP_COLLECTION #endif