Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json schema @extension #2057

Merged
merged 5 commits into from
Jun 14, 2023
Merged

Conversation

bterlson
Copy link
Member

@bterlson bterlson commented Jun 14, 2023

Similar to OpenAPI, JSON Schema users often want to emit custom extensions into the JSON. This adds support for using the @extension decorator to support that use case.

However, unlike OpenAPI, I have seen use cases where people want to emit actual schema content as the value of a custom extension as opposed to raw JSON. For example, something like @extension("x-content-schema", Person). In the absence of syntax for defining value literals (#2046 et al), a Json<T> template is used to disambiguate the "give me a schema for this value" vs "put this into the document as literal JSON" use cases. The Json<T> template validates that its argument is valid JSON, and when emitting JSON Schema, we use this as a sentinel to determine whether to emit a schema or raw JSON.

Closes #2054.

@github-actions
Copy link
Contributor

Changes in this PR will be published to the following url to try(check status of TypeSpec Pull Request Try It pipeline for publish status):
Playground: https://cadlplayground.z22.web.core.windows.net/prs/2057/

Website: https://cadlwebsite.z1.web.core.windows.net/prs/2057/

@bterlson bterlson enabled auto-merge (squash) June 14, 2023 16:45
@bterlson bterlson merged commit 61afd79 into microsoft:main Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JsonSchema] Provide a way to add extension properties
3 participants