Created
September 21, 2015 07:59
-
-
Save yhaskell/0e5c942d4cd528b0539b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%RAML 0.8 | |
title: New API | |
version: v1 | |
baseUri: http://api.samplehost.com | |
resourceTypes: | |
- base : | |
get?: | |
queryParameters: | |
username: | |
required: <<required>> | |
example: username=demo | |
responses: | |
200: | |
description: <<description>> | |
body: | |
application/xml: | |
/helloWorld: | |
get: | |
responses: | |
200: | |
body: | |
application/json: | |
example: | | |
{ | |
"message" : "Hello World" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs = require("fs") | |
import path = require("path") | |
import _=require("underscore") | |
import tsstruct = require("../raml1/tsStructureParser") | |
import ts2def = require("../raml1/tsStrut2Def") | |
import jsyaml = require("../raml1/jsyaml/jsyaml2lowLevel") | |
import yaml=require("../raml1/jsyaml/yamlAST") | |
import def = require("../raml1/definitionSystem") | |
import ll=require("../raml1/lowLevelAST") | |
import yll=require("../raml1/jsyaml/jsyaml2lowLevel") | |
import high = require("../raml1/highLevelImpl") | |
import hl=require("../raml1/highLevelAST") | |
import t3 = require("../raml1/artifacts/raml003parser") | |
import textutil = require("../util/textutil") | |
import pair = require("../util/pair"); | |
import hlimpl = require('../raml1/highLevelImpl') | |
import defs=require("../raml1/definitionSystem") | |
/* this file lies in /src/sandbox folder */ | |
var pdir = path.resolve(__dirname, "."); | |
var modPath = path.resolve(__dirname, "../raml1/spec-1.0/api.ts"); | |
var decls = fs.readFileSync(modPath).toString(); | |
var src = tsstruct.parseStruct(decls, {}, modPath); | |
var universe = ts2def.toDefSystem(src); | |
var apiType = <def.NodeClass>universe.type("Api"); | |
export function loadApi(name: string = 'api.raml'):high.ASTNodeImpl { | |
var p = new jsyaml.Project(pdir); | |
var unit = p.unit('data/' + name); | |
var api = new high.ASTNodeImpl(unit.ast(), null, <any>apiType, null); | |
return api; | |
} | |
function genStructuredValue(name: string, parent: hl.IHighLevelNode, pr: hl.IProperty) : string | hlimpl.StructuredValue { | |
if (pr.range() instanceof defs.ReferenceType){ | |
var t=<defs.ReferenceType>pr.range(); | |
var mockNode=jsyaml.createNode(name); | |
return new hlimpl.StructuredValue(mockNode, parent, pr); | |
// var hn = stv.toHighlevel() | |
// return hn; | |
} else return name; | |
} | |
var api = loadApi('api.raml'); | |
var node:hl.IHighLevelNode = api.elementsOfKind('resources')[0]; | |
var attr = node.attrOrCreate("type"); | |
var result = genStructuredValue("base", node, node.definition().property('type')); | |
var sv = <hlimpl.StructuredValue>result; | |
var svh = sv.toHighlevel(); | |
svh.attrOrCreate("required").setValue("true"); | |
svh.attrOrCreate("description").setValue("secondValue"); | |
node.attr("type").setValue(sv); | |
console.log(node.lowLevel().dump()); | |
console.log(node.lowLevel().unit().contents()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment