Add xml library following the approved design.
fix#2970
Only minor change was inverting the parmaeters for `@ns(namespace,
prefix` instead of `@namespace(prefix, namespace)` which makes it
clearer with the other overload `@ns(namespace: EnumMember)`
---------
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
`@server` works to provide values for the `servers` object, as is
documented elsewhere in the same files. This PR updates the table to
reflect that. Closes#3071.
Co-authored-by: Mario Guerra <85648637+mario-guerra@users.noreply.github.com>
Co-authored-by: Libba Lawrence <llawrence@microsoft.com>
Co-authored-by: Allen Zhang <allenzhang@live.com>
Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
PR added support for it but we need to update the docs to explain the
new feature.
---------
Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
Hi! 🖖🏻
This PR resolves#2624 by implementing the [design
doc](https://gist.github.com/timotheeguerin/56690786e61a436710dd647de9febc0f),
but in its initial form:
- `@useAuth` can now be applied not only to service namespace, but to
interfaces and operations as well. Its arguments override all
authentication, which was set for enclosing scopes.
- OAuth2 scopes can now be set at operation level (though, the code
doing this in OpenAPI emitter is a bit clunky).
- New `NoAuth` authentication option allows to declare optional
authentication (`NoAuth | AnyOtherAuth`) or override authentication to
none in nested scopes.
This implementation does not introduce new `@authScopes` decorator as
design doc comments suggest, and here's why:
1. It does not compose well with `@useAuth` at operation level. For
example
```
...
@useAuth(BasicAuth)
@authScopes(MyOauth2, ["read"])
op gogo(): void
```
Should that be equivalent to `BasicAuth | MyOauth2`, or to `[BasicAuth,
MyOauth2]`?
2. Introducing new decorator would increase complexity, but (imho) it
would not reduce the amount of boilerplate:
```
alias MyOAuth2 = OAuth2Auth<{ ... }>;
@useAuth(MyOAuth2)
@authAcopes(MyOauth2, ["read"])
@service
namepsace Foo;
```
vs
```
model MyOAuth2Flow<T extends string[]> { ... };
alias MyOauth2<T extends string[]> = Oauth2Auth<[MyOauth2Flow[T]]>
@useAuth(MyOAuth2<["read"]>)
@service
namepsace Foo
```
I would be happy to hear any feedback and apply suggested changes.
And thanks for a convenient development setup and thorough test
coverage!
---------
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Closes#2718
This change adds support for an optional message that emitters may use
to communicate the context of a pattern validation error.
I also added some baseline tests for `@pattern` since there were none in
decorators.spec.ts.
---------
Co-authored-by: Will Temple <will@wtemple.net>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Add vitest ui package and `test:ui` command to popup the vitest UI
https://vitest.dev/guide/ui
Import the common vitest config from the workspace so each package
doesn't need to define all of it.
Added `watchExclude: []` to the common config to preven vitest from
excluding dist and node_modules folder which is required so it can auto
rerun the test on when a dependency (monorepo dep) rebuilds
Added debug config to debug the current test. As the vitest extensions
is quite unreliable this should help
Add a new library template with:
- `@alernateName` decorator with some custom diagnostics and tests for
it.
- a linter rule and 2 rulesets(`recommended` and `all`)
Get rid of mocha and upgrade to vitest which is a more modern
alternative providing, watch, direct typescript compilation out of the
box, expect library and more.
Advantage over mocha:
- Much better cli
- watch mode
- better diff
- Better extension:
- tree organization for files too (not everything flattened)
- update in real time the test(no more need to refresh manually to
discover where are the tests)
- just a little buggy
- Compiles typescript directly
- provides more expectation apis(like jest)
Cons over mocha:
- Slower(about 2x) but that means we don't need to build the test as
part of build which would speed up that part(not as much as is lost)
Todo:
- typespec-azure migration
fix#2301
## Deteach the linter from `$lib`
Having the linter rules defined in `$lib` caused this circular reference
where the rules would call to some accessor that needed the $lib
diagnostics.
With this we keep $lib as manifest and helper functions only.
## Add state key declaration
```ts
export const internalLib = createTypeSpecLibrary({
state: {
authentication: { description: "State for the @auth decorator" },
header: { description: "State for the @header decorator" },
...
});
// use with StateKeys.authentication
```
## Add 3 new helper functions to be able to change the casing in
templates
```
naming.pascalCase
naming.camelCase
naming.kebabCase
```
## Update the `emitter-ts` to interpolate the emitter name
## Add snapshot test for templates
This way we can see what instantiating the template does at review time
and catch errors that wouldn't make the template crash the e2e test but
would still not be optimal
## Add a new template for scaffolding an emitter
`emitter-ts` template setup the following:
- basic emitter files
- typescript
- test with node test runner with basic test and test host setup
- prettier
- linting with eslint
## Change to the init area
- Added a new `--template` cli option to allow selecting the template
without a prompt.
- Refactor to make it easier to test. **Note that none of the API is
exposed yet so its just for internal use.**
## Added e2e test for templates
Scafold the template and then run commands like `npm install`, `npm run
build`, `npm run test`, etc. to make sure everything is done correctly.
This is quite costly so might be worth separating in a different step
Implementation of named template arguments as described in #2340.
I added a new syntax node (TemplateArgument), and a cover grammar for
this node:
`<Expression> ('=' <Expression>)?`
Rather than ExpressionNode, the type of a template argument is now
`TemplateArgumentNode`.
If the `=` is parsed, we assert in the parser that the first Expression
must be a "bare identifier" (i.e. a TypeReference with `target:
Identifier`) and unwrap the identifier to produce a clean AST with
`name?: Identifier
Template arguments are evaluated in the order that they were declared,
not in the order they are specified in the instantiation. The new
template argument checker _replaces_ the previous one, and it performs
normalization of argument order and typechecking of template arguments
all in one pass.
TODO:
- [x] Review templates across core libraries to ensure that template
arguments have good names.
- [x] Documentation of new behavior in website.
- [x] Semantic/tmlanguage colorization of tokens.
- [x] Validate that the AST printer produces the correct text for the
new template argument nodes and that the output is well-formatted.
- [x] Completion of template argument names in argument position.
- [x] Hover context on template argument names in instantiation.
Closes#2340
---------
Co-authored-by: Will Temple <will@wtemple.net>
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
I am following the document to create an emitter and found this link of
steps to initialize a typespec library is not working. So I create this
PR to update the md to point the link to basics.md file, which is for
creating a TypeSpec library.
update docs to bump node version from 14/16 to 18, which aligns with tsp
`0.50.0`
---------
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Fix#2497.
Clarifies which TypeSpec types these decorators can _actually_ be used
on by-design.
**BREAKING CHANGE** This is a breaking change because if unsupported
elements were previously decorated with these (i.e. Namespaces) those
will now throw an error.
Same pr in typespec-azure
https://github.com/Azure/typespec-azure/pull/3641
Migrate to use the `types` entry under `exports` instead of hte legacy
typesVersions. This was a leftover to when es modules where not
completely supported in typescript and using typesVersions was a
workaround.
Progress in #2480
## `Swc-loader`
Some minor perf improviement. Using `swc-loader` is much faster at
loading the js in the compile stage. This make the timed build nearly
50% faster but it **still gets stuck at** `cache (99%) shutdown
IdleFileCachePlugin` for the vast majority of the time. So this is a
little win but nearly negligable
## Updateing `typedoc-markdown`
This has changed the file structure to group by folder and has basically
brought back the perf from before the migration to the new doc format.
Not sure why but it works great now.
fix [#2333](https://github.com/microsoft/typespec/issues/2333)
I went through the docs and copied the samples as I went to make sure
everything was working fine.
With `tsp compile . --watch` you get a nice result with this doc now.
---------
Co-authored-by: Mike Kistler <mikekistler@microsoft.com>
This PR fixes#2059 by requiring that a semicolon appear after an
augment decorator statement. This is a breaking change but it should be
mitigated by the fact that the TypeSpec formatter already adds a
semicolon for all augment decorator statements.
This PR tweaks the way that models are included in output specifications
when they are not referenced by operations and adds an option for
controlling this behavior.
The option is `omit-unreachable-types` after the OpenAPI v3 emitter
which uses the same name, and the behavior in the protobuf emitter is
similar. If a message is expliclty decorated with `@message` or is
referenced direclty or indirectly by an operation/method, it will be
emitted. Otherwise, it will be emitted if (1) it is a direct child of a
`package` namespace AND (2) ALL of its fields are annotated with
`@field` AND (3) the `omit-unreachable-types` option is not set to true.
Closes#1879
---------
Co-authored-by: Will Temple <will@wtemple.net>
This PR revises the logic for encodings on utcDateTime and
offsetDateTime to set the `format` to the `encoding` value for any
unrecognized values. For backward compatibility, a special case is added
for `rfc7231` which maps to `format: date-time-rfc7231`.
Tests and docs are updated.
## Update
Revised this PR to map rfc7231 to http-date in the openapi3 emitter.
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
fix#2130
Generate the README.md for typespec libraries automatically using the
subset of the content as what gets included in the ref doc
To achieve this I reoganized the markdown rendering to be able to
provide a reusable system that can be cusomized for different markdown
engines.
- The markdown renderer will render a markdown compatible with Github
Flavored Markdown.
- The docusuaurs rendererer extends the markdown renderer and include a
few extra metadata.
fix#2239
`useRef` decorator in openapi3 library was missing `valueof` for ref
paramater which led to it saving the `StringLiteral` object instead of
the actual ref string.