-
Notifications
You must be signed in to change notification settings - Fork 1
Add descriptions to restriction AST type schema #756
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
Merged
yuji38kwmt
merged 2 commits into
main
from
feat/restriction-ast-type-schema-description
May 12, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,7 +32,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| from enum import Enum | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any, NoReturn, cast | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic import BaseModel, ConfigDict, Field, field_serializer, model_validator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic import BaseModel, ConfigDict, Field, GetJsonSchemaHandler, field_serializer, model_validator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic.json_schema import JsonSchemaValue | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic_core import CoreSchema | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| from annofabapi.pydantic_models.additional_data_definition_type import AdditionalDataDefinitionType | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from annofabapi.util.annotation_specs import AnnotationSpecsAccessor, AttributeChoice, AttributeDefinition, get_choice, get_english_message | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -49,7 +51,7 @@ class RestrictionAstType(str, Enum): | |||||||||||||||||||||||||||||||||||||||||||||||||
| IS_EMPTY = "is_empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """属性値が空であることを表すAST種別です。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| IS_NOT_EMPTY = "is_not_empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """属性値が空でないことを表すAST種別です。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """属性値が空でないことを表すAST種別です。必須制約に相当します。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| EQUALS_STRING = "equals_string" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """文字列属性またはtracking属性が指定文字列と一致することを表すAST種別です。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| NOT_EQUALS_STRING = "not_equals_string" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -76,6 +78,44 @@ class RestrictionAstType(str, Enum): | |||||||||||||||||||||||||||||||||||||||||||||||||
| def __str__(self) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return self.value | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @property | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def description(self) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """AST種別の説明文を返します。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return _RESTRICTION_AST_TYPE_DESCRIPTIONS[self] | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| def __get_pydantic_json_schema__(cls, core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """AST種別ごとの説明を含むJSON Schemaを返します。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| json_schema = handler(core_schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| json_schema["oneOf"] = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "const": ast_type.value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "title": ast_type.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "description": ast_type.description, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for ast_type in cls | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return json_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+88
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: JSON Schema のルートに enum 全体の説明が含まれていないため、
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| _RESTRICTION_AST_TYPE_DESCRIPTIONS: dict[RestrictionAstType, str] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.CHECKED: "チェックボックス属性がチェックされていることを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.UNCHECKED: "チェックボックス属性がチェックされていないことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.IS_EMPTY: "属性値が空であることを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.IS_NOT_EMPTY: "属性値が空でないことを表すAST種別です。必須制約に相当します。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+101
to
+105
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.EQUALS_STRING: "文字列属性またはtracking属性が指定文字列と一致することを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.NOT_EQUALS_STRING: "文字列属性またはtracking属性が指定文字列と一致しないことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.MATCHES_STRING: "文字列属性が指定した正規表現に一致することを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.NOT_MATCHES_STRING: "文字列属性が指定した正規表現に一致しないことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.EQUALS_INTEGER: "整数属性が指定した整数値と一致することを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.NOT_EQUALS_INTEGER: "整数属性が指定した整数値と一致しないことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.HAS_CHOICE: "選択属性で指定した選択肢が選ばれていることを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.NOT_HAS_CHOICE: "選択属性で指定した選択肢が選ばれていないことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.HAS_LABEL: "リンク属性が指定したラベル群のいずれかを指すことを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.CAN_INPUT: "属性が編集可能かどうかを表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| RestrictionAstType.IMPLY: "前提を満たす場合に結論を要求する含意制約を表すAST種別です。", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| class Restriction(ABC): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """属性の制約を表すクラス。""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: マッピングに漏れがあると
KeyErrorになる可能性があるため、dict.getを使ってデフォルト値を返すようにガードしてください。 [general, importance: 3]