Skip to content

GeneratedCode

🛈 DocStrings

Structured code generation result.

Source code in src/schemez/code_generation/toolset_code_generator.py
@dataclass
class GeneratedCode:
    """Structured code generation result."""

    models: str
    """Generated Pydantic input models."""

    http_methods: str
    """HTTP client methods using models."""

    clean_methods: str
    """Clean signature methods without models."""

    model_stubs: str
    """Model-based function stubs for LLM consumption."""

    explicit_stubs: str
    """Explicit signature function stubs for LLM consumption."""

    imports: str = ""
    """Common imports."""

    def get_client_code(
        self,
        args_format: ArgsFormat = "explicit",
        output_type: OutputType = "implementation",
        client_type: ClientType = "http",
    ) -> str:
        """Generate client code with specified format and type.

        Args:
            args_format: Argument format - "model" (with Pydantic models) or
                "explicit" (function signatures)
            output_type: Output type - "stubs" (type stubs) or
                "implementation" (working client)
            client_type: Client type - "http" or "fastmcp"

        Returns:
            Formatted client code
        """
        parts = []

        match (args_format, output_type):
            case ("model", "implementation"):
                # Client with models
                if self.imports:
                    parts.append(self.imports)
                if self.models:
                    parts.append(self.models)
                if self.http_methods:
                    parts.append(self.http_methods)

            case ("explicit", "implementation"):
                # Client with explicit signatures
                if self.imports:
                    parts.append(self.imports)
                if self.clean_methods:
                    parts.append(self.clean_methods)

            case ("model", "stubs"):
                # Model-based stubs for LLM consumption
                parts.append(STUB_IMPORTS)
                if self.models:
                    parts.append(self.models)
                if self.model_stubs:
                    parts.append(self.model_stubs)

            case ("explicit", "stubs"):
                # Explicit signature stubs for LLM consumption
                parts.append(STUB_IMPORTS)
                if self.explicit_stubs:
                    parts.append(self.explicit_stubs)

            case _:
                msg = f"Unknown combination: args_format={args_format}, output_type={output_type}"
                raise ValueError(msg)

        return "\n\n".join(parts)

clean_methods instance-attribute

clean_methods: str

Clean signature methods without models.

explicit_stubs instance-attribute

explicit_stubs: str

Explicit signature function stubs for LLM consumption.

http_methods instance-attribute

http_methods: str

HTTP client methods using models.

imports class-attribute instance-attribute

imports: str = ''

Common imports.

model_stubs instance-attribute

model_stubs: str

Model-based function stubs for LLM consumption.

models instance-attribute

models: str

Generated Pydantic input models.

get_client_code

get_client_code(
    args_format: ArgsFormat = "explicit",
    output_type: OutputType = "implementation",
    client_type: ClientType = "http",
) -> str

Generate client code with specified format and type.

Parameters:

Name Type Description Default
args_format ArgsFormat

Argument format - "model" (with Pydantic models) or "explicit" (function signatures)

'explicit'
output_type OutputType

Output type - "stubs" (type stubs) or "implementation" (working client)

'implementation'
client_type ClientType

Client type - "http" or "fastmcp"

'http'

Returns:

Type Description
str

Formatted client code

Source code in src/schemez/code_generation/toolset_code_generator.py
def get_client_code(
    self,
    args_format: ArgsFormat = "explicit",
    output_type: OutputType = "implementation",
    client_type: ClientType = "http",
) -> str:
    """Generate client code with specified format and type.

    Args:
        args_format: Argument format - "model" (with Pydantic models) or
            "explicit" (function signatures)
        output_type: Output type - "stubs" (type stubs) or
            "implementation" (working client)
        client_type: Client type - "http" or "fastmcp"

    Returns:
        Formatted client code
    """
    parts = []

    match (args_format, output_type):
        case ("model", "implementation"):
            # Client with models
            if self.imports:
                parts.append(self.imports)
            if self.models:
                parts.append(self.models)
            if self.http_methods:
                parts.append(self.http_methods)

        case ("explicit", "implementation"):
            # Client with explicit signatures
            if self.imports:
                parts.append(self.imports)
            if self.clean_methods:
                parts.append(self.clean_methods)

        case ("model", "stubs"):
            # Model-based stubs for LLM consumption
            parts.append(STUB_IMPORTS)
            if self.models:
                parts.append(self.models)
            if self.model_stubs:
                parts.append(self.model_stubs)

        case ("explicit", "stubs"):
            # Explicit signature stubs for LLM consumption
            parts.append(STUB_IMPORTS)
            if self.explicit_stubs:
                parts.append(self.explicit_stubs)

        case _:
            msg = f"Unknown combination: args_format={args_format}, output_type={output_type}"
            raise ValueError(msg)

    return "\n\n".join(parts)

:fa-brands-github: Show source on GitHub