TypeSpec library for emitting TypeSpec to JSON Schema and converting JSON Schema to TypeSpec
MIT License
Bot releases are hidden (Show)
Published by azure-sdk 3 months ago
Array
, Record
, Union
and unknown
typesPublished by azure-sdk 3 months ago
createAssetEmitter
directly#3699 Moved compiler dependencies to peer and dev for scaffolded projects.
#3572 Add new @example
and @opExample
decorator to provide examples on types and operations.
@example(#{
id: "some",
date: utcDateTime.fromISO("2020-01-01T00:00:00Z"),
timeout: duration.fromISO("PT1M"),
})
model Foo {
id: string;
date: utcDateTime;
@encode("seconds", int32) timeout: duration;
}
@opExample(
#{
parameters: #{
pet: #{
id: "some",
name: "Fluffy",
dob: plainDate.fromISO("2020-01-01"),
},
},
returnType: #{
id: "some",
name: "Fluffy",
dob: plainDate.fromISO("2020-01-01"),
},
},
#{ title: "First", description: "Show creating a pet" }
)
op createPet(pet: Pet): Pet;
#3751 Adds option to tsp init
to generate .gitignore file
#3793 Do not carry over @friendlyName
with model is
or op is
@friendlyName("Abc{T}", T)
model Foo<T> {}
model Bar is Foo<string>;
// This can be changed to
model Abcstring is Foo<string>;
#3659 Disallows overriding a required inherited property with an optional property.
In previous versions of TypeSpec, it was possible to override a required property with an optional property. This is no longer allowed. This change may result in errors in your code if you were relying on this bug, but specifications that used this behavior are likely to have been exposed to errors resulting from incoherent type checking behavior.
The following example demonstrates the behavior that is no longer allowed:
model Base {
example: string;
}
model Child extends Base {
example?: string;
}
In this example, the Child
model overrides the example
property from the Base
model with an optional property. This is no longer allowed.
getHttpPart
and types functionsmodel
property on HttpAuth
to retrieve original type used to define security scheme#3737 Keep trailing slash when building http routes, this is breaking if you used to have @route()
ending with /
.
TypeSpec | Before | After |
---|---|---|
@route("users/") |
users |
users/ |
@route("users") |
users |
users |
on interface @route("users/") and on op @route("addresses/")
|
users/addresses |
users/addresses/ |
on interface @route("users/") and on op @route("addresses")
|
users/addresses |
users/addresses |
tsp compile
from another directory@example
and @opExample
decorator@typespec/openapi3
package.tsp compile
from another directoryNo changes, version bump only.
Published by azure-sdk 3 months ago
Published by azure-sdk 3 months ago
Published by azure-sdk 3 months ago
No changes, version bump only.
Published by azure-sdk 3 months ago
Published by azure-sdk 3 months ago
Published by azure-sdk 3 months ago
Published by azure-sdk 4 months ago
tsp code install
const a = 100.0
)@param
doc tag on operation create with op is
to override upstream docPickProperties
type to dynamically select a subset of a model#3280 Support completion for Model with extended properties
Example
model Device {
name: string;
description: string;
}
model Phone extends Device {
┆
} | [name]
| [description]
#3280 Support completion for object values and model expression properties.
Example
model User {
name: string;
age: int32;
address: string;
}
const user: User = #{name: "Bob", ┆}
| [age]
| [address]
#3375 Allow @
to be escaped in doc comment with \
Object and array values
@dummy(#{
name: "John",
age: 48,
address: #{ city: "London" }
aliases: #["Bob", "Frank"]
})
Scalar constructors
scalar utcDateTime {
init fromISO(value: string);
}
model DateRange {
minDate: utcDateTime = utcDateTime.fromISO("2024-02-15T18:36:03Z");
}
#3527 Add support for @prop
doc comment tag to describe model properties
#3422 Formatter: Indent or dedent multiline strings to the current indentation
#3460 Hide deprecated items from completion list
#3443 Support completion for keyword 'extends' and 'is'
Example
model Dog ┆ {}
| [extends]
| [is]
scalar Addresss ┆
| [extends]
op jump ┆
| [is]
interface ResourceA ┆ {}
| [extends]
model Cat<T ┆> {}
| [extends]
#3462 Linter all
rulesets is automatically created if not explicitly provided
#3533 More logs and traces are added for diagnostic and troubleshooting in TypeSpec language server
model Test {
// Deprecated
values: string[] = ["a", "b", "c"];
// Correct
values: string[] = #["a", "b", "c"];
model Test {
// Deprecated
user: {name: string} = {name: "System"};
// Correct
user: {name: string} = #{name: "System"};
With the introduction of values, the decorator marshalling behavior has changed in some cases. This behavior is opt-in by setting the valueMarshalling
package flag to "new"
, but will be the default behavior in future versions. It is strongly recommended to adopt this new behavior as soon as possible.
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 js/ts files.
export const $flags = definePackageFlags({
decoratorArgMarshalling: "new",
});
#3342 Add new multipart handling. Using @multipartBody
with HttpPart<Type, Options>
. See multipart docs for more information.
op upload(@header contentType: "multipart/mixed", @multipartBody body: {
name: HttpPart<string>;
avatar: HttpPart<bytes>[];
}): void;
#3462 Use new compiler automatic all
ruleset instead of explicitly provided one
@madeRequired
decorator@removed
on member types and @added
on containing type could result in errorsdecimals: decimal[] = #[123, 456.7];
)Published by azure-sdk 4 months ago
Published by azure-sdk 4 months ago
Published by azure-sdk 4 months ago
Published by azure-sdk 4 months ago
Published by azure-sdk 5 months ago
--nostdlib
flag will now work by only applying to optional standard library types{foo?: string}
cannot be assigned to a constraint of {foo: string}
)tsp install
on windows due to recent NodeJS breaking change to fix vulnerability.is
target in an interface operation templatefetch
API that is now stable since node 18.13.0
getEncode
returns the fully qualified enum member name if using a custom enum.sourceModels
property to modelauthorizationUrl
instead of tokenUrl
@path
param mapping when spreading a record in operation parameters@path
property shouldn't be applicableMetadata if the visibility contains Read
#2945 Empty model after removing metadata and applying visibility always results in "void"
This means the following case have changed from returning {}
to no body
op b1(): {};
op b2(): {@visibility("none") prop: string};
op b3(): {@added(Versions.v2) prop: string};
Workaround: Use explicit @body
op b1(): {@body _: {}};
op b2(): {@body _: {@visibility("none") prop: string}};
op b3(): {@body _: {@added(Versions.v2) prop: string}};
#2945 Implicit status code always 200 except if response is explicitly void
op c1(): {@header foo: string}; // status code 200 (used to be 204)
Solution: Add explicit @statusCode
op c1(): {@header foo: string, @statusCode _: 204};
op c1(): {@header foo: string, ...NoContent}; // or spread common model
#2945 @body
means this is the body
This change makes using @body
mean this is the exact body and everything underneath will be included, including metadata properties. If metadata properties are present on the body, a warning will be logged.
op a1(): {@body _: {@header foo: string, other: string} };
^ warning header in a body, it will not be included as a header.
Use @bodyRoot
if you want to only change where to resolve the body from.
op a1(): {@bodyRoot _: {@header foo: string, other: string} };
#2945 Properties are not automatically omitted if everything was removed from metadata or visibility
op d1(): {headers: {@header foo: string}}; // body will be {headers: {}}
Solution: use @bodyIgnore
op d1(): {@bodyIgnore headers: {@header foo: string}}; // body will be {headers: {}}
@service
appears inside a versioned namespace@bodyRoot
and @body
distinction@path
property should be included in unreachable models@bodyRoot
and @body
distinctionsourceModels
property to model viewNo changes, version bump only.
Published by azure-sdk 5 months ago
Published by azure-sdk 5 months ago
Published by azure-sdk 5 months ago
Published by azure-sdk 5 months ago
Published by azure-sdk 7 months ago
warn-as-error
do not prevent compilation from moving to the next stage like regular warnings@encode
for model properties that have a union type. This supports cases like @encode("rfc3339") prop: utcDateTime | null
@knownValues
decorator. Use a named union of string literal with a string variant to achieve the same result without a decoratorExample:
-enum FooKV { a, b, c}
-@knownValues(FooKV)
-scalar foo extends string;
+union Foo { "a", "b", "c", string }
@projectedName
decorator. @encodedName
should be used instead.Example:
-@projectedName("json", "exp")
+@encodedName("application/json", "exp")
{nullable: true}
when trying to emit null
in openapi3format: binary
extends
was used in different visibility.generated-defs
folderNo changes, version bump only.
Published by timotheeguerin 8 months ago
model Example<T extends T>
Scalar
to TS TemplatedType
typetsp compile --watch
was missing coloring and error previews...Record<T>
to define the type of remaining properties@error
) is now an error.@typespec/compiler/utils
exports. Deprecate export from @typespec/compiler
of utils like DuplicateTracker
, Queue
, createTwoKeyMap
, etc.@service
version property. If wanting to describe a service versioning you can use the @typespec/versioning
library. If wanting to describe the project version you can use the package.json version. For OpenAPI generation. the @OpenAPI.info
nows decorator allows providing the document version.@useAuth
decorator is applied to a type.info
object on the @info
decoratorinfo
object on the @info
decoratorgetOpenAPI3
function that takes a TypeSpec program and returns the emitted OpenAPI as an object. Useful for other emitters and tools that want to work with emitted OpenAPI directly without writing it to disk.safeint-strategy
that can be set to double-int
to emit type: integer, format: double-int
instead of type: integer, format: int64
when using the safeint
scalar.temp
foldernoEmit
flag