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

outline: Do not omit an empty nodes field when marshalling to JSON #762

Merged
merged 1 commit into from
Jan 18, 2021

Conversation

dlipovetsky
Copy link
Contributor

If an empty 'nodes' field is represented as an empty JSON array, then a client
unmarshalling from JSON does not need to allow for the possibility that the
'nodes' field is undefined. That makes it is easier for clients to operate on
the JSON.

Before:

{
  "name": "It",
  "text": "normal",
  "start": 336,
  "end": 363,
  "spec": true,
  "focused": false,
  "pending": false
}
{
  "name": "It",
  "text": "normal",
  "start": 336,
  "end": 363,
  "spec": true,
  "focused": false,
  "pending": false,
  "nodes": []
}

If an empty 'nodes' field is represented as an empty JSON array, then a client
unmarshalling from JSON does not need to allow for the possibility that the
'nodes' field is undefined. That makes it is easier for clients to operate on
the JSON.

Before:
```json
{
  "name": "It",
  "text": "normal",
  "start": 336,
  "end": 363,
  "spec": true,
  "focused": false,
  "pending": false
}
```

```json
{
  "name": "It",
  "text": "normal",
  "start": 336,
  "end": 363,
  "spec": true,
  "focused": false,
  "pending": false,
  "nodes": []
}
```
@dlipovetsky
Copy link
Contributor Author

I've been working on a vscode extension that calls ginkgo outline. It is much simpler for the client to use array semantics for the nodes field. For example, the client can always iterate over nodes, and assume the iteration will exit immediately for a leaf node, where nodes has zero length. Without this change, the client must check whether nodes is defined before iterating over it.

Feedback welcome!

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

Successfully merging this pull request may close these issues.

None yet

2 participants