Merge branch 'master' into 3014-contributing-guidelines
This commit is contained in:
@@ -69,7 +69,9 @@ export default class ParamBody extends PureComponent {
|
|||||||
let { param, fn:{inferSchema} } = this.props
|
let { param, fn:{inferSchema} } = this.props
|
||||||
let schema = inferSchema(param.toJS())
|
let schema = inferSchema(param.toJS())
|
||||||
|
|
||||||
return getSampleSchema(schema, xml)
|
return getSampleSchema(schema, xml, {
|
||||||
|
includeWriteOnly: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = (value, { isEditBox, isXml }) => {
|
onChange = (value, { isEditBox, isXml }) => {
|
||||||
|
|||||||
@@ -83,11 +83,16 @@ export default class Response extends React.Component {
|
|||||||
|
|
||||||
if(isOAS3()) {
|
if(isOAS3()) {
|
||||||
let oas3SchemaForContentType = response.getIn(["content", this.state.responseContentType, "schema"])
|
let oas3SchemaForContentType = response.getIn(["content", this.state.responseContentType, "schema"])
|
||||||
sampleResponse = oas3SchemaForContentType ? getSampleSchema(oas3SchemaForContentType.toJS(), this.state.responseContentType, { includeReadOnly: true }) : null
|
sampleResponse = oas3SchemaForContentType ? getSampleSchema(oas3SchemaForContentType.toJS(), this.state.responseContentType, {
|
||||||
|
includeReadOnly: true
|
||||||
|
}) : null
|
||||||
schema = oas3SchemaForContentType ? inferSchema(oas3SchemaForContentType.toJS()) : null
|
schema = oas3SchemaForContentType ? inferSchema(oas3SchemaForContentType.toJS()) : null
|
||||||
} else {
|
} else {
|
||||||
schema = inferSchema(response.toJS())
|
schema = inferSchema(response.toJS())
|
||||||
sampleResponse = schema ? getSampleSchema(schema, contentType, { includeReadOnly: true }) : null
|
sampleResponse = schema ? getSampleSchema(schema, contentType, {
|
||||||
|
includeReadOnly: true,
|
||||||
|
includeWriteOnly: true // writeOnly has no filtering effect in swagger 2.0
|
||||||
|
}) : null
|
||||||
}
|
}
|
||||||
let example = getExampleComponent( sampleResponse, examples, HighlightCode )
|
let example = getExampleComponent( sampleResponse, examples, HighlightCode )
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ const RequestBody = ({ requestBody, getComponent, specSelectors, contentType })
|
|||||||
|
|
||||||
const mediaTypeValue = requestBodyContent.get(contentType)
|
const mediaTypeValue = requestBodyContent.get(contentType)
|
||||||
|
|
||||||
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType)
|
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType, {
|
||||||
|
includeWriteOnly: true
|
||||||
|
})
|
||||||
|
|
||||||
return <div>
|
return <div>
|
||||||
{ requestBodyDescription &&
|
{ requestBodyDescription &&
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const primitive = (schema) => {
|
|||||||
|
|
||||||
export const sampleFromSchema = (schema, config={}) => {
|
export const sampleFromSchema = (schema, config={}) => {
|
||||||
let { type, example, properties, additionalProperties, items } = objectify(schema)
|
let { type, example, properties, additionalProperties, items } = objectify(schema)
|
||||||
let { includeReadOnly } = config
|
let { includeReadOnly, includeWriteOnly } = config
|
||||||
|
|
||||||
if(example !== undefined)
|
if(example !== undefined)
|
||||||
return example
|
return example
|
||||||
@@ -46,16 +46,20 @@ export const sampleFromSchema = (schema, config={}) => {
|
|||||||
let props = objectify(properties)
|
let props = objectify(properties)
|
||||||
let obj = {}
|
let obj = {}
|
||||||
for (var name in props) {
|
for (var name in props) {
|
||||||
if ( !props[name].readOnly || includeReadOnly ) {
|
if ( props[name].readOnly && !includeReadOnly ) {
|
||||||
obj[name] = sampleFromSchema(props[name], { includeReadOnly: includeReadOnly })
|
continue
|
||||||
}
|
}
|
||||||
|
if ( props[name].writeOnly && !includeWriteOnly ) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
obj[name] = sampleFromSchema(props[name], config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( additionalProperties === true ) {
|
if ( additionalProperties === true ) {
|
||||||
obj.additionalProp1 = {}
|
obj.additionalProp1 = {}
|
||||||
} else if ( additionalProperties ) {
|
} else if ( additionalProperties ) {
|
||||||
let additionalProps = objectify(additionalProperties)
|
let additionalProps = objectify(additionalProperties)
|
||||||
let additionalPropVal = sampleFromSchema(additionalProps, { includeReadOnly: includeReadOnly })
|
let additionalPropVal = sampleFromSchema(additionalProps, config)
|
||||||
|
|
||||||
for (let i = 1; i < 4; i++) {
|
for (let i = 1; i < 4; i++) {
|
||||||
obj["additionalProp" + i] = additionalPropVal
|
obj["additionalProp" + i] = additionalPropVal
|
||||||
@@ -65,7 +69,7 @@ export const sampleFromSchema = (schema, config={}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(type === "array") {
|
if(type === "array") {
|
||||||
return [ sampleFromSchema(items, { includeReadOnly: includeReadOnly }) ]
|
return [ sampleFromSchema(items, config) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
if(schema["enum"]) {
|
if(schema["enum"]) {
|
||||||
@@ -96,7 +100,7 @@ export const inferSchema = (thing) => {
|
|||||||
export const sampleXmlFromSchema = (schema, config={}) => {
|
export const sampleXmlFromSchema = (schema, config={}) => {
|
||||||
let objectifySchema = objectify(schema)
|
let objectifySchema = objectify(schema)
|
||||||
let { type, properties, additionalProperties, items, example } = objectifySchema
|
let { type, properties, additionalProperties, items, example } = objectifySchema
|
||||||
let { includeReadOnly } = config
|
let { includeReadOnly, includeWriteOnly } = config
|
||||||
let defaultValue = objectifySchema.default
|
let defaultValue = objectifySchema.default
|
||||||
let res = {}
|
let res = {}
|
||||||
let _attr = {}
|
let _attr = {}
|
||||||
@@ -177,7 +181,13 @@ export const sampleXmlFromSchema = (schema, config={}) => {
|
|||||||
example = example || {}
|
example = example || {}
|
||||||
|
|
||||||
for (let propName in props) {
|
for (let propName in props) {
|
||||||
if ( !props[propName].readOnly || includeReadOnly ) {
|
if ( props[propName].readOnly && !includeReadOnly ) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ( props[propName].writeOnly && !includeWriteOnly ) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
props[propName].xml = props[propName].xml || {}
|
props[propName].xml = props[propName].xml || {}
|
||||||
|
|
||||||
if (props[propName].xml.attribute) {
|
if (props[propName].xml.attribute) {
|
||||||
@@ -199,7 +209,6 @@ export const sampleXmlFromSchema = (schema, config={}) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (additionalProperties === true) {
|
if (additionalProperties === true) {
|
||||||
res[displayName].push({additionalProp: "Anything can be here"})
|
res[displayName].push({additionalProp: "Anything can be here"})
|
||||||
|
|||||||
@@ -1,6 +1,105 @@
|
|||||||
import { createXMLExample } from "corePlugins/samples/fn"
|
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
|
||||||
import expect from "expect"
|
import expect from "expect"
|
||||||
|
|
||||||
|
describe("sampleFromSchema", function() {
|
||||||
|
it("returns object with no readonly fields for parameter", function () {
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
readOnlyDog: {
|
||||||
|
readOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
id: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns object with readonly fields for parameter, with includeReadOnly", function () {
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
readOnlyDog: {
|
||||||
|
readOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
id: 0,
|
||||||
|
readOnlyDog: "string"
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition, { includeReadOnly: true })).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns object without writeonly fields for parameter", function () {
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
writeOnlyDog: {
|
||||||
|
writeOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
id: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
writeOnlyDog: {
|
||||||
|
writeOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var expected = {
|
||||||
|
id: 0,
|
||||||
|
writeOnlyDog: "string"
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("createXMLExample", function () {
|
describe("createXMLExample", function () {
|
||||||
var sut = createXMLExample
|
var sut = createXMLExample
|
||||||
@@ -554,6 +653,69 @@ describe("createXMLExample", function () {
|
|||||||
expect(sut(definition, { includeReadOnly: false })).toEqual(expected)
|
expect(sut(definition, { includeReadOnly: false })).toEqual(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns object with readonly fields for parameter, with includeReadOnly", function () {
|
||||||
|
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
dog: {
|
||||||
|
readOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sut(definition, { includeReadOnly: true })).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns object without writeonly fields for parameter", function () {
|
||||||
|
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n</animals>"
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
dog: {
|
||||||
|
writeOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sut(definition)).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
|
||||||
|
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
|
||||||
|
var definition = {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: "integer"
|
||||||
|
},
|
||||||
|
dog: {
|
||||||
|
writeOnly: true,
|
||||||
|
type: "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
xml: {
|
||||||
|
name: "animals"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(sut(definition, { includeWriteOnly: true })).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
it("returns object with passed property as attribute", function () {
|
it("returns object with passed property as attribute", function () {
|
||||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals id=\"0\">\n\t<dog>string</dog>\n</animals>"
|
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals id=\"0\">\n\t<dog>string</dog>\n</animals>"
|
||||||
var definition = {
|
var definition = {
|
||||||
|
|||||||
Reference in New Issue
Block a user