Class MirageApiDetectorExtension

java.lang.Object
com.arc_e_tect.gradle.mirage.MirageApiDetectorExtension

public abstract class MirageApiDetectorExtension extends Object
DSL extension for the Mirage API Detector Gradle plugin.
 mirageApiDetector {
     controllerDirs.from('src/main/java')                                    // default
     rootDocument   = file('src/main/resources/openapi/openapi.yaml')       // required
     // openApiDir  = rootDocument.get().asFile.parentFile                  // default
     scanMocks      = false                                                  // default
     // stubDirs.from('src/test/resources/mappings')                       // default; used only when scanMocks = true
     failOnMirage   = false                                                  // default
     reportDir      = layout.buildDirectory.dir('reports/mirage-api-detector') // default
     reportFileName = 'mirage-apis.adoc'                                     // default
     // systemUnderTestVersion = 'v1.0.0'          // optional; default: project.version
     trackContractHistory  = false                                           // default
     // contractHistoryFile = file('mirage-api-detector-contract-history.ndjson') // default
     updateContractHistory = trackContractHistory                            // default; see getUpdateContractHistory()
 }
 

updateContractHistory can be overridden for the whole build from the command line, e.g. -PmirageApiDetector.updateContractHistory=true - see getUpdateContractHistory().

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default name of the persisted contract progress history file.
    static final String
    Default relative path of the directory searched for @RestController classes.
    static final String
    Default name of the generated AsciiDoc report file.
    static final String
    Default relative path of the directory searched for WireMock stub mapping files.
    static final String
    Extension DSL block name, i.e.
    static final String
    Name of the Gradle project property that overrides getUpdateContractHistory() from the command line for every project in the build, e.g.
  • Constructor Summary

    Constructors
    Constructor
    Description
    For use by the Gradle-generated concrete subclass.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract org.gradle.api.file.RegularFileProperty
    File that the persisted contract progress history is read from and, when getUpdateContractHistory() is true, written back to.
    abstract org.gradle.api.file.ConfigurableFileCollection
    Directories to search recursively for @RestController classes, used to determine which OpenAPI operations are implemented.
    abstract org.gradle.api.provider.Property<Boolean>
    Whether the build should fail when mirage APIs are found.
    abstract org.gradle.api.file.DirectoryProperty
    Directory where OpenAPI descriptions are stored.
    abstract org.gradle.api.file.DirectoryProperty
    Directory the AsciiDoc report is written to.
    abstract org.gradle.api.provider.Property<String>
    Name of the generated AsciiDoc report file (without path).
    abstract org.gradle.api.file.RegularFileProperty
    The root OpenAPI document describing the API.
    abstract org.gradle.api.provider.Property<Boolean>
    Whether to determine implemented endpoints from WireMock stub mapping files under getStubDirs() instead of scanning @RestController classes under getControllerDirs().
    abstract org.gradle.api.file.ConfigurableFileCollection
    Directories to search recursively for WireMock stub mapping files (*.json), used to determine implemented endpoints when getScanMocks() is true.
    abstract org.gradle.api.provider.Property<String>
    Version of the system under test whose @RestController classes are scanned, printed in the generated report as e.g.
    abstract org.gradle.api.provider.Property<Boolean>
    Whether to persist, across builds, a history of when each endpoint first reached each stage of its contract lifecycle - declared, implemented, verified - keyed by a fingerprint of its HTTP verb and path so the history is shared correctly with Shadow and Doppelganger API Detector when they're pointed at the same getContractHistoryFile().
    abstract org.gradle.api.provider.Property<Boolean>
    Whether getContractHistoryFile() is written back to disk after being updated with the current run's endpoints.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NAME

      public static final String NAME
      Extension DSL block name, i.e. the name used to register the extension with the project.
      See Also:
    • DEFAULT_CONTROLLER_DIR

      public static final String DEFAULT_CONTROLLER_DIR
      Default relative path of the directory searched for @RestController classes.
      See Also:
    • DEFAULT_STUB_DIR

      public static final String DEFAULT_STUB_DIR
      Default relative path of the directory searched for WireMock stub mapping files.
      See Also:
    • DEFAULT_REPORT_FILE_NAME

      public static final String DEFAULT_REPORT_FILE_NAME
      Default name of the generated AsciiDoc report file.
      See Also:
    • DEFAULT_CONTRACT_HISTORY_FILE_NAME

      public static final String DEFAULT_CONTRACT_HISTORY_FILE_NAME
      Default name of the persisted contract progress history file.
      See Also:
    • UPDATE_CONTRACT_HISTORY_OVERRIDE_PROPERTY

      public static final String UPDATE_CONTRACT_HISTORY_OVERRIDE_PROPERTY
      Name of the Gradle project property that overrides getUpdateContractHistory() from the command line for every project in the build, e.g. -PmirageApiDetector.updateContractHistory=true. Takes precedence over any project's own configured updateContractHistory value. The value is parsed as a boolean.
      See Also:
  • Constructor Details

    • MirageApiDetectorExtension

      public MirageApiDetectorExtension()
      For use by the Gradle-generated concrete subclass.
  • Method Details

    • getControllerDirs

      public abstract org.gradle.api.file.ConfigurableFileCollection getControllerDirs()
      Directories to search recursively for @RestController classes, used to determine which OpenAPI operations are implemented. Not scanned when getScanMocks() is true. One or more directories may be configured. Defaults to "src/main/java".
      Returns:
      mutable file collection of controller source directories
    • getScanMocks

      public abstract org.gradle.api.provider.Property<Boolean> getScanMocks()
      Whether to determine implemented endpoints from WireMock stub mapping files under getStubDirs() instead of scanning @RestController classes under getControllerDirs(). When true, controller directories are not scanned at all: an OpenAPI operation is a mirage API here when no stub mocks it, rather than when no controller implements it. Defaults to false.
      Returns:
      mutable boolean property controlling whether stub-based scanning is used
    • getStubDirs

      public abstract org.gradle.api.file.ConfigurableFileCollection getStubDirs()
      Directories to search recursively for WireMock stub mapping files (*.json), used to determine implemented endpoints when getScanMocks() is true. One or more directories may be configured. Defaults to "src/test/resources/mappings".
      Returns:
      mutable file collection of WireMock stub directories
    • getRootDocument

      public abstract org.gradle.api.file.RegularFileProperty getRootDocument()
      The root OpenAPI document describing the API. Required: every other OpenAPI document is expected to be reachable from this one via $ref links relative to it.
      Returns:
      mutable file property for the root OpenAPI document
    • getOpenApiDir

      public abstract org.gradle.api.file.DirectoryProperty getOpenApiDir()
      Directory where OpenAPI descriptions are stored. Used only to determine which files the task should track as inputs for up-to-date checks; every document actually consulted is discovered by following the $ref links reachable from getRootDocument(). Defaults to the root document's own parent directory.
      Returns:
      mutable directory property for the OpenAPI description directory
    • getFailOnMirage

      public abstract org.gradle.api.provider.Property<Boolean> getFailOnMirage()
      Whether the build should fail when mirage APIs are found. The report is written either way. Defaults to false.
      Returns:
      mutable boolean property controlling whether the build fails on mirage APIs
    • getReportDir

      public abstract org.gradle.api.file.DirectoryProperty getReportDir()
      Directory the AsciiDoc report is written to. Defaults to build/reports/mirage-api-detector.
      Returns:
      mutable directory property for the report output directory
    • getReportFileName

      public abstract org.gradle.api.provider.Property<String> getReportFileName()
      Name of the generated AsciiDoc report file (without path). Defaults to "mirage-apis.adoc".
      Returns:
      mutable string property for the report file name
    • getSystemUnderTestVersion

      public abstract org.gradle.api.provider.Property<String> getSystemUnderTestVersion()
      Version of the system under test whose @RestController classes are scanned, printed in the generated report as e.g. System Under Test version: v1.0.0. Defaults to the project's own version (as set in the build file or a properties file); set this property to override that default, e.g. when the controllers scanned belong to a different artifact than the one being built.
      Returns:
      mutable string property for the system-under-test version
    • getTrackContractHistory

      public abstract org.gradle.api.provider.Property<Boolean> getTrackContractHistory()
      Whether to persist, across builds, a history of when each endpoint first reached each stage of its contract lifecycle - declared, implemented, verified - keyed by a fingerprint of its HTTP verb and path so the history is shared correctly with Shadow and Doppelganger API Detector when they're pointed at the same getContractHistoryFile(). Defaults to false.

      The history file configured via getContractHistoryFile() is always read when this property is true, regardless of getUpdateContractHistory().

      Returns:
      mutable boolean property controlling whether contract progress history is tracked
    • getContractHistoryFile

      public abstract org.gradle.api.file.RegularFileProperty getContractHistoryFile()
      File that the persisted contract progress history is read from and, when getUpdateContractHistory() is true, written back to. Defaults to "mirage-api-detector-contract-history.ndjson" directly in the project directory - deliberately not under build/, since this file is meant to be committed to version control so the history survives across checkouts. Only consulted when getTrackContractHistory() is true.
      Returns:
      mutable file property for the contract history file
    • getUpdateContractHistory

      public abstract org.gradle.api.provider.Property<Boolean> getUpdateContractHistory()
      Whether getContractHistoryFile() is written back to disk after being updated with the current run's endpoints. Defaults to the same value as getTrackContractHistory(). Only consulted when getTrackContractHistory() is true; the history file is always read regardless of this property's value, so a build with this set to false still reports against the up-to-date-in-memory history, it simply doesn't persist it.

      The "mirageApiDetector.updateContractHistory" project property, when set (e.g. -PmirageApiDetector.updateContractHistory=true), overrides this property for every project in the build regardless of what any project configures here - typically driven from a Gradle property set differently per branch in the CI pipeline, since the plugin itself has no notion of which branch is currently checked out.

      Returns:
      mutable boolean property controlling whether the contract history file is written back