microsoft / microsoft/typespec

Json Schema should a union of literals be converted to an enum

Open
#2,545 0 comments 0 reactions 0 assignees View on GitHub
design:needed triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

```
model Foo {
a: "one" | "two"
}
```

```yaml
$schema: https://json-schema.org/draft/2020-12/schema
$id: Foo.yaml
type: object
properties:
a:
anyOf:
- type: string
const: one
- type: string
const: two
required:
- a
```

openapi3
```yaml
Foo:
type: object
required:
- a
properties:
a:
type: string
enum:
- one
- two
```
[Playground Link](https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvanNvbi1zY2hlbWEiOwoKdXNpbmcgVHlwZVNwZWMuSnNvblPFHTsKCkDELMYOCm5hbWVzcGFjZSDGEXM7Cgptb2RlbCBGb28gewogIGE6ICJvbmUiIHwgInR3byIKfQ%3D%3D&e=%40typespec%2Fjson-schema&options=%7B%7D)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.