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

$ref and values with hash (#) support #566

Open
olegsmetanin opened this issue Aug 18, 2024 · 1 comment
Open

$ref and values with hash (#) support #566

olegsmetanin opened this issue Aug 18, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@olegsmetanin
Copy link

Is your feature request related to a problem? Please describe.
YAML.parse(...) for

test:
  foo:
    prop: hello
  bar:
    $ref: #/test/foo/prop

returns

{
  "test": {
    "foo": {
      "prop": "hello"
    },
    "bar": {
      "$ref": null
    }
  }
}

I have tried to parse openapi spec with $ref: #/foo/bar properties, it seems that # always acts as a comment and parse function always returns null for $ref property. Moreover, reviver function (key, value) => string already getting null for such values.

Describe the solution you'd like
YAML.parse(str, reviver?, options = {}) could provide:

  1. additional option to define the list of specific keys like ['$ref', ...]
  2. additional optional key-value mapper "originalReviver" which will be called for every specific tag with original yaml value

Describe alternatives you've considered
It seems that I have to preprocess yaml files, collect $refs values before YAML.parse() and patch result object with original values after YAML.parse()

@olegsmetanin olegsmetanin added the enhancement New feature or request label Aug 18, 2024
@eemeli
Copy link
Owner

eemeli commented Aug 18, 2024

This sounds like an API layer you may build on top of the library, or find if one is already available for OpenAPI content. It's not a YAML feature, though, so not appropriate to include here directly.

Scalar values starting with # will, however, need to be quoted to not be parsed as comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants