Skip to content

Commit

Permalink
Merge pull request #8 from luckymarmot/006-cheatsheet
Browse files Browse the repository at this point in the history
🎩  improved naming structure and minor fixes
  • Loading branch information
JonathanMontane committed Aug 29, 2016
2 parents dddbb98 + 7e407e2 commit 982c6bb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ This structure can be used with the following values:

## JSON Schema Quickstart
If you are not very familiar with JSON Schemas, this should help you get the basics.
We strongly advise to read the [RFC drafts](http://json-schema.org/documentation.html) to better understand the intricacies of JSON Schemas.

The guys at the [Space Telescope Science Institute](https://github.com/spacetelescope) have made an awesome documentation about JSON Schemas, that's infinitely better than anything I could produce, and that you should [definitely check out](https://spacetelescope.github.io/understanding-json-schema/)

This extension is not fully compliant with the more advanced use of JSON Schemas, unfortunately.

### JSON Schema Introduction
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"mocha": "2.4.5",
"webpack": "1.12.14"
},
"eslintConfig": {
"extends": "./linting/prod.yaml"
},
"scripts": {
"build": "rm -rf build/ && BUILD_ENV=build ./node_modules/.bin/webpack --bail --display-error-details",
"test": "$npm_package_options_mocha \"src/**/__tests__/*-test.js\"",
Expand Down
44 changes: 40 additions & 4 deletions src/JSONSchemaFakerDynamicValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,67 @@ import {
export default class JSONSchemaFakerDynamicValue {
static identifier =
'com.luckymarmot.PawExtensions.JSONSchemaFakerDynamicValue'
static title = 'JSON Schema Faker'
static help =
'https://github.com/luckymarmot/Paw-JSONSchemaFakerDynamicValue'
static title = 'JSF'

static inputs = [
new InputField('schema', 'Schema', 'JSON', { persisted: true }),
new InputField(
'resolveRefs',
'Resolve References',
'Checkbox',
{ defaultValue: true }
{ defaultValue: true, persisted: true }
),
new InputField(
'predict',
'Guess Formats',
'Checkbox',
{ defaultValue: true }
{ defaultValue: true, persisted: true }
),
new InputField(
'changeName',
'Do not use x-title as name',
'Checkbox',
{ defaultValue: false, persisted: true }
)
]

constructor() {
this.context = null
}

title() {
return 'JSF'
if (
!this.changeName &&
this.schema &&
(
typeof this.schema.title === 'string' ||
typeof this.schema['x-title'] === 'string'
)
) {
return '\uD83C\uDFA9'
}

return 'JSF \uD83C\uDFA9'
}

text() {
if (!this.changeName && this.schema) {
if (typeof this.schema.title === 'string') {
return this.schema.title
}
else if (typeof this.schema['x-title'] === 'string') {
return this.schema['x-title']
}
}

return null
}

evaluate(context) {
this.context = context

jsf.option({
failOnInvalidTypes: false,
defaultInvalidTypeProduct: null
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/JSONSchemaFakerDynamicValue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,18 @@ export class TestJSONSchemaFakerDynamicValue extends UnitTest {
// TODO
}

@targets('title')
@desc('_ignored')
_testTitle() {
// TODO
}

@targets('text')
@desc('_ignored')
_testText() {
// TODO
}

__init(schema, resolveRefs = true, domainName) {
const dv = new ClassMock(new JSONSchemaFakerDynamicValue(domainName))
dv.schema = schema
Expand Down

0 comments on commit 982c6bb

Please sign in to comment.