Перейти к файлу
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
.chronus Organize versioning library (#3309) 2024-05-23 22:43:36 +00:00
.github Make the sync label logic reusable for typespec-azure repo (#3425) 2024-05-23 17:01:14 +00:00
.vscode Update extensions.json for Vitest Explorer. (#3251) 2024-05-01 20:29:53 +00:00
blog/2024-04-25-introducing Fix broken blog link (#3252) 2024-04-29 20:38:51 +00:00
docker Clean up capitalization, parentheses, and phrasing in docs (#2817) 2024-01-25 10:40:16 -08:00
docs Preserve leading whitespace in fenced blocks in doc comments (#3399) 2024-05-20 19:57:31 +00:00
e2e Add publish pipeline for dotnet emitter (#3116) 2024-04-08 17:33:06 -07:00
eng Make the sync label logic reusable for typespec-azure repo (#3425) 2024-05-23 17:01:14 +00:00
grammars Value world, object, tuple literals, const (#3022) 2024-05-08 20:06:28 +00:00
icons/raw Website & Docs Cleanup (#3002) 2024-03-11 18:56:35 -07:00
packages Organize versioning library (#3309) 2024-05-23 22:43:36 +00:00
.dockerignore Feature: docker image (#57) 2021-11-12 11:17:46 -08:00
.editorconfig Format CSharp files: add `dotnet format` to `rush format` (#490) 2022-04-29 09:46:23 -07:00
.gitattributes Add release notes for 0.56.0 (#3294) 2024-05-07 21:02:14 +00:00
.gitignore Move generator over to microsoft/typespec (#3175) 2024-04-22 22:36:24 +00:00
.npmrc Get rid of rush and move to pnpm (#2775) 2024-01-24 13:37:34 -08:00
.prettierignore Make the sync label logic reusable for typespec-azure repo (#3425) 2024-05-23 17:01:14 +00:00
.prettierrc.json Get rid of rush and move to pnpm (#2775) 2024-01-24 13:37:34 -08:00
CODE_OF_CONDUCT.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
CONTRIBUTING.md Make the sync label logic reusable for typespec-azure repo (#3425) 2024-05-23 17:01:14 +00:00
LICENSE Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
README.md Simplify Readme (#2864) 2024-01-30 16:18:37 -08:00
SECURITY.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
cspell.yaml Run all if vitest.config.ts change (#3411) 2024-05-21 17:49:46 +00:00
eslint.config.js Fix parser test running 1-4 times (#3168) 2024-04-15 15:14:53 -07:00
package.json Make the sync label logic reusable for typespec-azure repo (#3425) 2024-05-23 17:01:14 +00:00
pnpm-lock.yaml Simplify to use vite for building playground library (#3403) 2024-05-20 22:07:51 +00:00
pnpm-workspace.yaml Initial move of csharp client emitter (#3098) 2024-04-04 16:26:05 -07:00
troubleshooting.md 1/3 TypeSpec: Find/Replace Content 2023-02-16 13:07:22 -08:00
tsconfig.base.json Add numeric data structure (#3115) 2024-04-09 16:38:16 +00:00
tsconfig.eng.json Validate typescript eng scripts & use patterns for pr label triage (#3381) 2024-05-17 16:42:46 +00:00
tsconfig.json Migrate test framework to vitest (#2769) 2024-01-02 11:40:29 -08:00
tsconfig.ws.json Feature: Add Xml library (#3035) 2024-04-09 15:33:46 -07:00
vitest.config.ts Fix vitest not reloading JS files (#3395) 2024-05-17 21:53:01 +00:00
vitest.workspace.ts Allow reload of js files in vitest (#3086) 2024-04-01 17:54:38 +00:00

README.md

TypeSpec

Official Docs | Try TypeSpec Online | Getting Started | Language Overview

TypeSpec is a language for defining cloud service APIs and shapes. TypeSpec is a highly extensible language with primitives that can describe API shapes common among REST, OpenAPI, gRPC, and other protocols.

TypeSpec is excellent for generating many different API description formats, client and service code, documentation, and many other assets. All this while keeping your TypeSpec definition as a single source of truth.

Using TypeSpec, you can create reusable patterns for all aspects of an API and package those reusable patterns into libraries. These patterns establish "guardrails" for API designers and makes it easier to follow best practices than to deviate from them. TypeSpec also has a rich linter framework with the ability to flag anti-patterns as well as an emitter framework that lets you control of the output to ensure it follows the patterns you want.

Installation

npm install -g @typespec/compiler

Tools

The TypeSpec VS Code extension can be installed from the VS Code marketplace or directly on the command line:

tsp code install

The TypeSpec VS Extension can be installed from the VS Marketplace or directly on the command line:

tsp vs install

Usage

TypeSpec to OpenAPI 3.0 Example

This example uses the @typespec/http, @typespec/rest, and @typespec/openapi3 libraries to define a basic REST service and generate an OpenAPI 3.0 document from it.

Run the following command and select "Generic REST API":

tsp init

Hit enter a few times to confirm the defaults.

Copy the contents below into your main.tsp:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";

using TypeSpec.Http;
using TypeSpec.Rest;

/** This is a pet store service. */
@service({
  title: "Pet Store Service",
})
@server("https://example.com", "The service endpoint")
namespace PetStore;

@route("/pets")
interface Pets {
  list(): Pet[];
}

model Pet {
  @minLength(100)
  name: string;

  @minValue(0)
  @maxValue(100)
  age: int32;

  kind: "dog" | "cat" | "fish";
}

Install the dependencies of main.tsp:

tsp install

Compile it to OpenAPI 3.0:

tsp compile main.tsp --emit @typespec/openapi3

You can find the emitted OpenAPI output in ./tsp-output/openapi.json.

Advanced Scenarios

Installing nightly version

On every commit to the main branch, packages with changes are automatically published to npm with the @next tag. The packages section shows which version corresponds to the next tag for each package.

To use a nightly version of the packages, go over each one of the packages in the package.json file and update it to either the latest published @next version or @latest, whichever is the newest. You can also use the tag latest or next instead of an explicit version.

After updating the package.json file you can run npm update --force. Force is required as there might be some incompatible version requirement.

Example

// Stable setup
"dependencies": {
  "@typespec/compiler": "~0.30.0",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0",
  "@typespec/openapi": "~0.9.0",
}

// Consume next version
// In this example: compiler and openapi have changes but rest library has none
"dependencies": {
  "@typespec/compiler": "~0.31.0-dev.5",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0", // No changes to @typespec/rest library so need to stay the latest.
  "@typespec/openapi": "~0.10.0-dev.2",
}

Packages

Name Changelog Latest Next
Core functionality
@typespec/compiler Changelog
TypeSpec Libraries
@typespec/http Changelog
@typespec/rest Changelog
@typespec/openapi Changelog
@typespec/openapi3 Changelog
@typespec/versioning Changelog
TypeSpec Tools
@typespec/prettier-plugin-typespec Changelog
typespec-vs Changelog
typespec-vscode Changelog
tmlanguage-generator Changelog

@next version of the package are the latest versions available on the main branch.