Граф коммитов

333 Коммитов

Автор SHA1 Сообщение Дата
Timothee Guerin 4af9030264
Do not carry over friendly name with `model is` or `op is` (#3793)
fix #2276 As the design for a dedicated `@instanceName` was not approved
due to the concern that we should maybe have a more generic `@name`
decorator that handle template I am just fixing this very anyoing carry
over that requires using `@friendlyName` in all derived models when it
is used upstream.

This is technically a breaking change as if you used to have 

```
@friendlyName("Abc{T}", T)
model Foo<T> {}

model Bar is Foo<string>
```
it would have created  a model called `Abcstring` instead of `Bar`

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-07-16 17:52:57 +00:00
Timothee Guerin 5a4a5d4547
Add validator to prevent discriminator and encodedname used together (#3763)
fix [#3507](https://github.com/microsoft/typespec/issues/3507)
2024-07-16 17:22:54 +00:00
Timothee Guerin c7339f0c65
Keep trailing slash when building http routes (#3737)
fix [#3350](https://github.com/microsoft/typespec/issues/3350)
2024-07-15 23:25:21 +00:00
Christopher Radek 65a0288c2e
update tsp-openapi3 automatic doc newlines logic (#3839)
Fixes #3835 

`tsp-openapi3` will no longer automatically attempt to wrap
documentation strings based on maximum column width.

It will still honor any line breaks that exist in the original
documentation when generating doc strings.

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
2024-07-15 18:00:26 +00:00
Sarangan Rajamanickam 982ef9adb8
Move @typespec/compiler from dependencies to peerDependencies (#3699)
Per the requirement in Issue:
https://github.com/microsoft/typespec/issues/3632, the dependency of
`@typespec/compiler` has to be moved from `dependencies` to
`peerDependencies`. This PR moves the dependency.
2024-07-12 17:36:31 +00:00
Laurent Mazuel b7c70978ca
Add ? for madeOptional (#3820)
`madeOptional` implies the current property is optional, so adding the
missing `?`
2024-07-11 21:12:15 +00:00
Timothee Guerin a54e3bddf9
Fix formatting of scalar constructor with no args (#3823)
fix #3819
2024-07-11 20:49:09 +00:00
Timothee Guerin f3afdfa61e
Do not cast model expression to object value if the constraint is allowing the type (#3824)
fix [#3576](https://github.com/microsoft/typespec/issues/3576)
2024-07-11 20:14:05 +00:00
Will Temple b5d766cd43
[http-server-javascript] Merge JavaScript Server Generator to Main (#3231)
This work-in-progress PR tracks merging the JavaScript server code
generator to the TypeSpec repository.

The JavaScript server code generator creates HTTP bindings for TypeSpec
HTTP services and exposes them for binding either to the Node.js http
server directly, or to an Express.js app as middleware.

Closes #3215

---------

Co-authored-by: Will Temple <will@wtemple.net>
2024-07-10 21:44:45 +00:00
Timothee Guerin 07193bac43
Fix breaking change with `formatIdentifier` renamed to `printIdentifier` (#3809)
Keeping both for now, could also add `@deprecated` on`formatIdentifier`
to give ide guidance
2024-07-10 20:09:34 +00:00
Will Temple 859f79268b
[core] Disallow overriding a required property with an optional property (#3659)
Closes #3539 

This change disallows overriding a required inherited property with an
optional property.

This error does not take precedence over regular property assignability
rules. In case the property _both_ is optional when the overridden
property is required _and_ has a non-assignable type, both errors will
be reported.

---------

Co-authored-by: Will Temple <will@wtemple.net>
2024-07-10 17:00:20 +00:00
Timothee Guerin 2ebacf5ff5
Organize and add test and documentation for printIdentifier helper (#3792)
This is something that is quite useful for any external tool that want
to write some typespec code(Openapi3 to tsp converter for example or api
view)

Edit: actually that was already exported as that exact name directly
from the formatter. This then just adds tests
2024-07-10 15:18:30 +00:00
Christopher Radek 181dd8aaf3
Updates tsp-openapi3 to emit main.tsp even when formatter fails (#3794)
This updates the `tsp-openapi3` CLI so that it emits `main.tsp` even
when the formatter detects an issue. The CLI will still throw the error
after it is done emitting the file.

The `convertOpenAPI3Document` function used by the website does not
throw on formatter errors - the playground will highlight any TSP errors
already.

Playground example with bad emission:

![image](https://github.com/microsoft/typespec/assets/14189820/cbddf049-5928-4969-b1fa-cbf98ea95bc0)

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
2024-07-09 23:46:23 +00:00
Irvine Sunday 9fda9cd15d
Adds public function for setting info object directly (#3626)
Fixes https://github.com/microsoft/typespec/issues/3446

By adding support for extending namespace, we will be able to add
extensions to the OpenAPI `info` object via the new function -
`setNamespaceExtension(...)`

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-07-09 16:43:26 +00:00
Sylvain Bruyère bd0c7d63af
Fix doc errors for `@errorsDoc` and `@returnsDoc` decorators (#3600)
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-07-08 20:33:39 +00:00
Timothee Guerin 56b456d75e
Import openapi3 document in playground (#3750)
<img width="364" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/e9597497-97c3-4103-b0df-acf553e5af78">

<img width="726" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/00511247-8f95-4839-99a0-4d14c03b24b6">
2024-07-08 18:20:12 +00:00
Justin 245e4e620d
fix: fixes issue with tests not being found from template (#3605)
fix [#3647](https://github.com/microsoft/typespec/issues/3647)

With node 22 the --test needs a glob to find files to test. As the docs
a written the tests don't run or pass. This fixes it for me.

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-07-08 17:47:07 +00:00
Yuchao Yan a38126c1b6
[Http] expose necessary api for multipart (#3676)
TCGC needs these API exposed

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-07-08 17:29:59 +00:00
Timothee Guerin 7900f29d65
Classify single using (#3767)
fix  #3629
2024-07-08 17:27:00 +00:00
Christopher Radek 1cc570c72f
Updates tsp init to generate .gitignore file (#3751)
Fixes https://github.com/microsoft/typespec/issues/3262

This adds a new confirmation prompt to `tsp init` to generate a
.gitignore file. Defaults to yes (true).

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
2024-07-08 17:15:01 +00:00
Timothee Guerin 4553419b75
Enable react hooks linting and fix issues (#3761)
fix #3745
2024-07-08 17:10:06 +00:00
Rodge Fu 53836c5548
Fix "tsp vs install" command (#3743)
fixes #3615
2024-07-06 08:25:23 +00:00
Timothee Guerin e54a7f8fd0
TypeGraph Viewer V2 (#3713)
https://cadlplayground.z22.web.core.windows.net/prs/3713/
<img width="1155" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/6adfa086-fc97-4ab8-8557-a5e50a291a57">
2024-07-03 20:18:39 +00:00
Christopher Radek 8354a758b9
Add support for converting OpenAPI3 specs to TypeSpec (#3663)
fix #3038
This PR updates the `@typespec/openapi3` package to support converting
OpenAPI3 specs to TypeSpec.

## Example usage:
1. `npm install @typespec/openapi3`
2. `npx openapi3-to-tsp compile --output-dir ./tsp-output
/path/to/openapi-yaml-or-json`

## What's supported
- Parse OpenAPI3 specs in yml/json formats (via 3rd party package)
- Generates file namespace based on OpenAPI3 service name
- Populates `@info` decorator with OpenAPI3 service info
- Converts `#/components/schemas` into TypeSpec models/scalars.
- Converts `#/components/parameters` into TypeSpec models/model
properties as appropriate.
- Generates a response model for every operation/statusCode/contentType
combination.
- Operation tags
- Generates TypeSpec operations with routes/Http Method decorators
- Generates docs/extension decorators
- Most schema decorators
- Model inheritance via `allOf`
- Discriminators

## What's not supported (yet)
- auth
- deprecated directive
- combining multiple versions of an OpenAPI3-defined service into a
single TypeSpec project
- converting `#/components/requestBodies` and `#/components/responses`
into models - TypeSpec doesn't seem to generate these and I didn't find
examples in the wild where they were defined _and_ actually used so
deprioritized.
- emitting warnings/FIXMEs for unexpected/unsupported scenarios
- Probably a lot more that I'm still discovering

## Notes

When going through the TypeSpec -> OpenAPI3 -> TypeSpec loop, the
generated TypeSpec is going to be larger than the original. The biggest
contribution towards this is because I'm currently generating a model
for every possible response on every operation.

I can definitely pare this down with some simple heuristics that take
into account what default statusCode/contentTypes are, and extract the
referenced body type directly in the operation's return signature. I can
also eliminate the `@get` decorators, `@route("/")` routes, and likely
use some of the response models provided by TypeSpec.Http.

However - if I'm using this tool to convert from OpenAPI3 to TypeSpec -
I thought it might be preferable to be more explicit in the generated
output so there's no mystery on how things actually get defined. Will be
interested in feedback on this.


## Testing
For tests, I generate TypeSpec files for a number of OpenAPI3 specs.
Most of the OpenAPI3 specs I generated from our TypeSpec samples
packages. Then I'm able to compare the generated TypeSpec to the
corresponding original TypeSpec file. I've also been diffing the
OpenAPI3 specs generated from the original and generated TypeSpec files
<- these are what typically show no changes outside of known unsupported
conversions (e.g. auth).

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
2024-07-02 22:43:49 +00:00
Timothee Guerin 97d426e373
Apply openapi3 extension on Security schemes (#3732)
fix [#3555](https://github.com/microsoft/typespec/issues/3555)
2024-07-02 19:27:13 +00:00
Timothee Guerin ce10ed9955
Allow overriding base operation verb (#3717)
fix https://github.com/microsoft/typespec/issues/3636

[Playground
example](https://cadlplayground.z22.web.core.windows.net/prs/3717/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwpAc2VydmljZQpuYW1lc3BhY2UgRGVtb1PGFjsKCi8vIFRoaXMgc2hvdWxkIGJlIGFuIGVycm9yCkByb3V0ZSgiMSIpCkBnZXTGBW9wIG9wMSgpOiB2b2lk30LHQjLJQnBvc8dDMstDxBwgb3AgQmFzZTxUPsQaVMZaTm8gd2FybuQA2mhlcmXJUjQiKSDFTcQ3b3ZlcnJpZGUgaXPGQ3N0cmluZz47Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D)
2024-07-01 22:04:26 +00:00
Timothee Guerin f3c2c9b67c
Dependency updates July 2024 (#3718)
Notable: Typescript 5.5
2024-07-01 21:42:11 +00:00
Timothee Guerin 4cfb2c2193
Deprecate getAssetEmitter and recommend calling `createAssetEmitter` directly (#3516)
fix https://github.com/microsoft/typespec/issues/3397

Problem with calling `getAssetEmitter` is it create an asset emitter
with the instance of the compiler used in the compilation and not the
instance of the compiler defined in the type emitter necessarly. This
cause issue with `instanceof` checks which are then not the exact same
class as its loaded form different instance of the compiler
Calling `createAssetEmitter` solve the issue because it is imported in
teh context of the emitter package and will use the emitter package
version
2024-07-01 17:52:12 +00:00
Rodge Fu 224e725e43
Handle errors in tracing for environments that don't support Error.captureStackTrace (i.e. firefox) (#3623)
Error.captureStackTrace is used to get stacktrace for tracing details,
but it's not supported in some browser like firefox, so add handling for
it. thanks.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-06-21 01:01:38 +00:00
Timothee Guerin 216f423a8c
Fix crash in program viewer when trying to display new value type (#3585)
fix https://github.com/Azure/typespec-azure/issues/1016
### Fix crash in the program viewer
When we were trying to display a value(only case right now is using a
default value as property) it would blow up

### Add error boundary to only crash the output view and ability to
retry so the entire UI is not lost

![image](https://github.com/microsoft/typespec/assets/1031227/d856c8c9-41d9-4c86-9c6b-432e60a12d53)
2024-06-14 18:20:30 +00:00
Timothee Guerin 6bbc247570
Fix formatting of object and array literal in decorator (#3577)
Currently formats to 
```
@example(
  #{
    id: "some",
    bar: "thing",
    date: utcDateTime.fromISO("2020-01-01T00:00:00Z"),
    unixDate: unixTimestamp32.fromISO("2020-01-01T00:00:00Z"),
    encodedAsRfc7231: utcDateTime.fromISO("2020-01-01T00:00:00Z"),
    dob: plainDate.fromISO("2020-01-01"),
    timeout: duration.fromISO("PT1M"),
    timeoutInSeconds: duration.fromISO("PT1M1.5S"),
    timeoutInSecondsFloat: duration.fromISO("PT0.5S"),
  }
)
```

woudl get formatted to 

```

@example(#{
    id: "some",
    bar: "thing",
    date: utcDateTime.fromISO("2020-01-01T00:00:00Z"),
    unixDate: unixTimestamp32.fromISO("2020-01-01T00:00:00Z"),
    encodedAsRfc7231: utcDateTime.fromISO("2020-01-01T00:00:00Z"),
    dob: plainDate.fromISO("2020-01-01"),
    timeout: duration.fromISO("PT1M"),
    timeoutInSeconds: duration.fromISO("PT1M1.5S"),
    timeoutInSecondsFloat: duration.fromISO("PT0.5S"),
})
```
2024-06-14 15:13:27 +00:00
Allen Zhang 9c701cc272
TypeSpec 0.57 - June 2024 Release publish branch (#3578)
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-06-13 21:47:55 +00:00
Timothee Guerin 4ed71bf73f
Add release notes for 0.57.0 (#3560)
Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-06-13 15:12:45 +00:00
shiron-dev 147335dfd5
fix error when model property is invalid (#3574)
fix #3504

When unsuitable types are specified in the model property, the invalid
code location is now reported instead of throwing an error.

When compiling the following tsp file, it is reported as follows
```tsp
interface TestInterface1 {
  get1(prop: TestInterface1): TestInterface1;
}
```

```
Diagnostics were reported during compilation:

/projects/typespec/packages/samples/scratch/main.tsp:2:8 - error @typespec/openapi3/invalid-model-property: 'Interface' cannot be specified as a model property.
> 2 |   get1(prop: TestInterface1): TestInterface1;
    |        ^^^^

Found 1 error.
```

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-06-13 15:10:47 +00:00
Rodge Fu e4c4d2b7ca
Add support for completion of extends and is (#3443)
fixes #3152
2024-06-13 02:42:00 +00:00
Timothee Guerin 5bc98d9c9d
Fix: Using a scalar constructor defined in a parent scalar doesn't reference the right scalar (#3573)
```
const a = unixTimestamp.fromISO("...");
```

a would have the scalar utcDateTime not unixTimestamp
2024-06-12 20:58:15 +00:00
Rodge Fu 35e8625014
support loglevel filter in playground (#3569)
support loglevel filter in playground to avoid too many verbose log as
well as user can filter logs as needed.

fixes #3554
2024-06-12 14:54:50 +00:00
Timothee Guerin 1f82d65ea0
Do not run decorators on cloned type if the original type wasn't finished (#3566)
In the same way we have this logic for `cloneTypeForSymbol`
2024-06-11 22:10:35 +00:00
Timothee Guerin ac93dfa318
Fix using js special words as parameters names (#3564)
fix #3563
2024-06-11 21:55:37 +00:00
Will Temple c9fe5a0ce3
[protobuf] Handle cross-package references correctly in some buggy cases. (#3561)
Closes #3534
Closes #3556 

This PR adds cross-package resolution in some cases where it was
missing.

In the case of operation inputs, missing effective model type
calculation was causing some input types not to be resolved to external
packages.

In the case of map value types, the calculation of the right hand side
type did not correctly account for the possibility of the type being in
another package, and it now uses the same machinery as other type
references to instrument imports and cross-package references.

The existing scenario test has been extended to prevent regressions and
also extended to test arrays for good measure, though those were working
as expected.

---------

Co-authored-by: Will Temple <will@wtemple.net>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-06-11 21:25:17 +00:00
Timothee Guerin dd61517865
Format multi line strings (#3422)
fix  #1016

Format multi lines string 

```
@doc(
  """
          multi line
          do
          ${"abc"}
          """
)
@doc("""
def
""")
model Foo {}

alias T = """
          abc
          def ${"abc"}
          ghi
          """;

```

formats to

```
@doc("""
  multi line
  do
  ${"abc"}
  """)
@doc("""
  def
  """)
model Foo {}

alias T = """
  abc
  def ${"abc"}
  ghi
  """;
```
2024-06-11 20:06:12 +00:00
Timothee Guerin 7912e8c9c7
Add support for `@prop` doc comment tag to describe model properties (#3527)
closes https://github.com/microsoft/typespec/issues/2211

[Playground
example](https://cadlplayground.z22.web.core.windows.net/prs/3527/?c=LyoqCiAqIE1vZGVsIGRvY8QNQHByb3AgYSBByg1iIELKDWMgQ8oNZCBECiAqLwptxUJCYXNlIHsKICBhOiBzdHJpbmc7CiAgYsoNCiAgLyoqIEV4cGxpY2l0IHZpYcR3IGNvbW1lbnTESiAgY80wQGRvYygiZcwyxBMiKSBkyih9CgrnAMvoAKRvdmVycmlkZcVfaGVyZesAp0NoaWxk5QCoLi4u5AC0xEE%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)
2024-06-11 19:22:43 +00:00
Timothee Guerin 0cf3a67b25
Fix EINVAL error when running `tsp code install` (#3522)
fix #3513
2024-06-11 18:59:26 +00:00
Timothee Guerin 7a0212bba0
Fix handling of filename for http file (#3538)
fix #3532
2024-06-11 18:59:21 +00:00
Brian Terlson 295e68a698
Add oneOf to JSON Schema (#3557)
Fix #3544.
2024-06-11 17:11:53 +00:00
Reinier Hartog a27ce82741
Allow symbols to be escaped in DocText (#3375)
Related to #3374, this is an implementation of escaping characters in
doc comments, such as the `@` symbol.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-06-11 16:36:48 +00:00
☃ Elliot Shepherd d33090e933
Add PickProperties type and @withPickedProperties decorator (#3488)
Add PickProperties based on OmitProperties

Based on
https://github.com/microsoft/typespec/discussions/3484#discussioncomment-9610555
you may not be wanting more mutating decorators, but PR is here if it's
ok.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-06-11 15:12:23 +00:00
Timothee Guerin dae5e20157
Fix swagger UI missing (#3552)
Recent regression with the new program viewer refactoring
2024-06-10 17:47:53 +00:00
Rodge Fu a81c7fbe68
Enhance logging/trace for vscode extension (#3533) 2024-06-10 15:34:23 +00:00
Timothee Guerin 0f344accd6
Fix some styles in the playground with overflow (#3542)
FIx: 
- Hover popup would get croped 


![image](https://github.com/microsoft/typespec/assets/1031227/a2b975d5-47af-4e4a-b547-f56b8c4e3668)
- tabs overlap

![image](https://github.com/microsoft/typespec/assets/1031227/8919ec99-eb15-4197-a6c2-817f8d29fd17)
2024-06-06 20:18:46 +00:00
Travis Prescott 6ce8837c72
Fix Versioning Regression (#3526)
Fixes #3525.

Companion PR: https://github.com/Azure/azure-rest-api-specs/pull/29349
2024-06-06 16:44:50 +00:00
Timothee Guerin 1d668673c3
Fix playground crashing (#3529)
Issue is that we were returning before the hook declarations when there
was no output files which cause react to crash due to number of hook
running changing
2024-06-06 00:19:37 +00:00
Timothee Guerin 12e26a35fa
Custom output viewer (#3465)
Provide a way to pass a custom program viewer to the playground. This
should enable scnearios like having a `TypeSpec UI` viewer similar to
swagger UI.
Moved the viewer selection to be some vertical tabs with icons to the
right instead

File output viewer
<img width="723" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/e58caee7-8df5-4a9a-be16-9d6fec6701b4">

Type graph viewer

<img width="713" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/8bc2c4a0-42dc-4f91-a9ed-7b52bcad3692">


Also fix issues related to the playground build not validating the
typesript
2024-06-05 22:56:54 +00:00
Timothee Guerin c3913ca975
Do not create all rulesets if there is no rules in linter config (#3521)
This cover the case where you have a package only used to create ruleset
but doesn't have any rules.

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-06-05 19:34:13 +00:00
Timothee Guerin 24f81bf395
Fix application of `@param` on child operations (#3517)
fix #2233
2024-06-04 22:46:58 +00:00
Travis Prescott deedcbb14d
Fix versioning issue when `@added` is used implicitly and explicitly (#3255)
Fixes: https://github.com/microsoft/typespec/issues/3239
2024-06-04 20:43:58 +00:00
Timothee Guerin 5da8fe78d4
Linter `all` rulesets automatically created (#3462)
Provide a built in way for
https://github.com/Azure/typespec-azure/issues/330
2024-06-03 22:12:49 +00:00
Timothee Guerin 40df1ec9a3
Multipart explicit parts (#3342)
resolve #3046
[Playground](https://cadlplayground.z22.web.core.windows.net/prs/3342/)

Add the following:
- `@multipartBody` decorator
- `File` type
- `HttpPart<Type, Options>` type


Had to do a decent amount of refactoring to be able to reuse the body
parsing, this result in a much cleaner resolution of the body and other
metadata properties across request, response and metadata.

The way it works now is instead of calling `gatherMetadata` that would
just get the properties that are metadata but also ones with `@body` and
`@bodyRoot` we now call a `resolveHtpProperties`, this does the same
resolution in term of filtering properties but it also figure out what
is the kind of property in the concept of http(header, query, body,
etc.) this leaves the error resolution to this function for duplicate
annotations.
What is nice is now we don't need to keep asking oh is this a query or a
header or a body we can just check the kind of `HttpProperty`

also resolve #1311
2024-06-03 22:04:33 +00:00
もっちー 26e44b2c96
doc: fix incorrect example of `@statusCode` (#3230)
## Issue Description
There is a example of `TypeSpec.http.@statusCode`
[here](https://typespec.io/docs/next/libraries/http/reference/decorators#@TypeSpec.Http.statusCode).
However, the property name is missing in this example. Due to this, the
code did not work as expected.

```
op read(): {@statusCode: 200, @body pet: Pet}
op create(): {@statusCode: 201 | 202}
```

Instead, specifying the property name as follows made it work correctly:

```
op read(): {
  @statusCode _: 200;
  @body pet: Widget;
};
op create(): {
  @statusCode _: 201 | 202;
};
```

## Fix Description
- Corrected examples of `TypeSpec.http.@statusCode` in the reference and
documentation.

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-06-03 21:14:48 +00:00
Rodge Fu ce4b9c4495
support Arm processor for vs extension (#3461)
fixes #3279
2024-06-03 20:54:39 +00:00
Rodge Fu de45043c84
Hide deprecated items from completion list (#3460)
fixes #3305
2024-05-29 02:46:57 +00:00
Brian Terlson e78ba68782
Circular reference fixes (#3451)
fix #3447 
Fixed a few issues with circular references in the JSON Schema emitter
and emitter framework:

* The emitter framework wouldn't restore context correctly when directly
emitting a type reference to a type with a circular reference.
* The JSON Schema emitter did not handle circular references involving
non-JSON Schema types.
* The JSON Schema emitter would create an infinite loop when circular
references needed to be put into $defs.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-05-28 17:28:31 +00:00
Timothee Guerin 42e72b813d
Add storybook for playground library (#3412)
Don't include it anwhere but this will help showcasing all the
components available in the playground.


![image](https://github.com/microsoft/typespec/assets/1031227/8a7e130f-2e3f-4149-9f33-ed8991950ea2)
2024-05-24 02:37:11 +00:00
Brian Terlson 9a109906a0
Fix bundling and inlining of referenced schemas (#3430)
Fixes #3369 by changing how types are bundled. In particular, when a
type is not a JSON Schema type, we never create a root schema for it.
Instead, it is inlined into the defs of any schema which references it,
and referenced using a JSON pointer. This PR makes bundling have
essentially no impact on emitted schemas, and is merely a way to bundle
them into a single file.

The approach is as follows:

* When a type references another type outside a JSON Schema namespace,
include the referenced type under $defs:
   * Such referenced types do not have a $id or $schema field
   * Such referenced types are referenced via JSON pointers not ids
* Bundling does not alter the bundled schemas or introduce new root
schemas. This changes two things from what we do today:
* The `$id` of the bundled schemas now includes the file path as it does
for non-bundled schemas (whereas before it was just the type name)
* non-JSON Schema types do not get $defs in the bundle, so the bundle
has the same root schemas as would be written to disk when not bundling.
  
In terms of implementation, the basic approach is to not handle bundling
via the emitter framework source files. Instead, we always create source
files for root schemas, and inline the necessary defs as we did before
(but now using JSON pointers). Then when we're about to write source
files, if we're bundling we assemble the bundle and emit that single
file, otherwise we emit each source file that contains a root schema.

Todo: 

* [ ] Validate that the bundled schemas continue to work with ajv.
* [ ] Cleanups

---------

Co-authored-by: Vitalii Kryvenko <gersoh3@gmail.com>
2024-05-24 00:49:43 +00:00
Timothee Guerin 0a70aa7f61
Organize versioning library (#3309)
Versioning library is a big mess of things all into one file, this makes
it hard to contribute. Did this originally because I was going to deal
with multiple madeRequired and madeOptional over time but that will be
done later but finished the cleanup anyway.

Split the versioning.ts into multiple separate logical files:
- `decorators.ts`: Contains all the versioning decorators and accessor
- `internal-projection-functions.ts`: Contains implementation of the
helper function used inside the versioning projection(not meant for
external use)
- `projection.ts`: Contains the projection building functions
- `versioning.ts`: Contains the various versioning computation
function(timeline, etc.)


This makes it clearer of what is supposed to be public apis vs internal,
waht is just mean for decorator, projection, etc.
2024-05-23 22:43:36 +00:00
Travis Prescott a6bcade296
Fix issue with `@removed` decorator if model was not added from beginning (#3409)
Fixes #3210

While the issue was for model properties, it also applies to interfaces,
so tests are included for both.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-05-21 18:07:03 +00:00
Timothee Guerin 71784e2bc2
Simplify to use vite for building playground library (#3403)
Using rollup wasn't working super well when running in watch mode with
the playground-website package refresh and needed some restart.

Unfortunatelly can't seem to find a good way to just run `pnpm start` in
`/playground-website` and have that working so still have to do `pnpm
watch` in `/playground` as well.
2024-05-20 22:07:51 +00:00
Vitalii Kryvenko ccd67cf071
Fix handling decorators for union variants in JSONSchema emitter (#3398)
Fixes #3391

Also refactored a minor problem of using a deprecated reexport of
`DuplicateTracker`, not it's referenced from `@typespec/compiler/utils`
directly, and another small typo.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-05-20 19:57:40 +00:00
Vitalii Kryvenko d14b0d7b63
Preserve leading whitespace in fenced blocks in doc comments (#3399)
Fixes #3370.

This also updates the generated documentation and typescript code to fix
lack of indentation on existing fenced blocks in this repo.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-05-20 19:57:31 +00:00
Timothee Guerin e316792dcd
Update dependencies - May 2024 (#3401) 2024-05-20 16:31:39 +00:00
Timothee Guerin 46d50af478
Fix vitest not reloading JS files (#3395)
Seems like we also need a `vitest.config.ts` at the root of the
workspace to override the `watchExclude` setting otherwise `dist` and
`node_modules` are still excluded and everytime require a refresh of the
vitest UI or restarting the watch. Only thing that was working is if you
modified the test files or modified imported files directly from the
test
2024-05-17 21:53:01 +00:00
Rodge Fu 7223624826
Add 'show output channel' command in vscode extension (#3385)
fixes issue #3228
2024-05-17 16:20:30 +00:00
Rodge Fu b7f6948fd3
improve completion and onhover in VSCode for decorator and extended model (#3280)
add following feature
1. support completion when user typing model expression as decorator
argument value
2. support completion for extended model
3. support showing decorator model argument prop information when
hovering on model expression as decorator argument value

closes #3130, closes #2228, closes #1956

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-05-17 07:17:59 +00:00
Timothee Guerin 8424b2e76b
Fix alias cannot be used to pass indeterminate entities (#3377)
fix #3376
2024-05-16 22:02:47 +00:00
Timothee Guerin aa91dcdc63
Numeric not handling trailing zeros (#3371)
```tsp
const a = 100.0
```

was getting into an infinite loop
2024-05-16 16:55:57 +00:00
Timothee Guerin 6277f993d4
Missing `Discriminator` interface export in compiler (#3316) 2024-05-10 15:35:10 +00:00
Timothee Guerin 8c44c3a89d
Remove all circular references in TypeSpec Compiler (#3308)
They cause vitest to not be happy randomly. This is only a problem with
non type import so adding `type` helps finding which ones are a real
problem

Use madge with this command to find them
```
npx madge --circular --extensions ts ./src/
```

with this config
```
{
  "detectiveOptions": {
    "ts": {
      "skipTypeImports": true,
      "skipAsyncImports": true
    }
  }
}
```
2024-05-09 22:56:46 +00:00
Jim Borden bdb3f24bff
Add madeRequired decorator and tests (#3292)
Hopefully I got all the places I needed to get and added enough tests.
My methodology was pretty much "Look at what madeOptional does, and do
the opposite"

Closes #2731

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-05-09 21:45:43 +00:00
Timothee Guerin 7ec17161b7
Value world, object, tuple literals, const (#3022)
resolves #2046
[Playround](https://cadlplayground.z22.web.core.windows.net/prs/3022/)

Add the new syntax for object literals using `#{`. For this first
version an object literal can only contain other object literal and
other literals(string, number, boolean))

## Values axioms
1. `alias` always produces a type. If you attempt to alias a value, you
get an error.
2. A string template produces a string template type if all
substitutions are types, and a value if all substitutions are numeric,
boolean, or string values. A mixture of types and values is an error.
3. The string literal syntax always results in a string literal type
4. A string literal type may be passed as a string value when the
signature expects a value. When the signature expects either a string
literal type or a string value, it is passed as a string value.
5. A string template type can be passed as a string value when all its
substitutions are string literal types.

## Breaking change

### Removal of the `ValueType` replacement with `MixedConstraint`

This shouldn't affect anyone as you were only exposed to this if you
digged into the template parameter and looked at the constraint

## Deprecation

## Using a tuple instead of a tuple literal
-  still work
- emit a warning
<img width="1013" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/ab05359a-5ed9-4a27-a8d1-f40d1e21766f">

- provide a codefix
<img width="312" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/5ef93bdf-665f-4445-a6b2-62475efe8c16">

## Using a model expression instead of an object literal
This technically didn't work before(different from above where tuple was
used as a value) but allow this will allow us to convert most of our
decorators to use `valueof` without being breaking
![Kapture 2024-03-18 at 19 31
32](https://github.com/microsoft/typespec/assets/1031227/f6d69ab4-139e-4b01-95a3-f376b8515d1c)

## Old decorator marshalling

If a library had a decorator with `valueof` one of those types
`numeric`, `int64`, `uint64`, `integer`, `float`, `decimal`,
`decimal128`, `null` it used to marshall those as JS `number` and
`NullType` for `null`. With the introduction of values we have a new
marshalling logic which will marshall those numeric types as `Numeric`
and the others will remain numbers. `null` will also get marshalled as
`null`.

For now this is an opt-in behavior with a warning on decorators not
opt-in having a parameter with a constraint from the list above.

Example: 
```
extern dec multipleOf(target: numeric | Reflection.ModelProperty, value: valueof numeric);
```
Will now emit a deprecated warning because `value` is of type `valueof
string` which would marshall to `Numeric` under the new logic but as
`number` previously.

To opt-in you can add the following to your library 
```ts
export const $flags = defineModuleFlags({
  decoratorArgMarshalling: "value",
});
```

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-05-08 20:06:28 +00:00
Timothee Guerin dec504364c
Bump versions for 0.56.0 release (#3298) 2024-05-08 00:34:05 +00:00
Timothee Guerin 21edcb8f76
Add release notes for 0.56.0 (#3294)
Fixed up cspell not validating `.chronus` and causing some typo in
release notes

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-05-07 21:02:14 +00:00
Timothee Guerin 4b3489f859
Optional props cannot be assigned to required ones (#3290)
fix #3267

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-05-06 22:07:27 +00:00
Timothee Guerin d8c26b1580
Templated interface extending another templated interface shouldn't run decorator on their operations (#3287)
fix #3286
2024-05-06 20:48:00 +00:00
Timothee Guerin fef1c39712
Fix crash versioning sub namespace service (#3264)
fix #3263
2024-05-03 16:45:25 +00:00
Timothee Guerin cb6fea49d7
Split libraries from emitters (#3258)
Makes it easier to discover our emitters

also cleanup a reference to non existent json-rpc emitter
2024-05-02 16:54:35 +00:00
Timothee Guerin 5757fd16e4
Include `type` in generated extern dec (#3250)
This allows us to use `verbatimModuleSyntax: true`
2024-04-29 20:23:34 +00:00
Timothee Guerin 32a25ecb94
Fix stop running decorators on partially instantiated operations (#3227)
fix [#2619](https://github.com/microsoft/typespec/issues/2619)
2024-04-26 21:46:15 +00:00
Timothee Guerin 0a83800065
Use node built-in fetch (#3246)
Node `fetch` built-in function is now out of experimental since node
`18.13.0` this allows us to not have some partial implementation and get
rid of an external dependency
2024-04-26 18:07:22 +00:00
LadyCailin 713e22d0a9
Add shell: true to TSP install command. (#3243)
This is a breakage due to a breaking change in node's latest incremental
version. (See https://github.com/nodejs/node/issues/52554 for
background). Adding shell: true fixes this.

Fixes #3242.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-04-26 17:15:14 +00:00
Timothee Guerin df4dac296d
Blog redo with fixes (#3236)
- old date
- merge conflict that drop `diff` support
- non needed export
- broken playground class
2024-04-26 14:37:48 +00:00
Allen Zhang 629987c81b
Allow test library include recursed folder for tsp files (#3232) 2024-04-24 20:49:22 +00:00
Timothee Guerin 07b340a6dc
Fix: `@path` property should be included in unreachable models (#3218)
fix #3217
2024-04-23 23:02:04 +00:00
Timothee Guerin fe51f05297
Recover from bad op is reference in template (#3216)
fix #3199
2024-04-23 22:59:43 +00:00
Timothee Guerin e09af82db6
Fix: augmenting template property didn't resolve declaration (#3212)
fix #3211
Problem was we were checking the decorator declaration passing the
`mapper` this mean the checker was thinking we were defining this
decorator declaration in a template instance(which is not possible)
This resulted in the argument marshaling to not happen as it will only
happen when there is a valueof constraint
2024-04-23 17:18:37 +00:00
Timothee Guerin 36c339b432
Fix tsp init hanging when done due to unclosed connection (#3185)
fix [#3102](https://github.com/microsoft/typespec/issues/3102)

Problem was that when following redirect we need to explicitly close the
response watch otherwise we always await on it

However I switched to using `follow-redirects` library that will more
safely handle redirect for us.(e.g. max redirects)
With node 22 the fetch api should not be experimental anymore so we
could potentially migrate to it next year when node 20 is out of support
2024-04-23 17:04:16 +00:00
Timothee Guerin eb1185103d
Fix: Do not crash when trying to access member of aliased expression (#3188) 2024-04-23 01:50:06 +00:00
Timothee Guerin b7e45f008f
Fix `@path` param mapping when spreading a record in operation parameters (#3190)
fix #3051
2024-04-23 01:48:07 +00:00
Timothee Guerin 5fa3d78729
Add new `sourceModels` property to model (#3191)
resolves [#2818](https://github.com/microsoft/typespec/issues/2818)

Add a new `sourceModels` property that keeps track of models used to
construct it. `sourceModels` is an array of a new `SoruceModel` object
which contains metadata on how the model was used:
- is: `model A is B`
- spread: `model A {...B}`
- intersection: `alias A = B & C`
2024-04-23 01:47:41 +00:00
Timothee Guerin 1987a56220
Fix password flow (#3196)
fix [#3137](https://github.com/microsoft/typespec/issues/3137)
2024-04-23 00:53:04 +00:00
Timothee Guerin fa540a97ba
Split intrinsic from std lib (#3170)
fix https://github.com/microsoft/typespec/issues/3171
Currently the `--nostdlib` option is just useless, here splitting the
intrinsic types from the rest of the std lib.

Intrinsic types will always be loaded regardless of what `nostdlib`
says.


Being able to disable that can be useful in the compiler test to not be
polluted by some extra elements.
2024-04-18 20:51:52 +00:00
Rodge Fu 9fcc90facb
Include template arguments for operation in intellisense (#3183)
fix https://github.com/microsoft/typespec/issues/2423 

Include template arguments for operation in intellisense

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-04-18 09:27:14 -07:00
Timothee Guerin 1265330298
Update to Body consistency in http request (#2945)
fix [#2868](https://github.com/microsoft/typespec/issues/2868)

- Change meaning of `@body` to mean this is the body and nothing will be
excluded(show warning on containing metadata)
- Add new `@bodyRoot` which has the same purpose as the old `@body`(
Allows changing where the body is resolved from but allows mixing with
metadata.
- Add new `@bodyIgnore` which allows a property to be ignored from the
body
- Provide a new body resolution common function for request and response

also fix #2075
## Examples from original issue

1. [Inconsitency between request and
response](https://cadlplayground.z22.web.core.windows.net/prs/2945/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwoKLyoqCiAqIEJhc2VsaW5lIDE6IEhhdsQqYEBoZWFkZXJgIHByb3BlcnR5IG9ubHkgaW4gcmVxdWVzdMYLc3BvbnNlxAl1bMUTbm8gYm9kecRXUscpxBA6IHZvaWTGFnPFM80WLwpAcm91dGUoIi9i5wCNIikKQGdldCBvcCDIEygg5wCWIGN1c3RvbUjFDTogc3RyaW5nKToge90hIH0g6gD0Q2Fz5QDwQWRkxBtgQHZpc2liaWxpdHlgIHRv9AEBYmVoYXZlIGRpZmZlcmVudGx5IGZvcukBEGFuZOkBES7yAQB7ff8A%2FuUA%2FmNhc2UxIikKb3AgxQso6wCYKCJub%2BQBGOkA5XjuAPvfKsUqIH3vAQMy%2BgEDbm9uIGFubm90YXRlZOoBB%2BoB7GVtcOQBF%2FUB7%2FQA78UU7wDtMuoA7TL1AO3%2FAOXMIuUA3Q%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)
2. [Inconsitency between different
ways](https://cadlplayground.z22.web.core.windows.net/prs/2945/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZdmVyc2lvbmluZyI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwO9AVVskyOwoKQHNlcnZpY2UKQMdJZWQoxyFzKQpuYW1lc3BhY2UgTXlTxik7CmVudW0gyCQgewogIHYxLMQGMiwKfQoKQHJvdXRlKCJ0MSIpIG9wIHQxKCk6IHZvaWQ7IC8vIDIwNMUNyigyxygyxCh7fccmMM8mM8cmM8UmQGhlYWRlciBmb286IHN0cmluZ9g5NMc5NMY5dmlzaWJpbGl0eSgiZ2F0ZXdheSIp30jFSDXHSDXcSP8AmMxQNsdQNsVQ1THGFiJhYmMifco5N8c5N8U5QGFkZOsBtC52MvMAzsR6IGluIHYxykc4x0c430fFRyzpANpvdGhlcthe&e=%40typespec%2Fopenapi3&options=%7B%7D)

## Breaking changes 
Azure spec PR showing scale of breaking changes
https://github.com/Azure/azure-rest-api-specs/pull/27897
### `@body` means this is the body
This change makes it that using `@body` will mean exactly this is the
body and everything underneath will be included, including metadata
properties. It will log a warning explaining that.

```tsp
op a1(): {@body _: {@header foo: string, other: string} };
                ^ warning header in a body, it will not be included as a header.
```

Solution use `@bodyRoot` as the goal is only to change where to resolve
the body from.

```tsp
op a1(): {@bodyRoot _: {@header foo: string, other: string} };
```




### Empty model after removing metadata and visibility property result
in void always
This means the following case have changed from returning `{}` to no
body

```tsp
op b1(): {};
op b2(): {@visibility("none") prop: string};
op b3(): {@added(Versions.v2) prop: string};
```

Workaround: Use explicit `@body`

```tsp
op b1(): {@body _: {}};
op b2(): {@body _: {@visibility("none") prop: string}};
op b3(): {@body _: {@added(Versions.v2) prop: string}};
```

### Status code always 200 except if response is explicitly `void`

```tsp
op c1(): {@header foo: string}; // status code 200 (used to be 204)
```

Solution: Add explicit `@statusCode`
```tsp
op c1(): {@header foo: string, @statusCode _: 204};
op c1(): {@header foo: string, ...NoContent}; // or spread common model
```


### Properties are not automatically omitted if everything was removed
from metadata or visibility

```tsp
op d1(): {headers: {@header foo: string}}; // body will be {headers: {}}
```

Solution: use `@bodyIgnore`

```tsp
op d1(): {@bodyIgnore headers: {@header foo: string}}; // body will be {headers: {}}
```

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-04-17 11:20:25 -07:00
Travis Prescott fec999099e
Fix directive parsing on namespaces (#3180)
Fixes #3165.

Ensures that decorators and directives are attached the leaf node on
Namespace chains.
2024-04-16 12:42:17 -07:00
Timothee Guerin f007e642b7
Fix parser test running 1-4 times (#3168)
The `dumpAst` helper was imported from `parser.test.ts` in 3 other files
which caused vitest to randomly run the parser.test.ts tests(371 tests)
extra times. It wasn't consitent which is how I caught it the number of
test passed by vitest changed significantly from one run to the other
2024-04-15 15:14:53 -07:00
Timothee Guerin 117712147b
Fix xml version (#3177)
Should be 0.55.0 to match other packages
2024-04-15 15:14:46 -07:00
Timothee Guerin d290c17b5e
Update dependencies - april 2024 (#3169)
Notable: 
- vitest `1.5.0` which solves some issues with running in the extension
- remove `sinon` from compiler which is not needed anymore as vitest
provide spies built-in
2024-04-15 10:24:38 -07:00
Timothee Guerin b4caac6425
Fix completion of keywords (#3151) 2024-04-12 23:55:59 +00:00
Timothee Guerin f30120d3a5
Fix: Model with spread indexer shouldn't validate explicit properites (#3163)
This was causing errors in doing things like this 

```ts
model Info {
  age: int32;
  ...Record<string>;
}

model Bar<T extends Info> {}

model Test {
  t: Bar<{
    age: 123;
    other: "abc";
  }>;
}

```
2024-04-12 19:01:34 +00:00
Timothee Guerin 7bbe89cb17
Fix numeric comparison between integer with trailing 0 (#3160)
`32123 < 34000` wasn't actually returning true
2024-04-11 21:18:38 -07:00
Timothee Guerin 3c3bfdba5a
Fix compare of negative numbers in `Numeric` type (#3154)
I didn't invert the comparison when comparing 2 negative numeric.
2024-04-11 16:32:27 +00:00
Timothee Guerin 6b3bd9a8f1
Feature: Add Xml library (#3035)
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>
2024-04-09 15:33:46 -07:00
Timothee Guerin aa95fcbad3
Add numeric data structure (#3115)
Adding new `Numeric` data structure for the value world.

This PR doesn't export it so it won't be usable just yet but this
sparate this quite complex entity from the rest of the value world PR
2024-04-09 16:38:16 +00:00
Timothee Guerin df7b8ae8ff
Missed eslint config dependency removal (#3135)
Forgot to remove those references. Eslint is run from the root now
2024-04-08 18:18:06 -07:00
Timothee Guerin 35f5c90343
Migrate to eslint flat config (#3123)
resolve https://github.com/microsoft/typespec/issues/3121
same change in typespec-azure
https://github.com/Azure/typespec-azure/pull/620

## Single top level config
This makes it a little nicer to run as you know get the absolute path
for errors
No need to have the hacky rushstack dependency to allow using the same
shared config.

## Able to lint the projects that are outside of the pnpm workspace
<img width="1054" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/f88691d9-1bf2-4140-ba2b-533207b15f9d">


## Eslint 9 -no yet

eslint 9 was just released firday which makes this config the new
default however it does include breaking changes and not all our plugins
have updated
2024-04-08 09:58:19 -07:00
Timothee Guerin 6cae42529c
Fix playground wrong copy (#3126) 2024-04-06 00:24:04 +00:00
Timothee Guerin 51b2e57ac7
Pass compiler options for samples (#3124) 2024-04-05 15:00:39 -07:00
m-nash 0889ba248c
Initial move of csharp client emitter (#3098)
Fixes https://github.com/microsoft/typespec/issues/3095

---------

Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Patrick Hallisey <hallipr@gmail.com>
2024-04-04 16:26:05 -07:00
Timothee Guerin 0c1b96be47
Ci improvements (#3099)
- Use corepack to install pnpm: Faster and respect the pnpm version set
in package.json instead of having another place to keep up to date
- dependency cache
- upgrade to new code coverage task
- Move all consitency check to independent github action workflow(Makes
it easier to see which one failed immediately without having to open
devops and dig into the steps)
2024-04-03 16:19:59 -07:00
Timothee Guerin c0b1f9891d
Fix shouldn't have eslint-plugin-prettier (#3100)
Plugin wasn't used and what we have is `eslint-config-prettier` that
disable the formatting rules to delegate to prettier
2024-04-03 15:48:01 -07:00
Timothee Guerin 2f53533d94
Bump versions for release 0.55.0 - april 2024 (#3096) 2024-04-02 14:55:47 -07:00
Timothee Guerin 63cb176500
Deprecate known values (#3094)
fix #3009

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-04-02 19:37:27 +00:00
Timothee Guerin 29aa4a5ec4
Add release notes release 0.55 - April 2024 (#3093)
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-04-02 19:13:46 +00:00
Timothee Guerin d4823c089b
Fix swagger ui build (#3091)
Missed that when doing the PR, the default import tries to load the
`path` library, recommendation is just to import the right bundle
directly.
2024-04-02 09:33:15 -07:00
Timothee Guerin c6506bcdee
Fix: Literal unions with the same variants keep adding duplicate entries (#3090)
fix #3087
2024-04-02 01:21:29 +00:00
Timothee Guerin cda7ccf4d9
Playground: Migrate from swagger-ui-react to swagger-ui-dist (#3089)
swagger-ui-react pull in all the swagger ui dependencies which is a bit
anyoing as they are mostly optional and with pnpm requires you to build
native dependencies.
2024-04-01 17:13:08 -07:00
Timothee Guerin 5ba95d0371
Allow reload of js files in vitest (#3086)
Setup a workaround for the fact that vitest(vite underneath) doesn't
ever want to reload files in the outDir
https://github.com/vitest-dev/vitest/issues/5429

as the outDir isn't actually used in vitest(as far as I understand) this
is just an ok workaround.
2024-04-01 17:54:38 +00:00
Timothee Guerin 0dea649cd7
Update dependencies to resolve vulnerabilities and license issue (#3081)
- Remove unused rollup-plugin-dts dep that had problematic license
- Update dependencies to fix vulnerabilies
2024-03-29 21:22:06 +00:00
Timothee Guerin 6d54aeb4aa
Do not crash if hitting a unsupported intrinsic type (#3077)
fix #3073

This still doesn't provide an optimal experience as the error shows up
on the void type instead of where it is referenced but solving that is
that long standing issue about tracing back where an error should be
2024-03-28 20:29:33 +00:00
Timothee Guerin 85fa7aecec
Union template declaration were being finished in projector (#3052)
fix [#2946](https://github.com/microsoft/typespec/issues/2946)

Problem was that in the projector were were calling to this helper to
see if that was a type that we should finish but it was missing the
union case causing union template declaration from being finished in the
projector and then being shown as finished type in the semantic
navigator and crashing openapi3 emitter.
2024-03-28 20:08:30 +00:00
Timothee Guerin ce9c567e5b
Improve TM language for enums, unions and escaped identifiers (#3069)
resolves https://github.com/microsoft/typespec/issues/3070
The tm language wasn't correctly defining the syntax for escaped
identifiers

```
`North West`
```


Enums and unions syntax was also not very accurate and didn't tokenize
everything correctly


## Example of issue before


![image](https://github.com/microsoft/typespec/assets/1031227/ee60f4fe-5eef-4f86-baa5-1cc96b665526)

## After

![image](https://github.com/microsoft/typespec/assets/1031227/38405f18-0fa4-44ba-82f6-594bcd4fcebf)
2024-03-27 10:12:29 -07:00
Timothee Guerin 32e45d4da2
Add support for scalar in versioning (#3053)
fix [#3001](https://github.com/microsoft/typespec/issues/3001)
2024-03-26 23:43:37 +00:00
Timothee Guerin 4c34e78747
Fix visibility conflict with base models (#3049)
fix #2922
fix #3048(dup)
2024-03-25 18:56:55 +00:00
Timothee Guerin 095c7dd8d4
OpenAPI3: Fix multipart union part conflict (#3050)
Problem is that was now trying to create a new declaration for a named
union if it was used in multipart and json even though they were the
same
2024-03-25 18:13:26 +00:00
Timothee Guerin 39ee11bc46
Fix: OpenAPI3 not marking part of bytes or something else as `format: binary` (#3013)
fix [#2924](https://github.com/microsoft/typespec/issues/2924)

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-03-22 20:45:10 +00:00
Timothee Guerin 72bed4daf8
More reliable codefix application (#3041)
Current approach was getting in all kind of conflict because it was
calling getCodeActions too much and we were clearing the cached id
2024-03-22 17:44:47 +00:00
Timothee Guerin 4e6f137c65
Emit `{nulable: true}` when trying to emit `null` in openapi3 (#2967)
fix #2217

This isn't fully accurate as it is saying in openapi3 that it can be
anything and `null` but this solve a crash, we could consider adding a
warning

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-03-22 16:53:54 +00:00
Timothee Guerin 8839ae173f
Fix policy include private package that doesn't get versioned (#2990) 2024-03-22 04:16:00 +00:00
Timothee Guerin e0dfe6f5d0
Grammar: Fix comments in template params not tokenized (#3018)
fix #3017

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-03-22 02:53:07 +00:00
Timothee Guerin 077db13c8d
Generate TypeScript decorator signatures from `extern dec` (#2122)
Note this is added to `tspd` which is not published yet so this can be
iterated over without any issues.

Adds a decorator signature generator. Generates 2 files:
- `<namespace>.ts` : Contains the decorator signatures that can be
imported and when declaring the decorators functions
- `<namespace>.ts-test.ts`: Contains some test using typescript type
system to make sure the package does reexport the right `$<name>` for
each decorator

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-03-19 23:08:59 +00:00
Timothee Guerin 743c4b0a39
Fix another set of accessibility issues (#3031) 2024-03-19 18:57:02 +00:00
Timothee Guerin 4199f83575
Upgrade dependencies march 2024 (#3027)
General update of all dependencies, notable
- typescript 5.4
- vitest 1.4
2024-03-18 10:52:06 -07:00
Timothee Guerin 6d42ca6e65
Deprecate projected name (#2910)
fix [#2832](https://github.com/microsoft/typespec/issues/2832)
2024-03-13 12:48:07 -07:00
Timothee Guerin 00996bbe30
Don't prevent going to next stage when a warning is elevated to an error (#2983)
fix #2972
2024-03-12 22:14:42 +00:00
Timothee Guerin 128a508c25
Allow encode on a union (#2992)
fix [#2969](https://github.com/microsoft/typespec/issues/2969)
2024-03-12 14:49:17 -07:00
Timothee Guerin d8576effd5
Website & Docs Cleanup (#3002)
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>
2024-03-11 18:56:35 -07:00
Timothee Guerin 6d5fb9c047
Bump chronus github with fix to not crash on existing release (#2995) 2024-03-06 19:48:53 +00:00
Timothee Guerin 7312314bcb
Remove old message burried in changelog (#2989) 2024-03-05 16:05:57 -08:00
Timothee Guerin 9881002f1c
Bump versions for release march 2024 (#2988) 2024-03-05 15:31:47 -08:00
iscai-msft 4cafd969de
Add json schema test library (#2987) 2024-03-05 22:14:58 +00:00
Timothee Guerin d5380fb8e1
Add release notes for march 2024 release (#2986) 2024-03-05 13:36:38 -08:00
Timothee Guerin 6a9c62ad24
Feature: Code fixes (#2888)
closes #615

## Code fixes added

### Suppress
![Kapture 2024-02-05 at 15 16
22](https://github.com/microsoft/typespec/assets/1031227/644014a3-9352-4bd4-b1b8-0d314c627405)

### `number` -> `float64` typo fix

![Kapture 2024-02-06 at 09 50
28](https://github.com/microsoft/typespec/assets/1031227/65b2e9aa-c510-440f-a1c6-7851611b65a2)

### Enum to extensible enum in typespec-azure

https://github.com/Azure/typespec-azure/pull/258

---------

Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
2024-03-05 11:51:21 -08:00
Timothee Guerin abba29c173
Validate playground samples and fix docs to deprecated version (#2977)
fix #1560

Json schema emitter also didn't respect the `noEmit` flag
2024-03-04 23:35:17 +00:00
Timothee Guerin de6bd7bc30
Go to import (#2978)
fix #1294
![Kapture 2024-03-01 at 14 41
07](https://github.com/microsoft/typespec/assets/1031227/8be68f83-4eca-421c-b6dd-27bc1eed141f)
2024-03-04 15:15:19 -08:00
Timothee Guerin 82fab0a5e6
Fix: Authentication on containing namespace (#2980)
fix #2979

Authentication wasn't resolving values set on the namespaces.
2024-03-04 10:55:35 -08:00
Timothee Guerin 01ba99b061
Fix dup doc (#2976)
Before
<img width="465" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/b620cac2-b70a-4a99-a784-bf03d55bd28b">

Now
<img width="413" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/d2a0b293-7924-44e7-9e1c-036ff40f1b6d">
2024-03-01 20:50:11 +00:00
Timothee Guerin 8c7c76bf8e
`isErrorModel` check for base models (#2968)
fix #2957
2024-03-01 01:59:52 +00:00
Timothee Guerin fa8b959491
Feature: Spread `Record<T>` (#2920)
fix  #2785
2024-02-29 16:47:23 -08:00
Timothee Guerin 9654dd836b
[OpenAPI3 Emitter] Add option to map `safeint` to `double-int` (#2933)
fix  #2367 
Format was added to the schema registry so we are safe to use that now
https://spec.openapis.org/registry/format/double-int.html

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-02-29 16:05:41 -08:00
Timothee Guerin 02ed01e79b
Improved ref docs for model (#2951)
fix https://github.com/Azure/typespec-azure-pr/issues/3861
fix #2232
Generate docs for model properties and reference models within the same
package
<img width="1213" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/ae7eccd0-97d8-401e-b07f-3375c7b41446">
2024-02-29 07:21:13 -08:00
Timothee Guerin 717af6421f
Deprecate `@service` version and allow `@OpenAPI.info` to take all properties allowed by openapi (#2902)
fix [#2821](https://github.com/microsoft/typespec/issues/2821)

## Deprecate `@service({version`

Using this property will emit a deprecation warning

## Cover everything with `@OpenAPI.info`

Makes sure all the properties allowed on the `info` object of openapi
specification can also be provided in `@info`. The properties will
either override other ways of specifying those previously or be the only
way.
- `@info({description` would override `@doc` on service namespace
- `@info({summary` would override `@summary` on service namespace
- `@info({title` would override `@service({title}` on service namespace
2024-02-28 22:56:09 +00:00
Timothee Guerin 9d8cfb016e
Fix don't emit shared route error when verb don't match (#2948)
fix [#2925](https://github.com/microsoft/typespec/issues/2925)

Stop emitting the error if there is a shared route and a non shared
route on a different verb.

Also improve the error: 
- change message to be a little more clear
- emit the error on every offending operation not just the first one we
find an duplicate

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-02-28 22:17:46 +00:00
Timothee Guerin c9c1f3e442
Validate `@useAuth` is unique on node (#2958)
fix #2787 

having multiple has no effect, the latest value will override the
previous ones so there is no reason to use `@useAuth` twice on the same
node

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-02-28 21:52:19 +00:00
Timothee Guerin f884772255
Fix: File with only comment and one on the first line reorder comments (#2955)
fix #2508
2024-02-28 21:24:07 +00:00
Timothee Guerin 8b062e33bb
Update http authentication docs with new operation level auth and scopes (#2960)
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>
2024-02-28 19:40:28 +00:00
Timothee Guerin 628517e0c2
Remove prettier2.0 support in prettier plugin (#2956)
fix #2760 
`@typespec/prettier-plugin-typespec` dropped support for prettier 2.0.
Update to 3.0 to use the new version of the plugin.
2024-02-28 11:17:30 -08:00
Timothee Guerin 66c2df18e2
Do not run decorators that have missing args (#2959)
fix [#3940](https://github.com/Azure/typespec-azure-pr/issues/3940)
2024-02-27 11:04:00 -08:00
Vasil Markoukin d2d397cb67
Operation level authentication and scopes (#2901)
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>
2024-02-27 07:39:30 -08:00
Brian Terlson aa6e53f4ab
Add `getOpenAPI3` to OpenAPI3 emitter (#2950)
This function is useful when you want to work with the OpenAPI 3
directly, or don't want to write it to disk for some reason.

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
2024-02-26 22:44:26 +00:00
Timothee Guerin 15702e82f4
Move compiler utils to `/utils` exports (#2919)
Provide a new exports `/utils` where we can export utils that are
commonly used in libraries and emitters but not tied to typespec
directly(deepClone, deepEquals, etc.)
2024-02-23 17:48:19 +00:00
Timothee Guerin 753ca1ad9b
Improvement to the import auto complete (#2936)
- fix #2481 Autocomplete directive names
- Stop crashing when completing invalid dir
- Autocompleting dir with non letter char (e.g. `-`) will autocomplete
correctly
- Playground autocomplete imports
<img width="579" alt="image"
src="https://github.com/microsoft/typespec/assets/1031227/08e9e516-6472-4ab2-b3a5-30b4a8ce722d">
2024-02-20 13:49:56 -08:00
Ikko Eltociear Ashimine b4b0bbbc9d
Update file-templating.ts (#2847)
langauges -> languages

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Allen Zhang <allenzhang@live.com>
2024-02-20 21:01:01 +00:00
Timothee Guerin 09aae4cbd1
Report error when having a circular template constraint (#2932)
fix [#2788](https://github.com/microsoft/typespec/issues/2788)
2024-02-20 20:37:29 +00:00
Timothee Guerin d53b30dbfa
Add `Scalar` to TS `TemplatedType` type (#2929)
fix [#2763](https://github.com/microsoft/typespec/issues/2763)
2024-02-20 20:05:54 +00:00
Timothee Guerin 79745d1cc8
Fix: Program Viewer crash when using unnamed union variants (#2941) 2024-02-20 08:46:40 -08:00
Timothee Guerin 2d6e138ac1
Fix crash with deleted file (#2934)
fix #2928
2024-02-16 19:00:44 -08:00
Timothee Guerin 69e93a8310
Fix: Bumping prerelease count changes from chronus (#2918) 2024-02-14 15:40:39 -08:00
Timothee Guerin 4879eea2e3
Fix pr artifacts deps versions (#2914)
Since we moved to `workspace:~` instead of `workspace:~x.y.z` for
dependency when building pr artifact it is repalced with the actual
version which in pr case is `x.y.z-pr.{prnumber}.{buildid}` and this
cause installation conflict
2024-02-13 23:52:20 +00:00
Timothee Guerin 639d8992c8
Add e2e test for the CLI (#2878)
fix #489

e2e test were also not running at all and the `emitter-ts` template was
failing due to importing `vitest` instead of `node:test`
2024-02-09 16:41:52 +00:00
Timothee Guerin afd377242e
Include tmlanguage computed file in repo as we'll need it for github linguist (#2872)
To register a tm language on github linguist we need to publish our
grammar.
Instructions
https://github.com/github-linguist/linguist/blob/master/CONTRIBUTING.md#adding-a-language
2024-02-09 04:07:46 +00:00
Timothee Guerin 24d3ba0add
Update docs to clarify range of `numeric`, `integer`, etc. and meaning of unixTimestamp (#2893)
fix #2892 Clarify `numeric`, `integer`, `decimal`, `float`
fix #2887 Clarify unixTimestamp encoding

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-02-09 01:37:32 +00:00
Timothee Guerin 71fa909634
Fix: No colors when using `--watch` (#2886)
fix  #2591
2024-02-09 01:12:48 +00:00
Timothee Guerin a1eb851cc3
Enable spell check for all files and fix (#2881)
fix #2776
2024-02-08 16:54:23 -08:00
Timothee Guerin 7452fe9a57
Update dependencies - feb 2024 (#2900)
General dependency updates, notable:
- typescript 5.3
- chronus 0.6.0 (BREAKING  THE CHANGELOG FORMAT)
2024-02-08 15:14:01 -08:00