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

2504 Коммитов

Автор SHA1 Сообщение Дата
Christopher Radek ae229b22c9
tsp-openapi3 - update to group items by namespace when separated by dot, and escaped otherwise invalid identifiers (#3844)
Fixes #3810 and replaces #3808

This PR does 2 things:
1. Groups operations/models into namespaces based on the dots in their
schema names/operationIds.
2. Escapes invalid identifiers by surrounding them with backticks.

---------

Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
2024-07-16 20:00:00 +00:00
Timothee Guerin fef3f01706
Examples (#3572)
Fix #2700 Add support for `@example` and `@opExample`


[Playground
demo](https://cadlplayground.z22.web.core.windows.net/prs/3572/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBIdHRwOwoKQGV4YW1wbGUoI3sKICBpZDogInNvbWUiLAogIGJhcjogInRoaW5nxRBkYXRlOiB1dGNEYXRlVGltZS5mcm9tSVNPKCIyMDIwLTAxLTAxVDAwOsUDWiIpxDV1bml4xDA6xQrENnN0YW1wMzLfPcU9ZW5jb2RlZEFzUmZjNzIzMd9%2B0kFkb2I6IHBsYWluxDbUMsYodGltZW91dDogZHVyYXRpb27KK1BUMU3NJUluU2Vjb25kc9guMS41U9YyRmxvYddlMMc1fSkKbW9kZWwgRm9vIOgBlHN0cmluZzvoAZTKD%2FEBk8QV%2BQFzOwoKICBA5gFVKMgyS25vd25FxBRpbmcucuYBaSn%2FAX1lxUvuAV7Ee%2FEBSM1zInPmAQciLCBpbnQzMsRm%2BgFV2Dtm5AFF1j3vAWA7Cn0K5wFOUGV08wFObmFtZcwQ8ADRfQoKQG9wRecDIwogIOUDJiAgcGFyYW1ldGVyczrIE%2FADPcUnZXTLINQi6ACDIkZsdWZmecsY%2FwK66QK6xAF9xgnHB3JldHVyblR5cGX9AJ3Wed93y3fFbsUFI3sgdGl0bMVOaXJzdCIsIGRlc2NyaXDkAYU6ICJTaG93IGNyZWF05AR6YeQBGCIgfQopCm9wxhdlUGV0KOoBmyzEIjrkAbQpxQY7Cg%3D%3D&e=%40typespec%2Fopenapi3&options=%7B%7D)

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-07-16 19:14:24 +00:00
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
Timothee Guerin 613c981c91
Fix pagination index (#3840) 2024-07-15 19:45:34 +00:00
Dapeng Zhang 6fda756743
Refine `GetSerializationProviders` (#3830)
Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-15 19:07:44 +00:00
JoshLove-msft 04435d1b2e
Test plugin (part 2) (#3828)
Remaining files that were left out of initial merge
2024-07-15 18:27:03 +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
Mario Guerra 0d8507700c
Update getting started http guide (#3684)
Revised and expanded version of the pet store HTTP example.

---------

Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
2024-07-15 15:42:17 +00:00
Timothee Guerin 83afa54678
Improve tryit comment (#3833)
This link is super useful to review PRs but it is currently just a
little too much parsing effort to click on the right one.

### Before

![image](https://github.com/user-attachments/assets/cf8c1428-b3f9-487f-be1a-d48640336004)

### After

![image](https://github.com/user-attachments/assets/d83970de-2b9e-4826-94fc-5df030deec99)
2024-07-12 21:19:59 +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
Dapeng Zhang ba65f90868
sync 4893 from autorest.csharp (#3832)
Sync up change from https://github.com/Azure/autorest.csharp/pull/4893
2024-07-12 08:41:01 +00:00
Dapeng Zhang d2a165963c
fix serialized name issue in deserialization (#3817)
A follow up for https://github.com/microsoft/typespec/pull/3755
2024-07-12 02:38:37 +00:00
Timothee Guerin 67190da0e8
Fix http authentication docs example (#3760) 2024-07-12 00:32:27 +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
JoshLove-msft 88f4b10e93
Add test plugin (#3698)
Adds a test plugin demonstrating simple tracing and customization of
list setters.
Fixes https://github.com/microsoft/typespec/issues/3672
2024-07-11 19:44:33 +00:00
Dapeng Zhang d94a2a2f59
a few refinement to the existing snippets (#3816)
Some snippets are not adding the return types explicitly to the return
expression, this PR adds them.

---------

Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-11 16:34:59 +00:00
Timothee Guerin f84dbe81e1
Add docs for emitter framework import (#3788)
fix [#3633](https://github.com/microsoft/typespec/issues/3633)
2024-07-10 23:11:11 +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
m-nash 86a0c564b9
Mocking client model (#3812)
Follow new mocking pattern in mgc.cm as well.

Follow up to https://github.com/microsoft/typespec/pull/3807
2024-07-10 21:03:57 +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
m-nash 22ac8af723
Normalize mocking in mgc.tests (#3807)
We were all doing mocking slightly differently. I created a common
helper to mock the plugin and provide some functionality to pass in
behaviors that we want to change on a per test basis. I will make a
follow up PR to update mgc.cm to follow the same pattern.
2024-07-10 19:48:35 +00:00
m-nash 737f244f0b
Add NamedSymbolTypeProvider (#3746)
Fixes https://github.com/microsoft/typespec/issues/3744
2024-07-10 17:16:20 +00:00
Jorge Rangel 4658a058e0
Populate MRW cast methods (#3771)
This PR populates the cast methods that are currently generated for
models. Additional unit tests and functional tests were also added.
2024-07-10 17:06:37 +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
Jorge Rangel fe345f26d0
Bump System.Text.Json to v8.0.4 (#3802)
fixes https://github.com/microsoft/typespec/issues/3801
2024-07-10 16:30:50 +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
m-nash 6b79334035
use typeprovider csharptype creation (#3799)
Addresses
https://github.com/microsoft/typespec/pull/3776/files#r1671606604
2024-07-10 07:28:13 +00:00
Crystal YU 311d99f9fa
export more api (#3723)
- export more apis from http-client-csharp library so that those api can
be used in follow-up emitter.
- change NetEmitterOptions to interface: it can be extended; consistent
with others e.g. SdkEmitterOptions; it can used as partial scenario to
add more fields which may more suitable for plugin framework.
2024-07-10 06:16:46 +00:00
Dapeng Zhang 76bbb40413
Fix the issue in writing serialized name and generating property names (#3755)
Fixes https://github.com/microsoft/typespec/issues/3753

---------

Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-10 02:14:09 +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
Jorge Rangel 532e6ed4b1
Properly generate readonly prop declarations (#3685)
This PR fixes an issue where model properties that were read only
collections were not being declared with the correct type.
2024-07-09 23:44:54 +00:00
Timothee Guerin c2043a4da8
Add docs on identifiers (#3789)
fix #3271

---------

Co-authored-by: Brian Terlson <brian.terlson@microsoft.com>
2024-07-09 22:35:20 +00:00
Timothee Guerin b2c03c5b59
Fix upload of playground package bundle (#3790)
A recent break in storage blob SDK corrupted the uploading of certain
files https://github.com/Azure/azure-sdk-for-js/issues/30138 when using
the `upload(text, length)` method. Switching to converting to a buffer
and uploading fixes the issue.
2024-07-09 21:27:53 +00:00
Dapeng Zhang 9c021559c7
Conversions between parameters, properties and fields (#3754)
Fixes #3692 

In the practice, we usually need to keep tracking the property-parameter
conversion
For instance, when constructing the constructor of a model, we first
construct all the properties of the current model then building up the
ctors. And during building the ctors, we need to convert the properties
to parameters. And in the body of the ctor, we will need to assign the
parameters to the properties, but the code of building signature and
body are in different places, therefore we may lose track of the
conversion relationship therefore we will have to find them by names.

This PR adds the two-way references among `ParameterProvider`,
`PropertyProvider` and `FieldProvider`.
You can convert a property to a parameter by calling the
`PropertyProvider.Parameter`, and the constructed parameter will hold
the reference of the propety which constructs it.
Similarly you could do the same between fields and parameters.
In this way we could prevent that when building something, we will make
things up.

there is also a two-way reference between property and field, but this
is not a conversion, this is to track the field to be the "backing
field" of the property, and vice versa. We do not have a solid use case
for this yet, therefore this part is only prototyping, and if possible,
I could remove it from this PR and add it back later when we have a case
for it (such as the json merge patch case?).

---------

Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-09 20:19:20 +00:00
Dapeng Zhang f5a9764a62
Refactor `MethodProvider` (#3756)
Fixes https://github.com/microsoft/typespec/issues/3739

Previously, constructors and methods are both represented by
`MethodProvider`, which is quite inconvenience in some cases that we
want to get the `ReturnType` out from a method, we will have to cast the
`Signature` to `MethodSignature`.
A new type `ConstructorProvider` is introduced in this PR to represent
ctors only and now the `Signature` type is `MethodSignature` in
`MethodProvider` which only represents the normal methods.

Considering that ctors and methods are similar, we may add a common base
type to `MethodProvider` and `ConstructorProvider`, such as
`MethodBaseProvider` just like how `MethodSignature` and
`ConstructorSignature` do.
But currently I did not see any use case that requires to add ctors and
methods into the same list, therefore this PR does not add that, and we
could always add that part later.

---------

Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-09 19:47:43 +00:00
Pan Shao 0887d96f51
Generate optional value type as nullable (#3757)
1. Fix #3740
2. Add `IsNullable` to `PropertyWireInformation` so that downstream
could know whether we should check `null` when doing serialization.

Confirmed after this change, the core part of test code (like
serializing properties) now is exactly same as that in autorest.csharp.
(except some code structure thing like `WriteCore`)(except that in this
this repo there are several newly-added properties like
`FloatExtensibleEnumWithIntValue` which is not in autorest.csharp)

---------

Co-authored-by: Pan Shao <pashao@microsoft.com>
Co-authored-by: m-nash <64171366+m-nash@users.noreply.github.com>
2024-07-09 19:38:51 +00:00
m-nash 53e95ef0d6
Remove circular dependency between csharptype and typeprovider (#3776)
Fixes https://github.com/microsoft/typespec/issues/3775
2024-07-09 18:15:46 +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
Timothee Guerin 26636840cd
Upgrade to pnpm 9 (#3772) 2024-07-09 16:06:03 +00:00
Jorge Rangel 82234663e8
Add serialization functional tests (#3749)
This PR adds a set of tests that validates the generated serialization
methods for the models in the `Unbranded-TypeSpec` test project.
2024-07-08 23:43:04 +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 65fbae8c4a
Disable 1ES codeql due to unreliability (#3770)
From Azure sdk for js repo >


> All the other languages have disabled codeql and we are now hitting
blocking issues when running codeql on macos
(https://dev.azure.com/twcdot/Data/_workitems/edit/138580) and even on
the other OS's the configuration causes the builds to run for a long
time.

https://github.com/Azure/azure-sdk-for-js/pull/30277
2024-07-08 20:22:25 +00:00
Timothee Guerin e484821e3a
Add disclaimer on the openapi3 to typespec conversion (#3769) 2024-07-08 18:26:19 +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