updates 33.1 84
This commit is contained in:
@@ -13,7 +13,7 @@ Expects the folder to have an __init__.py that exports:
|
||||
import dataclasses as dc
|
||||
import importlib.util
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Type, get_type_hints
|
||||
@@ -32,6 +32,10 @@ class FieldDefinition:
|
||||
primary_key: bool = False
|
||||
foreign_key: Optional[str] = None # target model name
|
||||
unique: bool = False
|
||||
# True when foreign_key points at many rows rather than one — an array of
|
||||
# $ref, a m2m table. graphgen renders the two differently, so losing the
|
||||
# distinction would draw every collection as a single edge.
|
||||
many: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -60,6 +64,51 @@ class GrpcServiceDefinition:
|
||||
methods: List[Dict[str, Any]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class EndpointDefinition:
|
||||
"""Represents one HTTP operation on a service.
|
||||
|
||||
Models describe the shapes a service passes around; endpoints describe how
|
||||
it is called. Loaders that read a service contract (OpenAPI) or infer one
|
||||
(tabular) emit these alongside the models, and shuntgen turns them into
|
||||
routes. Loaders that only see shapes — dataclasses, a Django app — emit
|
||||
none, which is why this is not part of the BaseExtractor contract.
|
||||
"""
|
||||
|
||||
method: str # GET, POST, ...
|
||||
path: str # /pets/{petId}
|
||||
operation_id: Optional[str] = None
|
||||
summary: Optional[str] = None
|
||||
# "collection" returns/accepts many, "item" one, "action" neither.
|
||||
kind: str = "item"
|
||||
model: Optional[str] = None # what this operation is about
|
||||
request_model: Optional[str] = None
|
||||
response_model: Optional[str] = None
|
||||
response_is_list: bool = False
|
||||
# Set when the collection arrives wrapped — {"items": [...], "total": n}
|
||||
# rather than a bare array. Answering a wrapped endpoint with an array is
|
||||
# the kind of mismatch a client only discovers at parse time.
|
||||
envelope_key: Optional[str] = None
|
||||
status: int = 200
|
||||
path_params: List[str] = field(default_factory=list)
|
||||
example: Any = None # response example carried through from the source
|
||||
|
||||
|
||||
@dataclass
|
||||
class DatasetDefinition:
|
||||
"""Concrete rows harvested next to a model.
|
||||
|
||||
Importing a spreadsheet yields both a shape and the data that shaped it.
|
||||
Throwing the rows away would mean generating a service that answers with
|
||||
invented values when the real ones were right there.
|
||||
"""
|
||||
|
||||
model: str
|
||||
rows: List[Dict[str, Any]] = field(default_factory=list)
|
||||
source: Optional[str] = None # file the rows came from
|
||||
collection: Optional[str] = None # url-facing name, e.g. "customers"
|
||||
|
||||
|
||||
class SchemaLoader:
|
||||
"""Loads model definitions from Python dataclasses in schema/ folder."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user