Skip to content

Commit 447fb67

Browse files
authored
Merge branch 'master' into feature/headerfix
2 parents 5aa7f30 + e1a49ee commit 447fb67

File tree

8 files changed

+274
-40
lines changed

8 files changed

+274
-40
lines changed

CONTRIBUTING.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Contributing to Swagger-UI
2+
3+
We love contributions from our community of users! This document explains our guidelines and workflows. Please take care to follow them, as it helps us keep things moving smoothly.
4+
5+
#### Environment setup
6+
7+
0. Install Node.js (4 or newer) and npm (3 or newer).
8+
1. Make a fork of Swagger-UI on GitHub, then clone your fork to your machine.
9+
2. Run `npm install` in your Swagger-UI directory.
10+
3. Run `npm run dev`. `localhost:3200` should open automatically.
11+
4. You're ready to go!
12+
13+
#### Branching model
14+
15+
Feature branches should be prefixed with `ft/`.
16+
17+
Bugfix branches should be prefixed with `bug/`.
18+
19+
Version branches should be prefixed with `v/`.
20+
21+
After the forward slash, include a short description of what you're fixing. For example: `bug/fix-everything-that-was-broken`. For versions, add the version that will be released via the branch, for example: `v/1.2.3`.
22+
23+
If there's an issue filed that you're addressing in your branch, include the issue number directly after the forward slash. For example: `bug/1234-fix-all-the-other-things`.
24+
25+
#### Filing issues
26+
27+
- **Do** include the Swagger-UI build you're using - you can find this by opening your console and checking `window.versions.swaggerUi`
28+
- **Do** include a spec that demonstrates the issue you're experiencing.
29+
- **Do** include screenshots, if needed. GIFs are even better!
30+
- **Do** place code inside of a pre-formatted container by surrounding the code with triple backticks.
31+
- **Don't** open tickets discussing issues with the Swagger/OpenAPI specification itself, or for issues with projects that use Swagger-UI.
32+
- **Don't** open an issue without searching the issue tracker for duplicates first.
33+
34+
#### Committing
35+
36+
- Break your commits into logical atomic units. Well-segmented commits make it _much_ easier for others to step through your changes.
37+
- Limit your subject (first) line to 50 characters (GitHub truncates more than 70).
38+
- Provide a body if you'd like to explain your commit in detail.
39+
- Capitalize the beginning of your subject line, and do not end the subject line with a period.
40+
- Your subject line should complete this sentence: `If applied, this commit will [your subject line].`
41+
- Don't use [magic GitHub words](https://help.github.com/articles/closing-issues-using-keywords/) in your commits to close issues - do that in the pull request for your code instead.
42+
43+
_Adapted from [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/#seven-rules)._
44+
45+
#### Making pull requests
46+
47+
- **Do** summarize your changes in the PR body. If in doubt, write a bullet-point list titled `This PR does the following:`.
48+
- **Do** include references to issues that your PR solves, and use [magic GitHub words](https://help.github.com/articles/closing-issues-using-keywords/) to close those issues automatically when your PR is merged.
49+
- **Do** include tests that cover new or changed functionality.
50+
- **Do** be careful to follow our ESLint style rules. We recommend installing an ESLint plugin if you use a graphical code editor.
51+
- **Do** make sure that tests and the linter are passing by running `npm test` locally, otherwise we can't merge your pull request.
52+
- **Don't** include any changes to files in the `dist/` directory - we update those files only during releases.
53+
- **Don't** mention maintainers in your original PR body - we probably would've seen it anyway, so it just increases the noise in our inboxes. Do feel free to ping maintainers if a week has passed and you've heard nothing from us.
54+
- **Don't** open PRs for custom functionality that only serves a small subset of our users - custom functionality should be implemented outside of our codebase, via a plugin.

src/core/components/param-body.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export default class ParamBody extends PureComponent {
6969
let { param, fn:{inferSchema} } = this.props
7070
let schema = inferSchema(param.toJS())
7171

72-
return getSampleSchema(schema, xml)
72+
return getSampleSchema(schema, xml, {
73+
includeWriteOnly: true
74+
})
7375
}
7476

7577
onChange = (value, { isEditBox, isXml }) => {

src/core/components/response.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ export default class Response extends React.Component {
8383

8484
if(isOAS3()) {
8585
let oas3SchemaForContentType = response.getIn(["content", this.state.responseContentType, "schema"])
86-
sampleResponse = oas3SchemaForContentType ? getSampleSchema(oas3SchemaForContentType.toJS(), this.state.responseContentType, { includeReadOnly: true }) : null
86+
sampleResponse = oas3SchemaForContentType ? getSampleSchema(oas3SchemaForContentType.toJS(), this.state.responseContentType, {
87+
includeReadOnly: true
88+
}) : null
8789
schema = oas3SchemaForContentType ? inferSchema(oas3SchemaForContentType.toJS()) : null
8890
} else {
8991
schema = inferSchema(response.toJS())
90-
sampleResponse = schema ? getSampleSchema(schema, contentType, { includeReadOnly: true }) : null
92+
sampleResponse = schema ? getSampleSchema(schema, contentType, {
93+
includeReadOnly: true,
94+
includeWriteOnly: true // writeOnly has no filtering effect in swagger 2.0
95+
}) : null
9196
}
9297
let example = getExampleComponent( sampleResponse, examples, HighlightCode )
9398

src/core/curlify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function curl( request ){
2020
if ( request.get("body") ){
2121

2222
if(type === "multipart/form-data" && request.get("method") === "POST") {
23-
for( let [ k,v ] of request.get("body").values()) {
23+
for( let [ k,v ] of request.get("body").entrySeq()) {
2424
curlified.push( "-F" )
2525
if (v instanceof win.File) {
2626
curlified.push( `"${k}=@${v.name};type=${v.type}"` )

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const RequestBody = ({ requestBody, getComponent, specSelectors, contentType })
1616

1717
const mediaTypeValue = requestBodyContent.get(contentType)
1818

19-
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType)
19+
const sampleSchema = getSampleSchema(mediaTypeValue.get("schema").toJS(), contentType, {
20+
includeWriteOnly: true
21+
})
2022

2123
return <div>
2224
{ requestBodyDescription &&

src/core/plugins/samples/fn.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const primitives = {
99
"number": () => 0,
1010
"number_float": () => 0.0,
1111
"integer": () => 0,
12-
"boolean": (schema) => typeof schema.default === "boolean" ? schema.default : true
12+
"boolean": (schema) => typeof schema.default === "boolean" ? schema.default : true
1313
}
1414

1515
const primitive = (schema) => {
@@ -27,7 +27,7 @@ const primitive = (schema) => {
2727

2828
export const sampleFromSchema = (schema, config={}) => {
2929
let { type, example, properties, additionalProperties, items } = objectify(schema)
30-
let { includeReadOnly } = config
30+
let { includeReadOnly, includeWriteOnly } = config
3131

3232
if(example !== undefined)
3333
return example
@@ -46,16 +46,20 @@ export const sampleFromSchema = (schema, config={}) => {
4646
let props = objectify(properties)
4747
let obj = {}
4848
for (var name in props) {
49-
if ( !props[name].readOnly || includeReadOnly ) {
50-
obj[name] = sampleFromSchema(props[name], { includeReadOnly: includeReadOnly })
49+
if ( props[name].readOnly && !includeReadOnly ) {
50+
continue
5151
}
52+
if ( props[name].writeOnly && !includeWriteOnly ) {
53+
continue
54+
}
55+
obj[name] = sampleFromSchema(props[name], config)
5256
}
5357

5458
if ( additionalProperties === true ) {
5559
obj.additionalProp1 = {}
5660
} else if ( additionalProperties ) {
5761
let additionalProps = objectify(additionalProperties)
58-
let additionalPropVal = sampleFromSchema(additionalProps, { includeReadOnly: includeReadOnly })
62+
let additionalPropVal = sampleFromSchema(additionalProps, config)
5963

6064
for (let i = 1; i < 4; i++) {
6165
obj["additionalProp" + i] = additionalPropVal
@@ -65,7 +69,7 @@ export const sampleFromSchema = (schema, config={}) => {
6569
}
6670

6771
if(type === "array") {
68-
return [ sampleFromSchema(items, { includeReadOnly: includeReadOnly }) ]
72+
return [ sampleFromSchema(items, config) ]
6973
}
7074

7175
if(schema["enum"]) {
@@ -96,7 +100,7 @@ export const inferSchema = (thing) => {
96100
export const sampleXmlFromSchema = (schema, config={}) => {
97101
let objectifySchema = objectify(schema)
98102
let { type, properties, additionalProperties, items, example } = objectifySchema
99-
let { includeReadOnly } = config
103+
let { includeReadOnly, includeWriteOnly } = config
100104
let defaultValue = objectifySchema.default
101105
let res = {}
102106
let _attr = {}
@@ -177,27 +181,32 @@ export const sampleXmlFromSchema = (schema, config={}) => {
177181
example = example || {}
178182

179183
for (let propName in props) {
180-
if ( !props[propName].readOnly || includeReadOnly ) {
181-
props[propName].xml = props[propName].xml || {}
182-
183-
if (props[propName].xml.attribute) {
184-
let enumAttrVal = Array.isArray(props[propName].enum) && props[propName].enum[0]
185-
let attrExample = props[propName].example
186-
let attrDefault = props[propName].default
187-
_attr[props[propName].xml.name || propName] = attrExample!== undefined && attrExample
188-
|| example[propName] !== undefined && example[propName] || attrDefault !== undefined && attrDefault
189-
|| enumAttrVal || primitive(props[propName])
190-
} else {
191-
props[propName].xml.name = props[propName].xml.name || propName
192-
props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
193-
let t = sampleXmlFromSchema(props[propName])
194-
if (Array.isArray(t)) {
195-
res[displayName] = res[displayName].concat(t)
196-
} else {
197-
res[displayName].push(t)
198-
}
184+
if ( props[propName].readOnly && !includeReadOnly ) {
185+
continue
186+
}
187+
if ( props[propName].writeOnly && !includeWriteOnly ) {
188+
continue
189+
}
199190

191+
props[propName].xml = props[propName].xml || {}
192+
193+
if (props[propName].xml.attribute) {
194+
let enumAttrVal = Array.isArray(props[propName].enum) && props[propName].enum[0]
195+
let attrExample = props[propName].example
196+
let attrDefault = props[propName].default
197+
_attr[props[propName].xml.name || propName] = attrExample!== undefined && attrExample
198+
|| example[propName] !== undefined && example[propName] || attrDefault !== undefined && attrDefault
199+
|| enumAttrVal || primitive(props[propName])
200+
} else {
201+
props[propName].xml.name = props[propName].xml.name || propName
202+
props[propName].example = props[propName].example !== undefined ? props[propName].example : example[propName]
203+
let t = sampleXmlFromSchema(props[propName])
204+
if (Array.isArray(t)) {
205+
res[displayName] = res[displayName].concat(t)
206+
} else {
207+
res[displayName].push(t)
200208
}
209+
201210
}
202211
}
203212

test/core/curlify.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ describe("curlify", function() {
132132
url: "http://example.com",
133133
method: "POST",
134134
headers: { "content-type": "multipart/form-data" },
135-
body: [
136-
["id", "123"],
137-
["name", "Sahar"]
138-
]
135+
body: {
136+
id: "123",
137+
name: "Sahar"
138+
}
139139
}
140140

141141
let curlified = curl(Im.fromJS(req))
@@ -152,10 +152,10 @@ describe("curlify", function() {
152152
url: "http://example.com",
153153
method: "POST",
154154
headers: { "content-type": "multipart/form-data" },
155-
body: [
156-
["id", "123"],
157-
["file", file]
158-
]
155+
body: {
156+
id: "123",
157+
file
158+
}
159159
}
160160

161161
let curlified = curl(Im.fromJS(req))

0 commit comments

Comments
 (0)