Skip to content

Commit

Permalink
Merge branch 'main' into bug/escape-characters-in-docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored May 24, 2024
2 parents 69e900e + 42e72b8 commit 5deb6ff
Show file tree
Hide file tree
Showing 90 changed files with 4,224 additions and 1,753 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/json-schema"
---

The emitted JSON Schema now doesn't make root schemas for TypeSpec types which do not have the @jsonSchema decorator or are contained in a namespace with that decorator. Instead, such schemas are put into the $defs of any root schema which references them, and are referenced using JSON Pointers.
8 changes: 8 additions & 0 deletions .chronus/changes/playground-storybook-2024-4-22-18-10-6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/playground"
---

Add storybook for playground library
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/versioning"
---

Organize versioning library
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:20

RUN corepack enable pnpm && \
echo 'alias pnpm="corepack pnpm"' >> /home/node/.bash_aliases
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Standard",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"vitest.explorer"
]
}
}
}
2 changes: 0 additions & 2 deletions .github/policies/issues.needs-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ configuration:
filters:
- isIssue
- isOpen
- hasLabel:
label: No-Recent-Activity
- hasLabel:
label: needs-info
- noActivitySince:
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
auto-install-peers=true
package-manager-strict=false
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
**/obj/
**/.vs/
**/.docusaurus/
common/temp/
common/scripts/
.chronus/changes/

# Pnpm lock file
Expand Down
22 changes: 11 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,6 @@ TypeSpec repo use labels to help categorize and manage issues and PRs. The follo

### Labels reference

#### issue_kinds

Issue kinds

| Name | Color | Description |
| --------- | ------- | ------------------------------------------ |
| `bug` | #d93f0b | Something isn't working |
| `feature` | #cccccc | New feature or request |
| `docs` | #cccccc | Improvements or additions to documentation |
| `epic` | #cccccc | |

#### area

Area of the codebase
Expand All @@ -332,6 +321,17 @@ Area of the codebase
| `emitter:service:js` | #967200 | |
| `eng` | #65bfff | |

#### issue_kinds

Issue kinds

| Name | Color | Description |
| --------- | ------- | ------------------------------------------ |
| `bug` | #d93f0b | Something isn't working |
| `feature` | #cccccc | New feature or request |
| `docs` | #cccccc | Improvements or additions to documentation |
| `epic` | #cccccc | |

#### breaking-change

Labels around annotating issues and PR if they contain breaking change or deprecation
Expand Down
3 changes: 3 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ words:
- createsorreplacesresource
- createsorupdatesresource
- CRUDL
- dbaeumer
- debouncer
- devdiv
- dogfood
- eastus
- ecmarkup
- esbenp
- esbuild
- espt
- ESRP
- fluentui
- genproto
- globby
- Infima
- inlines
- inmemory
- instanceid
- interner
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY . /app

WORKDIR /app
ENV TYPESPEC_SKIP_VS_BUILD=1
RUN npm install -g pnpm@8.13.1
RUN corepack enable && corepack prepare
RUN pnpm install --frozen-lockfile
RUN pnpm --filter "@typespec/compiler..." run build

Expand Down
37 changes: 37 additions & 0 deletions docs/emitters/json-schema/guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Guide
---

# JSON Schema files and references

When a TypeSpec data type has the `@jsonSchema` decorator or is declared inside a namespace with that decorator, it is considered a _JSON Schema type_.

By default, this emitter will produce one JSON Schema file per JSON Schema type. The file defines an `$id` metadata keyword based on the TypeSpec type name and the file format of the schema (for example, `Widget.yaml`). The `$id` can be overridden by using the `@id` decorator.

:::note
The base URI of a schema is the reference point for resolving relative URIs within the schema, such as those inside `$ref`s. When the `$id` metadata keyword of a schema is an absolute URI, the `$id` is the base URI. When the `$id` is a relative reference, then the base URI is determined by resolving the relative reference against the URI used to retrieve the schema.

The default behavior of this emitter for a model named `Widget` is to produce a schema with a `$id` of `Widget.yaml`, which allows the actual base URI of the document to differ depending on where it is retrieved from, and therefore should allow resolving relative references to other schemas whether loaded from disk or retrieved over HTTP.
:::

When JSON Schema types reference other JSON Schema types, those references are created using a `$ref` with a relative reference (see the note above for how this works in JSON Schema).

How this emitter handles data types which aren't JSON Schema types can be controlled using the `emitAllModels` and `emitAllRefs` options.

By default, this emitter does not define schemas for such data types. Instead, the schemas for them are placed in the `$defs` of any JSON Schema types that reference them. The schemas do not define either `$id` or `$schema` metadata keywords. The `$defs` are referenced using a `$ref` with URI fragment containing a JSON Pointer, which uses the syntax of the following form:

```json
{ "$ref": "#/$defs/{TypeNameHere}" }
```

If you want to treat all TypeSpec types as JSON Schema types (even if they don't have the `@jsonSchema` decorator), you can set the `emitAllModels` option to true. With this set, every data type in your TypeSpec program will get its own schema file, and all references will be relative URIs.

If you want to treat all TypeSpec types referenced from JSON Schema types as JSON Schema types (even if they don't have the `@jsonSchema` decorator), you can set the `emitAllRefs` option to true. With this set, data types which are referenced from JSON Schema types will get their own schema file, and all references to them will be relative URIs.

## Bundling behavior

By default, this emitter will produce separate schema files for each JSON Schema type in your program. However, if you prefer to bundle all of your schemas into a single file, you can set the `bundleId` option to the id you want to use for your bundle. You will now get a single file containing all of your schemas.

Note that bundling does not affect any references within the bundled schemas. In particular, references between JSON Schema types still use relative URIs. As such, correctly resolving these references to the local file requires JSON Schema implementations to support bundling as defined in the JSON Schema 2020-12 specification.

Note also that this does not affect the behavior of non-JSON Schema data types. In particular, by default, non-JSON Schema data types are inlined into each referencing schema's `$defs` object. The `emitAllModels` and `emitAllRefs` options can be used to turn these inlined `$defs` into `$defs` in the bundle.
24 changes: 0 additions & 24 deletions eng/common/config/areas.ts

This file was deleted.

75 changes: 51 additions & 24 deletions eng/common/config/labels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// cspell:ignore bfff
import { repo } from "../scripts/common.js";
import { defineConfig, defineLabels } from "../scripts/labels/config.js";

/**
* Labels that are used to categorize issue for which area they belong to.
Expand Down Expand Up @@ -74,10 +76,10 @@ export const AreaLabels = defineLabels({
},
});

export default {
export const CommonLabels = {
issue_kinds: {
description: "Issue kinds",
labels: {
labels: defineLabels({
bug: {
color: "d93f0b",
description: "Something isn't working",
Expand All @@ -94,11 +96,7 @@ export default {
color: "cccccc",
description: "",
},
},
},
area: {
description: "Area of the codebase",
labels: AreaLabels,
}),
},
"breaking-change": {
description:
Expand Down Expand Up @@ -150,23 +148,52 @@ export default {
},
},
},
misc: {
description: "Misc labels",
labels: {
"Client Emitter Migration": {
color: "FD92F0",
description: "",
},
"good first issue": {
color: "7057ff",
description: "Good for newcomers",
};

/**
* Set the paths that each area applies to.
*/
export const AreaPaths: Record<keyof typeof AreaLabels, string[]> = {
"compiler:core": ["packages/compiler/"],
"compiler:emitter-framework": [],
ide: ["packages/typespec-vscode/", "packages/typespec-vs/"],
"lib:http": ["packages/http/"],
"lib:openapi": ["packages/openapi/"],
"lib:rest": ["packages/rest/"],
"lib:versioning": ["packages/versioning/"],
"meta:blog": ["blog/"],
"meta:website": ["website/"],
tspd: ["packages/tspd/"],
"emitter:client:csharp": ["packages/http-client-csharp/"],
"emitter:json-schema": ["packages/json-schema/"],
"emitter:protobuf": ["packages/protobuf/"],
"emitter:openapi3": ["packages/openapi3/"],
"emitter:service:csharp": [],
"emitter:service:js": [],
eng: ["eng/", ".github/"],
};

export default defineConfig({
repo,
labels: {
area: {
description: "Area of the codebase",
labels: AreaLabels,
},
...CommonLabels,
misc: {
description: "Misc labels",
labels: {
"Client Emitter Migration": {
color: "FD92F0",
description: "",
},
"good first issue": {
color: "7057ff",
description: "Good for newcomers",
},
},
},
},
} as const;

function defineLabels<const T extends string>(
labels: Record<T, { color: string; description: string }>
) {
return labels;
}
areaPaths: AreaPaths,
});
Loading

0 comments on commit 5deb6ff

Please sign in to comment.