Skip to content

Fixing indentation in the generated configuration #1663

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

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

Aniruddh25
Copy link
Contributor

@Aniruddh25 Aniruddh25 commented Aug 28, 2023

Why make this change?

  • With the overhaul of the config system using our own Write method while serializing objects, the config that is generated is misaligned with respect to indentation for all the keys under each entity name.
    For e.g.:
    In the following picture, the entity name Todo is indented with 4 leading spaces, subsequently its child key source should have been indented with 6 leading spaces, however its currently indented with only 2 spaces.

image

What is this change?

  • Use the same writer to serialize the subkeys under the entity name so that the depth of indentation is maintained.

How does this change fix the issue?

  • WriteRawValue writes the json string argument provided as is without doing any additional formatting on it. It doesn't utilize the _currentDepth private member of the writer to determine how to indent.

  • Prior to this change, we were generating the inner json string first then writing the generated inner json "as is". While generating that json on line 29

string json = JsonSerializer.Serialize(entity, options);

Line 29 in 31b7542

a new writer is being used by the JsonSerializer.Serialize() function, effectively resetting the _currentDepth. The _currentDepth of the writer in context was not getting honored.

How was this tested?

  • Manual test, building solution and using dab add to simulate automatic writing of an entity to the config file. With the change, the indentation is fixed.

image

@Aniruddh25 Aniruddh25 enabled auto-merge (squash) August 29, 2023 00:54
Copy link
Contributor

@aaronpowell aaronpowell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we regenerate the config files in the test projects to make sure they are formatted properly (or are they already?)

Copy link
Contributor

@severussundar severussundar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting and fixing this!

@Aniruddh25 Aniruddh25 merged commit 57886c9 into main Aug 29, 2023
@Aniruddh25 Aniruddh25 deleted the fixIndentation branch August 29, 2023 05:09
Aniruddh25 added a commit that referenced this pull request Aug 29, 2023
## Why make this change?

- With the overhaul of the config system using our own Write method
while serializing objects, the config that is generated is misaligned
with respect to indentation for all the keys under each entity name.
For e.g.:
In the following picture, the entity name `Todo` is indented with 4
leading spaces, subsequently its child key `source` should have been
indented with 6 leading spaces, however its currently indented with only
2 spaces.


![image](https://github.com/Azure/data-api-builder/assets/3513779/4c4a926f-ae22-444e-bc86-23f207b3cf22)

- This is a regression in 0.8.44-rc.

## What is this change?

- Use the same writer to serialize the subkeys under the entity name so
that the depth of indentation is maintained.

## How does this change fix the issue?
- `WriteRawValue` writes the json string argument provided as is without
doing any additional formatting on it. It doesn't utilize the
`_currentDepth` private member of the writer to determine how to indent.

- Prior to this change, we were generating the inner json string first
then writing the generated inner json "as is". While generating that
json on line 29


https://github.com/Azure/data-api-builder/blob/31b754251832ffebf4c4ce36ffcbead9baff6355/src/Config/Converters/RuntimeEntitiesConverter.cs#L29

Line 29 in
[31b7542](31b7542)

a new writer is being used by the `JsonSerializer.Serialize()` function,
effectively resetting the `_currentDepth`. The `_currentDepth` of the
writer in context was not getting honored.

## How was this tested?

- Manual test, building solution and using `dab add` to simulate
automatic writing of an entity to the config file. With the change, the
indentation is fixed.


![image](https://github.com/Azure/data-api-builder/assets/3513779/bf708ecc-4fa2-4711-ba88-844c24922b81)
Aniruddh25 added a commit that referenced this pull request Aug 29, 2023
- Cherry Picking #1663. 

----------------

## Why make this change?

- With the overhaul of the config system using our own Write method
while serializing objects, the config that is generated is misaligned
with respect to indentation for all the keys under each entity name. For
e.g.:
In the following picture, the entity name `Todo` is indented with 4
leading spaces, subsequently its child key `source` should have been
indented with 6 leading spaces, however its currently indented with only
2 spaces.



![image](https://github.com/Azure/data-api-builder/assets/3513779/4c4a926f-ae22-444e-bc86-23f207b3cf22)

- This is a regression in 0.8.44-rc.

## What is this change?

- Use the same writer to serialize the subkeys under the entity name so
that the depth of indentation is maintained.

## How does this change fix the issue?
- `WriteRawValue` writes the json string argument provided as is without
doing any additional formatting on it. It doesn't utilize the
`_currentDepth` private member of the writer to determine how to indent.

- Prior to this change, we were generating the inner json string first
then writing the generated inner json "as is". While generating that
json on line 29



https://github.com/Azure/data-api-builder/blob/31b754251832ffebf4c4ce36ffcbead9baff6355/src/Config/Converters/RuntimeEntitiesConverter.cs#L29

Line 29 in

[31b7542](31b7542)

a new writer is being used by the `JsonSerializer.Serialize()` function,
effectively resetting the `_currentDepth`. The `_currentDepth` of the
writer in context was not getting honored.

## How was this tested?

- Manual test, building solution and using `dab add` to simulate
automatic writing of an entity to the config file. With the change, the
indentation is fixed.



![image](https://github.com/Azure/data-api-builder/assets/3513779/bf708ecc-4fa2-4711-ba88-844c24922b81)
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.

4 participants