Skip to content

Commit

Permalink
feat(js-yaml): update our main YAML parser to v4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed Aug 9, 2021
1 parent d76e681 commit b601037
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 30 deletions.
75 changes: 70 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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 Down
2 changes: 1 addition & 1 deletion src/plugins/editor/editor-plugins/json-to-yaml.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});
}
}
}
}

0 comments on commit b601037

Please sign in to comment.