Skip to content

Class Names Glob Patterns

Vojtěch Habarta edited this page Sep 29, 2020 · 2 revisions

Typescript-generator input classes can be specified using classPatterns parameter which is a list of glob patterns. Any class whose name matches any of the specified patterns will be included unless it is explicitly excluded. This parameter can be combined with other input parameters (classes and classesFromJaxrsApplication).

Note: class dependencies will be also included even if they do not match any pattern (for example if class A has a propery of type B then B will be also included regardless of its name). This transitive mechanism applies to all input parameters.

Classes can be excluded one by one by using excludeClasses parameter. It is also possible to exclude multiple classes at once by using excludeClassPatterns parameter.

Globbing syntax

Class name glob patterns support two wildcards.

  • Single * wildcard matches any character except for . and $.
  • Double ** wildcard matches any character.

Example patterns

  • cz.habarta.example.* - pattern for classes in cz.habarta.example package
  • cz.habarta.example.** - pattern for classes in cz.habarta.example package and all sub-packages
  • cz.habarta.**Json - pattern for classes ending with Json suffix
  • **.dto.* - pattern for classes in any dto package
  • **$Companion - pattern useful for excluding Kotlin companion objects

Maven example

<plugin>
    <groupId>cz.habarta.typescript-generator</groupId>
    <artifactId>typescript-generator-maven-plugin</artifactId>
    <version>1.7.x</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <phase>process-classes</phase>
            <configuration>
                <jsonLibrary>jackson2</jsonLibrary>
                <classPatterns>
                    <pattern>cz.habarta.example.*</pattern>
                    <pattern>cz.habarta.example.data.**</pattern>
                    <pattern>cz.habarta.example.rest.*</pattern>
                </classPatterns>
                <excludeClasses>
                    <class>cz.habarta.example.Application</class>
                </excludeClasses>
                <outputFile>target/rest.d.ts</outputFile>
                <outputKind>global</outputKind>
            </configuration>
        </execution>
    </executions>
</plugin>

JAX-RS Application

If you have JAX-RS Application it is recommended to specify input classes using classesFromJaxrsApplication parameter instead of using globbing. For more information see JAX RS Application.

Tip: as mentioned before classes are included transitively. But sometimes whole chain of classes is discovered unintentionally so it is practical to use excludeClasses parameter to exclude root of this chain or tree. For example if class A which is explicitly included has a property of type B, class B has C and class C has D it is sufficient to exclude class B to exclude B, C and D and process class A only.

Clone this wiki locally