diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/CodeFile.json b/tools/apiview/parsers/apiview-treestyle-parser-schema/CodeFile.json index 882645d4194..1161df5e7b0 100644 --- a/tools/apiview/parsers/apiview-treestyle-parser-schema/CodeFile.json +++ b/tools/apiview/parsers/apiview-treestyle-parser-schema/CodeFile.json @@ -1,111 +1,117 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "CodeFile.json", - "type": "object", - "properties": { - "PackageName": { - "type": "string" - }, - "PackageVersion": { - "type": "string" - }, - "ParserVersion": { - "type": "string", - "description": "version of the APIview language parser used to create token file" - }, - "Language": { - "anyOf": [ - { - "type": "string", - "const": "C" - }, - { - "type": "string", - "const": "C++" - }, - { - "type": "string", - "const": "C#" - }, - { - "type": "string", - "const": "Go" - }, - { - "type": "string", - "const": "Java" - }, - { - "type": "string", - "const": "JavaScript" + "$defs": { + "CodeFile": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "CodeFile.json", + "type": "object", + "properties": { + "PackageName": { + "type": "string" }, - { - "type": "string", - "const": "Kotlin" + "PackageVersion": { + "type": "string" }, - { + "ParserVersion": { "type": "string", - "const": "Python" + "description": "version of the APIview language parser used to create token file" }, - { - "type": "string", - "const": "Swagger" + "Language": { + "anyOf": [ + { + "type": "string", + "const": "C" + }, + { + "type": "string", + "const": "C++" + }, + { + "type": "string", + "const": "C#" + }, + { + "type": "string", + "const": "Go" + }, + { + "type": "string", + "const": "Java" + }, + { + "type": "string", + "const": "JavaScript" + }, + { + "type": "string", + "const": "Kotlin" + }, + { + "type": "string", + "const": "Python" + }, + { + "type": "string", + "const": "Swagger" + }, + { + "type": "string", + "const": "Swift" + }, + { + "type": "string", + "const": "TypeSpec" + } + ] }, - { - "type": "string", - "const": "Swift" + "LanguageVariant": { + "anyOf": [ + { + "type": "string", + "const": "None" + }, + { + "type": "string", + "const": "Spring" + }, + { + "type": "string", + "const": "Android" + } + ], + "default": "None", + "description": "Language variant is applicable only for java variants" }, - { - "type": "string", - "const": "TypeSpec" - } - ] - }, - "LanguageVariant": { - "anyOf": [ - { - "type": "string", - "const": "None" + "CrossLanguagePackageId": { + "type": "string" }, - { - "type": "string", - "const": "Spring" + "ReviewLines": { + "type": "array", + "items": { + "$ref": "ReviewLine.json" + } }, - { - "type": "string", - "const": "Android" + "Diagnostics": { + "type": "array", + "items": { + "$ref": "CodeDiagnostic.json" + }, + "description": "Add any system generated comments. Each comment is linked to review line ID" } + }, + "required": [ + "PackageName", + "PackageVersion", + "ParserVersion", + "Language", + "ReviewLines" ], - "default": "None", - "description": "Language variant is applicable only for java variants" - }, - "CrossLanguagePackageId": { - "type": "string" + "description": "ReviewFile represents entire API review object. This will be processed to render review lines." }, - "ReviewLines": { - "type": "array", - "items": { - "$ref": "#/$defs/ReviewLine" - } - }, - "Diagnostics": { - "type": "array", - "items": { - "$ref": "#/$defs/CodeDiagnostic" - }, - "description": "Add any system generated comments. Each comment is linked to review line ID" - } - }, - "required": [ - "PackageName", - "PackageVersion", - "ParserVersion", - "Language", - "ReviewLines" - ], - "description": "ReviewFile represents entire API review object. This will be processed to render review lines.", - "$defs": { "ReviewLine": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "ReviewLine.json", "type": "object", "properties": { "LineId": { @@ -118,14 +124,14 @@ "Tokens": { "type": "array", "items": { - "$ref": "#/$defs/ReviewToken" + "$ref": "ReviewToken.json" }, "description": "list of tokens that constructs a line in API review" }, "Children": { "type": "array", "items": { - "$ref": "#/$defs/ReviewLine" + "$ref": "ReviewLine.json" }, "description": "Add any child lines as children. For e.g. all classes and namespace level methods are added as a children of namespace(module) level code line. \nSimilarly all method level code lines are added as children of it's class code line." }, @@ -147,40 +153,13 @@ ], "description": "ReviewLine object corresponds to each line displayed on API review. If an empty line is required then add a code line object without any token." }, - "CodeDiagnostic": { - "type": "object", - "properties": { - "DiagnosticId": { - "type": "string", - "description": "Diagnostic ID is auto generated ID by CSharp analyzer." - }, - "TargetId": { - "type": "string", - "description": "Id of ReviewLine object where this diagnostic needs to be displayed" - }, - "Text": { - "type": "string", - "description": "Auto generated system comment to be displayed under targeted line." - }, - "Level": { - "$ref": "#/$defs/CodeDiagnosticLevel" - }, - "HelpLinkUri": { - "type": "string" - } - }, - "required": [ - "TargetId", - "Text", - "Level" - ], - "description": "System comment object is to add system generated comment. It can be one of the 4 different types of system comments." - }, "ReviewToken": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "ReviewToken.json", "type": "object", "properties": { "Kind": { - "$ref": "#/$defs/TokenKind" + "$ref": "TokenKind.json" }, "Value": { "type": "string" @@ -227,26 +206,61 @@ ], "description": "Token corresponds to each component within a code line. A separate token is required for keyword, punctuation, type name, text etc." }, - "CodeDiagnosticLevel": { + "TokenKind": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "TokenKind.json", "type": "number", "enum": [ + 0, 1, 2, 3, - 4 + 4, + 5, + 6, + 7 ] }, - "TokenKind": { + "CodeDiagnostic": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "CodeDiagnostic.json", + "type": "object", + "properties": { + "DiagnosticId": { + "type": "string", + "description": "Diagnostic ID is auto generated ID by CSharp analyzer." + }, + "TargetId": { + "type": "string", + "description": "Id of ReviewLine object where this diagnostic needs to be displayed" + }, + "Text": { + "type": "string", + "description": "Auto generated system comment to be displayed under targeted line." + }, + "Level": { + "$ref": "CodeDiagnosticLevel.json" + }, + "HelpLinkUri": { + "type": "string" + } + }, + "required": [ + "TargetId", + "Text", + "Level" + ], + "description": "System comment object is to add system generated comment. It can be one of the 4 different types of system comments." + }, + "CodeDiagnosticLevel": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "CodeDiagnosticLevel.json", "type": "number", "enum": [ - 0, 1, 2, 3, - 4, - 5, - 6, - 7 + 4 ] } } diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/ci.yml b/tools/apiview/parsers/apiview-treestyle-parser-schema/ci.yml new file mode 100644 index 00000000000..5cae68f3367 --- /dev/null +++ b/tools/apiview/parsers/apiview-treestyle-parser-schema/ci.yml @@ -0,0 +1,61 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - release/* + - hotfix/* + paths: + include: + - tools/apiview/parsers/apiview-treestyle-parser-schema + +pr: + branches: + include: + - main + - feature/* + - release/* + - hotfix/* + paths: + include: + - tools/apiview/parsers/apiview-treestyle-parser-schema + +pool: + name: azsdk-pool-mms-ubuntu-2204-general + vmImage: ubuntu-22.04 + +variables: + NodeVersion: '18.x' + +jobs: +- job: CompileApiViewTokenSchema + displayName: 'Compile and Emit APIView Token Schema' + + variables: + - template: /eng/pipelines/templates/variables/globals.yml + + steps: + - task: NodeTool@0 + inputs: + versionSpec: $(NodeVersion) + displayName: "Use Node $(NodeVersion)" + + - script: | + npm install + workingDirectory: tools/apiview/parsers/apiview-treestyle-parser-schema + displayName: "Install npm packages" + + - script: | + npx tsp compile . + workingDirectory: tools/apiview/parsers/apiview-treestyle-parser-schema + displayName: "Build APIView Token Schema" + + - pwsh: | + git diff --exit-code CodeFile.json + if($LastExitCode -ne 0) { + Write-Error "CodeFile.json is not in sync with the TypeSpec APIView schema in main.tsp.Compile TypeSpec schema by running 'tsp compile .' in directory 'tools/apiview/parsers/apiview-treestyle-parser-schema' and include updated json schema in the PR." + } + Write-Host "TypeSpec and json schema for APIView token are in sync" + displayName: "Check if TypeSpec and json schema are in sync" + workingDirectory: tools/apiview/parsers/apiview-treestyle-parser-schema \ No newline at end of file diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp b/tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp index c909e196b3f..4886bc744b6 100644 --- a/tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp +++ b/tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp @@ -1,3 +1,10 @@ +import "@typespec/json-schema"; + +using TypeSpec.JsonSchema; + +@jsonSchema +namespace Schemas; + /** ReviewFile represents entire API review object. This will be processed to render review lines. */ model CodeFile { PackageName: string; diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/sample tokens/Azure.Template_review_content.txt b/tools/apiview/parsers/apiview-treestyle-parser-schema/sample/Azure.Template_review_content.txt similarity index 100% rename from tools/apiview/parsers/apiview-treestyle-parser-schema/sample tokens/Azure.Template_review_content.txt rename to tools/apiview/parsers/apiview-treestyle-parser-schema/sample/Azure.Template_review_content.txt diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/sample tokens/Azure.Template_token.json b/tools/apiview/parsers/apiview-treestyle-parser-schema/sample/Azure.Template_token.json similarity index 100% rename from tools/apiview/parsers/apiview-treestyle-parser-schema/sample tokens/Azure.Template_token.json rename to tools/apiview/parsers/apiview-treestyle-parser-schema/sample/Azure.Template_token.json diff --git a/tools/apiview/parsers/apiview-treestyle-parser-schema/tspconfig.yaml b/tools/apiview/parsers/apiview-treestyle-parser-schema/tspconfig.yaml index 34626fc9c60..890dfc2011e 100644 --- a/tools/apiview/parsers/apiview-treestyle-parser-schema/tspconfig.yaml +++ b/tools/apiview/parsers/apiview-treestyle-parser-schema/tspconfig.yaml @@ -4,3 +4,6 @@ options: "@typespec/json-schema": file-type: "json" emitter-output-dir: "{project-root}" + bundleId: "CodeFile.json" + emitAllModels: false + emitAllRefs: false \ No newline at end of file