Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solido Smithy

Generates Smithy models from Solido DTO metadata.

This package is currently experimental. It provides package-owned Smithy metadata attributes, a DTO metadata extractor, a small intermediate API model, optional Symfony route operation extraction, and a deterministic Smithy IDL renderer.

Installation

composer require solido/smithy

Usage

use Solido\Smithy\Extractor\DtoMetadataExtractor;
use Solido\Smithy\GeneratorConfig;
use Solido\Smithy\Renderer\SmithyIdlRenderer;
use Solido\Smithy\SmithyGenerator;
use Solido\Smithy\Type\TypeOverride;

$generator = new SmithyGenerator(
    new DtoMetadataExtractor($resolver),
    new SmithyIdlRenderer(),
);

$smithy = $generator->generate(new GeneratorConfig(
    namespace: 'com.example.api',
    serviceName: 'ExampleService',
    dtoNamespaces: ['App\\DTO'],
    typeOverrides: [
        TypeOverride::type(App\ValueObject\UserId::class, 'String'),
        TypeOverride::member(App\DTO\v1\v1_0\User::class, 'id', 'smithy.api#String'),
    ],
));

Use generateResult() when diagnostics or the intermediate model are needed:

$result = $generator->generateResult(new GeneratorConfig(
    namespace: 'com.example.api',
    serviceName: 'ExampleService',
    dtoNamespaces: ['App\\DTO'],
));

foreach ($result->diagnostics() as $diagnostic) {
    // Surface warnings in CI or in an application command.
}

CLI

vendor/bin/solido-smithy \
  --namespace=com.example.api \
  --service-name=ExampleService \
  --dto-namespace='App\DTO' \
  --output=build/smithy/model.smithy

Supported Metadata

  • Solido\Smithy\Attribute\HttpHeader
  • Solido\Smithy\Attribute\HttpLabel
  • Solido\Smithy\Attribute\HttpPayload
  • Solido\Smithy\Attribute\IgnoreInput
  • Solido\Smithy\Attribute\IgnoreOutput
  • Solido\Smithy\Attribute\InputName
  • Solido\Smithy\Attribute\ListOutput
  • Solido\Smithy\Attribute\MemberName
  • Solido\Smithy\Attribute\SolidoList
  • type overrides configured with Solido\Smithy\Type\TypeOverride
  • PHPDoc list types such as Project[], rendered as Smithy list shapes when the element class can be resolved
  • Symfony #[Route] attributes, when symfony/routing is installed
  • KCS serializer SerializedName, Exclude, and VirtualProperty attributes, when kcs/serializer is installed
  • Symfony validator NotBlank and NotNull constraints, when symfony/validator is installed

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages