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

Anchor on property which uses alias fails validation #273

Closed
dleavitt opened this issue Jul 9, 2020 · 5 comments
Closed

Anchor on property which uses alias fails validation #273

dleavitt opened this issue Jul 9, 2020 · 5 comments
Labels

Comments

@dleavitt
Copy link

dleavitt commented Jul 9, 2020

Schema:

{
  "title": "Field definitions schema!",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "field": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label"],
      "properties": {
        "label": { "type": "string" }
      }
    },
    "model": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "props": {
          "type": "object",
          "additionalProperties": { "$ref": "#/definitions/field" }
        }
      }
    }
  },
  "type": "object",
  "additionalProperties": { "$ref": "#/definitions/model" }
}

Document:

Named:
  props: &NamedProps
    name:
      label: Name

Timestamped:
  props: &TimestampedProps
    <<: *NamedProps
    ts:
      label: Timestamp

Record:
  props:
    <<: *TimestampedProps # commenting out this line removes the errors
    id:
      label: ID

Looks like it's incorrectly adding a layer of nesting or something?

Screenshot 2020-07-08 20 25 57 Screenshot 2020-07-08 20 25 51

@JPinkney JPinkney added the bug label Jul 9, 2020
@JPinkney
Copy link
Contributor

JPinkney commented Jul 9, 2020

From what I remember the way the merge key works in the code is it basically replaces << with the value so

Timestamped:
  props: &TimestampedProps
    <<: *NamedProps
    ts:
      label: Timestamp

becomes

Timestamped:
  props: &TimestampedProps
    name:
      label: Name
    ts:
      label: Timestamp

and then

Record:
  props:
    <<: *TimestampedProps
    id:
      label: ID

should become

Record:
  props:
    name:
      label: Name
    ts:
      label: Timestamp
    id:
      label: ID

but my guess is somewhere along the lines something is going wrong but then again anchors are the piece of the spec I understand the least

@dleavitt
Copy link
Author

Yep, and that's what it does become when parsed. It's just an issue with the schema validation, from what I can tell.

@dleavitt dleavitt changed the title Anchor on property which uses reference fails validation Anchor on property which uses alias fails validation Jul 13, 2020
@JPinkney
Copy link
Contributor

JPinkney commented Aug 6, 2020

I think I've finally figured out what the issue is here. I think only the first merge key is being transformed and not the second one so the representation to the parser is:

Named:
  props: &NamedProps
    name:
      label: Name

Timestamped:
  props: &TimestampedProps
    <<: *NamedProps
    ts:
      label: Timestamp

Record:
  props:
    Timestamped:
      props: &TimestampedProps
        <<: *NamedProps
      ts:
        label: Timestamp
    id:
      label: ID

leading to the issue

@dleavitt
Copy link
Author

Anything I can do to help? My yamls are all red :(

@JPinkney
Copy link
Contributor

I haven't been able to look into it but my hunch is that the first merge key is being properly expanded but the second one isn't, leading to the error. The code that does that is here: https://github.com/redhat-developer/yaml-language-server/blob/master/src/languageservice/parser/jsonParser07.ts#L951 if you want to poke around

andrew-stripe added a commit to metcalf/yaml-language-server that referenced this issue Apr 26, 2021
andrew-stripe added a commit to metcalf/yaml-language-server that referenced this issue Apr 27, 2021
andrew-stripe added a commit to metcalf/yaml-language-server that referenced this issue Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants