microsoft / microsoft/typespec
Converting JSON to values in code fixes
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Clear and concise description of the problem
People may have JSON on hand when trying to create examples for their models, but examples are expected to be values.
It would be nice if the existing "convert to an object value" code fix that handles when you drop a model into a spot designated for a value [[Playground]](https://typespec.io/playground?c=QGV4YW1wbGUoeyJCYXoiOiAiSGVsbG8ifSkNCm1vZGVsIEZvb0JhciB7IEJheiA6IHN0cmluZzsgfQ%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D):
```
@example(#{"Baz": "Hello"})
model FooBar { Baz : string; }
```
would turn it into a value
```
@example(#{Baz: "Hello"})
```
instead of to an invalid value [[Playground]](https://typespec.io/playground?c=QGV4YW1wbGUoI3siQmF6IjogIkhlbGxvIn0pDQptb2RlbCBGb29CYXIgeyBCYXogOiBzdHJpbmc7IH0%3D&e=%40typespec%2Fopenapi3&options=%7B%7D):
```
@example(#{"Baz": "Hello"})
```
This would ease migrations to TypeSpec while removing a case where a codefix leaves invalid code after being applied.
### Checklist
- [X] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [docs](https://typespec.io/docs/).
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
Assessment
This issue has not been assessed yet.