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

Emitter options deal with path #2241

Closed
timotheeguerin opened this issue Aug 2, 2023 · 1 comment
Closed

Emitter options deal with path #2241

timotheeguerin opened this issue Aug 2, 2023 · 1 comment
Assignees
Labels
design:needed A design request has been raised that needs a proposal

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Aug 2, 2023

Many of our emitters have options that are a path to a directory or a file. They are very incositent on their handleing and by default end-up being resolved relative to the current working directory. For example the examples-directory in the autorest emitter.

It would be nice to provide a way so an emitter can say this option is a path and that way the compiler could automatically interpolate it with the {project-root} or {cwd} if done explicitly and complain if the path is a relative path.

A potential approach would be to have the emitter options be defined in TypeSpec itself:

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

model EmitterOptions {
  `examples-dir`: TypeSpec.EmitterOptions.path
}

but maybe in the meantime we can just add that as a format or x-path: true extension in the jsonschema

@markcowl markcowl added the design:needed A design request has been raised that needs a proposal label Aug 2, 2023
@markcowl markcowl added this to the [2023] October milestone Aug 9, 2023
@timotheeguerin
Copy link
Member Author

timotheeguerin commented Sep 27, 2023

Proposal

In Typespec

If we had way to define option in typespec, could imagine the following:

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

model EmitterOptions {
  `examples-dir`: TypeSpec.EmitterOptions.absolutePath,
  `sub-folder`: TypeSpec.EmitterOptions.relativePath
}

Actually defining the options in typespec is not the core part of this proposal but this is what it would look like. It would anyway need to be compiled to some easy to parse format(like jsonschema) so compiler doesn't need to compile typespec to compile more typespec

In jsonschema

type: string
format: absolute-path
type: string
format: relative-path

Behavior

The expected behavior is when resolving the options the compiler would automatically validate that a path is actually absolute or complain if not. This would make sure user explicilty use {project-root} or {cwd}

Relative path would still be useful when interpolating things that can be undefined like path/{version}/foo.json and if version is undefeined it would produce path/foo.json instead of path//foo.json
Other things would be path complaining about backslash which cause so many issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design:needed A design request has been raised that needs a proposal
Projects
None yet
Development

No branches or pull requests

2 participants