Comments (6)
@jstoiko is this issue still relevant after rework using webapi-parser?
We already validate dt2js output while running integration tests. IMO if integration tests pass, we can assume dt2js produces valid json.
I think this step should be performed during development/testing (as it is now) and not in users' projects.
from ramldt2jsonschema.
would it “cost” a lot to add a —validate
option to dt2js and use AJV to validate? if not, I think it’s worth working on it for a future minor release.
from ramldt2jsonschema.
would it “cost” a lot to add a
—validate
option to dt2js and use AJV to validate?
It wouldn't.
if not, I think it’s worth working on it for a future minor release.
Ok
from ramldt2jsonschema.
@jstoiko should validation only work when using dt2js as CLI?
I think it should because when using it from js code:
- Users can validate output json schema by themselves if they want;
- Output of dt2js would become complicated because then it would have to be either validation report or json schema, and have some flag to show if schema is valid or not.
Or should it work both in CLI and js and throw an error when output schema is invalid, instead of returning a validation report?
from ramldt2jsonschema.
I have an idea. Would you be able to provide two simple examples, one showing dt2js
CLI + output pipes using ajv-cli
(or any other "standard"/popular JSON Schema validator), and the other one showing how to achieve the same in code. Let's see what it looks like. Maybe we don't need this feature at all as longs as they're easy ways to get to the same result.
from ramldt2jsonschema.
Below are code examples.
Validating output schema in JS code is pretty simple. Validating using CLI, on the other hand, is complicated. I didn't find any CLI libs to validate json schema other than ajv-cli. It doesn't have support for piping so a complex command has to be constructed to make it work with dt2js.
const r2j = require('ramldt2jsonschema')
const ramlData = `#%RAML 1.0 Library
types:
Cat:
type: object
properties:
name: string
color: string`
async function main () {
const schema = await r2j.dt2js(ramlData, 'Cat')
schema.required = 123
const Ajv = require('ajv')
const ajv = new Ajv({ allErrors: true, schemaId: 'auto' })
const valid = ajv.validateSchema(schema)
if (!valid) {
const errorsText = ajv.errorsText(ajv.errors, { separator: '; ' })
throw new Error(`Invalid json: ${errorsText}`)
}
}
main()
$ ajv -d <(dt2js ../test/integration/raml/complex_homeanimal.raml Cat) -s <(curl http://json-schema.org/draft-07/schema#)
from ramldt2jsonschema.
Related Issues (20)
- Test & describe accurately the limitations in the README HOT 1
- Fails silently for (some) old node versions - include min version in ReadMe? HOT 1
- RAML to JSON schema conversion not working properly HOT 7
- Add type:nil support HOT 2
- `dt2js` does not always output a `$schema` property HOT 4
- Validate RAML Datatype output of js2dt
- JSON schema to RAML not converting arrays HOT 5
- Question js2dt HOT 7
- Is a 'full API definition json' to raml conversion possible? HOT 12
- "Cannot parse document with specified vendor: OAS 2.0" despite attempting to run js2dt command HOT 4
- resolving references not working HOT 4
- script not working on windows; need help HOT 1
- Can someone review the bot pull request please?
- All versions greater than v1.0.0 have CLI dt2js broken! HOT 3
- Please update README for Mandatory dependency to ajv
- Dependency to json-schema-migrate
- An in-range update of commander is breaking the build 🚨 HOT 1
- Use webapi-parser to convert HOT 3
- Compare old vs new conversion output HOT 4
- Schema generation not working properly when raml key contains dot('.') in it HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ramldt2jsonschema.