Add field descriptions to the config schema :)
This commit is contained in:
parent
2def2aece5
commit
3cb5db7528
6 changed files with 84 additions and 23 deletions
|
@ -13,7 +13,12 @@
|
|||
"$ref": "#/definitions/URL"
|
||||
},
|
||||
"cache": {
|
||||
"$ref": "#/definitions/URL"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/URL"
|
||||
}
|
||||
],
|
||||
"description": "A URL describing a cache service for mpd-now-playable to use. Supported protocols are memory://, redis://, and memcached://."
|
||||
},
|
||||
"mpd": {
|
||||
"additionalProperties": false,
|
||||
|
@ -24,14 +29,17 @@
|
|||
"properties": {
|
||||
"host": {
|
||||
"default": "127.0.0.1",
|
||||
"description": "The hostname or IP address of your MPD server. If you're running MPD on your local machine, you don't need to configure this.",
|
||||
"format": "hostname",
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"description": "The password required to connect to your MPD instance, if you need one.",
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"default": 6600,
|
||||
"description": "The port on which to connect to MPD. Unless you're managing multiple MPD servers on one machine for some reason, you probably haven't changed this from the default port, 6600.",
|
||||
"maximum": 65535,
|
||||
"minimum": 1,
|
||||
"type": "integer"
|
||||
|
|
|
@ -11,8 +11,14 @@ __all__ = ("MpdConfig", "Config")
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class MpdConfig:
|
||||
#: The password required to connect to your MPD instance, if you need one.
|
||||
password: Optional[str] = optional()
|
||||
#: The hostname or IP address of your MPD server. If you're running MPD
|
||||
#: on your local machine, you don't need to configure this.
|
||||
host: Host = Host("127.0.0.1")
|
||||
#: The port on which to connect to MPD. Unless you're managing multiple MPD
|
||||
#: servers on one machine for some reason, you probably haven't changed this
|
||||
#: from the default port, 6600.
|
||||
port: Port = Port(6600)
|
||||
|
||||
|
||||
|
@ -22,5 +28,8 @@ class Config:
|
|||
default=URL("https://cdn.00dani.me/m/schemata/mpd-now-playable/config-v1.json"),
|
||||
metadata=alias("$schema"),
|
||||
)
|
||||
|
||||
#: A URL describing a cache service for mpd-now-playable to use. Supported
|
||||
#: protocols are memory://, redis://, and memcached://.
|
||||
cache: Optional[URL] = optional()
|
||||
mpd: MpdConfig = field(default_factory=MpdConfig)
|
||||
|
|
|
@ -3,13 +3,30 @@ from pathlib import Path
|
|||
from pprint import pp
|
||||
from typing import Any, Mapping
|
||||
|
||||
from apischema import schema, settings
|
||||
from apischema.json_schema import JsonSchemaVersion, deserialization_schema
|
||||
from apischema.schemas import Schema
|
||||
from class_doc import extract_docs_from_cls_obj
|
||||
|
||||
from .model import Config
|
||||
|
||||
|
||||
def field_base_schema(tp: type, name: str, alias: str) -> Schema | None:
|
||||
desc_lines = extract_docs_from_cls_obj(tp).get(name, [])
|
||||
if desc_lines:
|
||||
print((tp, name, alias))
|
||||
return schema(description=" ".join(desc_lines))
|
||||
return None
|
||||
|
||||
|
||||
settings.base_schema.field = field_base_schema
|
||||
|
||||
|
||||
def generate() -> Mapping[str, Any]:
|
||||
return deserialization_schema(Config, version=JsonSchemaVersion.DRAFT_7)
|
||||
return deserialization_schema(
|
||||
Config,
|
||||
version=JsonSchemaVersion.DRAFT_7,
|
||||
)
|
||||
|
||||
|
||||
def write() -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue