Skip to content

Commit

Permalink
feat: title in annotations (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-tichovsky-s2 authored Feb 11, 2021
1 parent d9338fd commit 9e52a29
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
15 changes: 15 additions & 0 deletions test/programs/annotation-title/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @title filled#
*/
interface MySubObject {
a: boolean;
}

interface MyObject {
/**
* @title empty#
*/
empty;

filled: MySubObject;
}
23 changes: 23 additions & 0 deletions test/programs/annotation-title/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"MySubObject": {
"title": "filled#",
"type": "object",
"properties": {
"a": { "type": "boolean" }
},
"required": ["a"]
}
},
"properties": {
"empty": {
"title": "empty#"
},
"filled": {
"$ref": "#/definitions/MySubObject"
}
},
"required": ["empty", "filled"],
"type": "object"
}
12 changes: 4 additions & 8 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,15 @@ describe("schema", () => {
describe("annotations", () => {
assertSchema("annotation-default", "MyObject");
assertSchema("annotation-ref", "MyObject", {}, undefined, undefined, {
skipCompile: true
skipCompile: true,
});
assertSchema("annotation-tjs", "MyObject", {
validationKeywords: ["hide"],
});
assertSchema("annotation-id", "MyObject", {}, undefined, undefined, {
expectedWarnings: [
"schema id ignored",
"schema id ignored",
"schema id ignored",
"schema id ignored"
]
expectedWarnings: ["schema id ignored", "schema id ignored", "schema id ignored", "schema id ignored"],
});
assertSchema("annotation-title", "MyObject");
assertSchema("annotation-items", "MyObject");

assertSchema("typeof-keyword", "MyObject", { typeOfKeyword: true });
Expand Down Expand Up @@ -461,6 +457,6 @@ describe("tsconfig.json", () => {

describe("Functionality 'required' in annotation", () => {
assertSchema("annotation-required", "MyObject", {
tsNodeRegister: true
tsNodeRegister: true,
});
});
3 changes: 2 additions & 1 deletion typescript-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ const validationKeywords = {
format: true,
default: true,
$ref: true,
id: true
id: true,
title: true
};

/**
Expand Down

0 comments on commit 9e52a29

Please sign in to comment.