Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js-yaml): update our main YAML parser to v4.1.0 #2760

Merged
merged 3 commits into from Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
101 changes: 73 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -67,7 +67,7 @@
"file-dialog": "0.0.8",
"immutable": "^3.x.x",
"is-json": "^2.0.1",
"js-yaml": "^3.13.1",
"js-yaml": "=4.1.0",
"json-beautify": "^1.0.1",
"json-refs": "^3.0.4",
"lodash": "^4.17.21",
Expand All @@ -87,8 +87,8 @@
"react-transition-group": "^1.1.1",
"redux": "^3.x.x",
"reselect": "^4.0.0",
"swagger-client": "^3.14.1",
"swagger-ui": "^3.51.2",
"swagger-client": "^3.15.0",
"swagger-ui": "^3.52.0",
"traverse": "^0.6.6",
"validator": "=13.6.0",
"yaml-js": "^0.2.3"
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/editor/editor-plugins/json-to-yaml.js
Expand Up @@ -9,7 +9,7 @@ export default function(editor) {

let yamlString
try {
yamlString = YAML.safeDump(YAML.safeLoad(originalStr), {
yamlString = YAML.dump(YAML.load(originalStr), {
lineWidth: -1 // don't generate line folds
})
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/json-schema-validator/index.js
Expand Up @@ -6,8 +6,8 @@ import debounce from "lodash/debounce"
import swagger2SchemaYaml from "./swagger2-schema.yaml"
import oas3SchemaYaml from "./oas3-schema.yaml"

const swagger2Schema = YAML.safeLoad(swagger2SchemaYaml)
const oas3Schema = YAML.safeLoad(oas3SchemaYaml)
const swagger2Schema = YAML.load(swagger2SchemaYaml)
const oas3Schema = YAML.load(oas3SchemaYaml)

// Lazily created promise worker
let _promiseWorker
Expand Down
12 changes: 6 additions & 6 deletions src/standalone/topbar-insert/forms/components/AddForm.jsx
Expand Up @@ -9,7 +9,7 @@ class AddForm extends Component {

this.state = {
formErrors: false,
formData: this.props.existingData ?
formData: this.props.existingData ?
this.props.getFormData( (newForm, path) => this.updateForm(newForm, path), [], this.props.existingData) :
this.props.getFormData( (newForm, path) => this.updateForm(newForm, path), [] )
}
Expand Down Expand Up @@ -40,15 +40,15 @@ class AddForm extends Component {

// Update the spec string in the Swagger UI state with the new json.
const currentJson = this.props.specSelectors.specJson()
this.props.specActions.updateSpec(YAML.safeDump(currentJson.toJS()), "insert")
this.props.specActions.updateSpec(YAML.dump(currentJson.toJS()), "insert")

// Perform any parent component actions for the form.
this.props.submit()
}

updateForm = (newFormData, path) => {
this.setState(prevState => ({
formData: prevState.formData.setIn(path, newFormData)
this.setState(prevState => ({
formData: prevState.formData.setIn(path, newFormData)
}))
}

Expand All @@ -61,15 +61,15 @@ class AddForm extends Component {
<div className="modal-body">
<div className="form-container">
<InsertForm formData={this.state.formData} getComponent={getComponent} />
</div>
</div>
</div>
<div className="modal-footer">
{ this.state.formErrors && <div className="invalid-feedback">Please fix errors before submitting.</div>}
<button className="btn btn-default" onClick={this.submit}>{this.props.submitButtonText}</button>
</div>
</div>
)
}
}
}

AddForm.propTypes = {
Expand Down
Expand Up @@ -14,9 +14,9 @@ export default class ImportFileMenuItem extends Component {

fileReader.onload = fileLoadedEvent => {
let content = fileLoadedEvent.target.result

try {
const preparedContent = isJsonObject(content) ? YAML.safeDump(YAML.safeLoad(content)) : content
const preparedContent = isJsonObject(content) ? YAML.dump(YAML.load(content)) : content

if (typeof onDocumentLoad === "function") {
onDocumentLoad(preparedContent)
Expand Down
16 changes: 8 additions & 8 deletions src/standalone/topbar/topbar.jsx
Expand Up @@ -66,7 +66,7 @@ export default class Topbar extends React.Component {
.then(res => {
this.setState({ clients: res.body || [] })
})

serverGetter({}, {
// contextUrl is needed because swagger-client is curently
// not building relative server URLs correctly
Expand Down Expand Up @@ -97,7 +97,7 @@ export default class Topbar extends React.Component {
.then(res => res.text())
.then(text => {
this.props.specActions.updateSpec(
YAML.safeDump(YAML.safeLoad(text), {
YAML.dump(YAML.load(text), {
lineWidth: -1
})
)
Expand Down Expand Up @@ -129,9 +129,9 @@ export default class Topbar extends React.Component {
//// so convert and download

// JSON String -> JS object
let jsContent = YAML.safeLoad(editorContent)
let jsContent = YAML.load(editorContent)
// JS object -> YAML string
let yamlContent = YAML.safeDump(jsContent)
let yamlContent = YAML.dump(jsContent)
this.downloadFile(yamlContent, `${fileName}.yaml`)
}

Expand All @@ -146,7 +146,7 @@ export default class Topbar extends React.Component {
}

// JSON or YAML String -> JS object
let jsContent = YAML.safeLoad(editorContent)
let jsContent = YAML.load(editorContent)
// JS Object -> pretty JSON string
let prettyJsonContent = beautifyJson(jsContent, null, 2)
this.downloadFile(prettyJsonContent, `${fileName}.json`)
Expand All @@ -164,8 +164,8 @@ export default class Topbar extends React.Component {
convertToYaml = () => {
// Editor content -> JS object -> YAML string
let editorContent = this.props.specSelectors.specStr()
let jsContent = YAML.safeLoad(editorContent)
let yamlContent = YAML.safeDump(jsContent)
let jsContent = YAML.load(editorContent)
let yamlContent = YAML.dump(jsContent)
this.props.specActions.updateSpec(yamlContent)
}

Expand Down Expand Up @@ -361,7 +361,7 @@ export default class Topbar extends React.Component {
</DropdownMenu>
<DropdownMenu {...makeMenuOptions("Edit")}>
<li><button type="button" onClick={this.convertToYaml}>Convert to YAML</button></li>
<ConvertDefinitionMenuItem
<ConvertDefinitionMenuItem
isSwagger2={specSelectors.isSwagger2()}
onClick={() => topbarActions.showModal("convert")}
/>
Expand Down
10 changes: 5 additions & 5 deletions test/unit/plugins/json-schema-validator/index.js
Expand Up @@ -6,8 +6,8 @@ import path from 'path';
const swagger2SchemaYaml = fs.readFileSync(path.join(__dirname, '../../../../src/plugins/json-schema-validator/swagger2-schema.yaml')).toString();
const oas3SchemaYaml = fs.readFileSync(path.join(__dirname, '../../../../src/plugins/json-schema-validator/oas3-schema.yaml')).toString();

const swagger2Schema = YAML.safeLoad(swagger2SchemaYaml);
const oas3Schema = YAML.safeLoad(oas3SchemaYaml);
const swagger2Schema = YAML.load(swagger2SchemaYaml);
const oas3Schema = YAML.load(oas3SchemaYaml);


var testDocuments = fs
Expand All @@ -19,7 +19,7 @@ var testDocuments = fs
}))
.map(doc => ({
path: doc.path,
content: YAML.safeLoad(doc.contentString)
content: YAML.load(doc.contentString)
}));

testDocuments.forEach(doc => {
Expand Down Expand Up @@ -85,5 +85,5 @@ function assertCaseExpectations(currentCase, result) {
itFn('should equal expected value', function() {
expect(result).toEqual(currentCase.output.equal);
});
}
}
}
}