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

Add example support to json schema #3946

Closed
timotheeguerin opened this issue Jul 23, 2024 Discussed in #3944 · 3 comments · Fixed by #4447
Closed

Add example support to json schema #3946

timotheeguerin opened this issue Jul 23, 2024 Discussed in #3944 · 3 comments · Fixed by #4447
Assignees

Comments

@timotheeguerin
Copy link
Member

Discussed in #3944

Originally posted by risabhds July 23, 2024
I have the following typespec in my playground:

import "@typespec/json-schema";

using TypeSpec.JsonSchema;

@jsonSchema
namespace Schemas;

/** Description goes here */
@summary("Title goes here")
model Person {
  /** The person's name. */
  @example("John")
  name: string;

  /** Age in years which must be equal to or greater than zero. */
  @example(18)
  @minValue(0)
  age: integer;
}

But I don't get examples in the emitted json-schema.

What I desire is a json-schema with examples on the property:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "Person.json",
    "description": "Description goes here",
    "title": "Title goes here",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "The person's name.",
            "examples": ["John"]
        },
        "age": {
            "type": "integer",
            "minimum": 0,
            "description": "Age in years which must be equal to or greater than zero.",
            "examples": [18]
        }
    },
    "required": [
        "name",
        "age"
    ]
}

How do I get examples in the emitted json-schema?

@markcowl
Copy link
Contributor

est: 5

@timotheeguerin
Copy link
Member Author

Cannot seem to find actual spec that json schema support that. This might not be the best idea to add without knowing more how it can be used.

@timotheeguerin timotheeguerin self-assigned this Sep 13, 2024
@timotheeguerin
Copy link
Member Author

Found it as part of the json schmea validaiton spec https://json-schema.org/draft/2020-12/json-schema-validation#name-examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants