microsoft / microsoft/typespec

Emitter options as TypeSpec

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

Description

## Problem

Problem with the current approach

- **Overkill**: Right now we use a `jsonschema` with `ajv` to validate which works great but both feels like a bit too overkill
- **Duplication**: You currently have to write the TypeScript schema and JSON schema for each option as well as duplicating the documentation to be available in both ref docs and intelisense. This makes it hard to maintain as the jsonschema doc needs to be a string hard to read.
- **Custom types**: There is some custom types that would be nice to be able to provide. For example `path` #2241, ref resolution, namespace name, version, etc.

## Proposal

```tsp
import "@typespec/compiler/emitter-options";

model MyOptions {
name: string;
`model-dir`: TypeSpec.EmitterOptions.absolutePath;
}
```

which would generate the following typescript

```ts
interface MyOptions {
name: string;
"model-dir": string;
}
```

and would compile to a json schema for validation

```yaml
type: object
properties:
name:
type: string
model-dir:
type: string
format: absolute-path
```

Alternatively we could have some simplified schema and use our own validator which would allow us to not depend on ajv anymore.

Or we have the typespec compiler compute the options on the fly

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.