Package: sinch-spectre
⚠️⚠️⚠️ This project was moved toTHISnew repository ⚠️⚠️⚠️SpectreOverviewCLI tool for generating code and config from generic, language-agnostic data model specifications based on JSON.
All spectre related files should be in a subdirectory calledspectrein your project dir. This will also be where generated files appear.See theGeneratorssection for more information about what is possible to generate.You can runspectre generatewithout arguments to learn the possible commands and options.QuickstartBegin with creating an entity. This can be done in several waysWriting a .spec file manuallyFrom the interactive wizard in the CLI:spectre create entityImportinga MySQL table descriptionThis file can then be used to generate code and other artifacts. This is done with commands of the formatspectre generate artifactType pathToSpec --someOption.Example:spectre generate java --all MyEntity.specEntitiesThe core of Spectre is theentityconcept. An entity is something like a resource, the data model that the app concerns itself with.
The idea is that a big part of what applications do is passing data back and forth and reading/writing to databases.
If one knows how the data looks it is possible to generate those parts of the application, since they generally function in the same way.
The entities are specified in JSON.Example{
  "foo_type": {
    "description": "a demonstration entity",
    "fields": [
      {
        "name": "bar",
        "type": "string",
        "description": "Explanatory text about bar, these next properties are optional",
        "required": true,
        "example": "sample_value_123",
      },
      {
        "name": "baz",
        "type": "int",
      },
      {
        "name": "guid",
        "type": "uuid",
        "description": "Internal unique ID for the entity,
        "required": true,
      }
    ]
  }
}You can find more examples in thesample-datadir.TypesSpectre has its own internal types that are intended to correspond to common programming constructs. They don't always map 1:1 with the datatypes in the target language, and sometimes the generation is less than perfect. Improving this is a work in progress.The following types are supported:INTSTRINGBOOLFLOATENUM  #This is only partially supported currently, in Java it will end up as a StringTIMESTAMPUUIDUNDEFINED #Shouldn't be used, this is for when something has gone wrongThere is currently no support for nested entity types or objects. It's a nice-to-have feature that might end up being implemented later.ConfigYou can create a config file to set some metadata about your generated code, for example a namespace that will be used in package declarations.To create a config, use the commandspectre create configor write it in a YAML file and place inspectre/spectre.yml.The config system is early in development and may be subject to change. Sorry for any breaking changes.GeneratorsMultiple different generators are available. Adding a new one is fairly quick.JavaThis can generate various different classes relating to an entity, many of them use the Spring framework. They are available as switches in the CLI, or alternatively the--allswitch can be used to generate everything.ModelThis entity is always generated and corresponds to the POJO for the entity. If generated with the--spring-dataflag, this will be a JPA entity with database annotations.DTOA copy of the model without annotations, in a separate package for DTO:s. Enabled with the--dtoflag.RepositoryA Spring Data repository interfaces for themodelclass, with some standard methods specified for clarity. Enabled with the--spring-dataflag.ManagerAn abstraction to encapsulate the repository and place to add business logic around CRUD operations. Enabled with the--managerflag.REST ControllerA Spring Web controller that provides a CRUD like interface for themodel entityover REST by wrapping themanager. Enabled with the--spring-webflag.ProtoGenerates a protofile with messages and a CRUD-like service.LiquibaseGenerates a liquibase changelog for a database schema matching the entityJhipsterGenerates JHipster JDL files which in turn can be used to generate Java code with their generator. This is quite similar to the code generated by the Java generator, so if not already heavily invested in JHipster framework the vanilla Java generator may be a better choice if not wanting to commit to their ecosystem.API.jsonGenerates anapi.jsonspecification that can be used to generate other code from the apibuilder tool. NB: We never ended up using this so support may be poor/broken.