This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$id": "https://example.com/cat.schema.json", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Cat", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "The cat's name." | ||
}, | ||
"age": { | ||
"description": "Age in years which must be equal to or greater than zero.", | ||
"type": "integer", | ||
"minimum": 0 | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"$id": https://example.com/cat.schema.json | ||
"$schema": http://json-schema.org/draft-04/schema# | ||
title: Cat | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
description: The cat's name. | ||
age: | ||
description: Age in years which must be equal to or greater than zero. | ||
type: integer | ||
minimum: 0 |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Example of parsing RAML 1.0 with basePath parameter. | ||
*/ | ||
const wap = require('webapi-parser').WebApiParser | ||
const path = require('path') | ||
|
||
const ramlStr = ` | ||
#%RAML 1.0 | ||
title: API with Types | ||
/users/{id}: | ||
get: | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
type: !include cat-schema.json | ||
` | ||
|
||
async function main () { | ||
// Parse RAML 1.0 string with basePath parameter | ||
console.log('Input:\n', ramlStr) | ||
const fpath = path.resolve( | ||
__dirname, | ||
'../api-specs/includes/api.raml') | ||
const location = `file://${fpath}` | ||
const model = await wap.raml10.parse(ramlStr, location) | ||
console.log('Model location:\n', model.location) | ||
const resolved = await wap.raml10.resolve(model) | ||
|
||
// Generate RAML 1.0 string | ||
const generated = await wap.raml10.generateString(resolved) | ||
console.log('Generated:\n', generated) | ||
} | ||
|
||
main() |