jlblcc / json-schema-viewer

JavaScript tool for visualizing json-schemas
jlblcc.github.io/json-schema-viewer
The Unlicense
186 stars 69 forks source link

Improved allOf/anyOf/oneOf display #11

Closed foxxyz closed 8 years ago

foxxyz commented 9 years ago

When displaying sub-schemas specified within a combination block, the allOf/anyOf/oneOf keyword is currently repeated if the sub-schema does not have a "title" set. This change proposes using the type as a fallback instead of repeating the keyword. This makes way more sense for a schemas such as:

"participants": {
    "type": "array",
    "description": "People involved in the event",
    "items": {
        "oneOf": [
            {
                "type": "object",
                "properties": {
                    "role": {
                        "type": "string",
                        "description": "Role of this participant"
                    },
                    "name": {
                        "type": "string",
                        "description": "Participant's name"
                    }
                },
                "required": ["name"]
            },
            {
                "type": "string",
                "description": "Participant's name"
            }
        ]
    }
}

The main change here is s.title || all[key][i].type (from: s.title || key), the rest are nesting simplifications for readability.

foxxyz commented 9 years ago

@jlblcc let me know if you have any suggestions/changes for acceptance! Thanks!

jlblcc commented 9 years ago

Sorry, meant to get back to you on this. I'm not opposed to merging this, but can't merge this in as is. The code fails the jshint validation. Specifically, the The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. Line 772.

Note: I added a basic TravisCI config that runs jshint - that should auto-check any pull requests from now on.

foxxyz commented 9 years ago

Ah, my fault entirely. Should have checked jshint before submitting the request.

I've made the change to pass the validation, although if you look at the change it makes the code a bit more redundant than it needs to be.

Regardless, thanks for the feedback and let me know if there's anything else that concerns you!

foxxyz commented 8 years ago

@jlblcc Please let me know if there's anything I can do to speed up adoption of this PR! Thanks!

foxxyz commented 8 years ago

Appreciate it, thanks for the awesome code @jlblcc

jlblcc commented 8 years ago

Thanks for the reminder and the contributions.