const yaml = require('js-yaml')
const yamlData = `
openapi: 3.0.0
info:
title: my-api
description: Some description.
version: 6.0
`
// Define a custom schema that treats all numbers as strings
const SCHEMA = yaml.DEFAULT_SCHEMA.extend({
implicit: [
new yaml.Type('tag:yaml.org,2002:float', {
kind: 'scalar',
resolve: data => !isNaN(data),
construct: data => data.toString(),
predicate: data => typeof data === 'string',
represent: data => data,
}),
],
})
// Parse the YAML string into a JavaScript object using the custom schema
const obj = yaml.load(yamlData, { schema: SCHEMA })
console.log(obj)