Class DoppelgangerApiDetectorExtension
doppelgangerApiDetector {
controllerDirs.from('src/main/java') // default
testDirs.from('src/testContract/java') // default
rootDocument = file('src/main/resources/openapi/openapi.yaml') // required
// openApiDir = rootDocument.get().asFile.parentFile // default
// contractsDir = file('src/testContract/resources/contracts') // required if useSpringCloudContract = true
useRestDocs = true // default
useOpenApiRequestValidator = false // default
useSpringCloudContract = false // default
failOnDoppelganger = false // default
reportDir = layout.buildDirectory.dir('reports/doppelganger-api-detector') // default
reportFileName = 'doppelganger-apis.adoc' // default
// systemUnderTestVersion = 'v1.0.0' // optional; default: project.version
trackContractHistory = false // default
// contractHistoryFile = file('doppelganger-api-detector-contract-history.ndjson') // default
updateContractHistory = trackContractHistory // default; see getUpdateContractHistory()
// excludePaths.add('/actuator/health') // default: empty
// excludeFiles.from('doppelganger-exclusions.yaml') // default: empty
// excludeWellKnown.add('spring-boot-actuator') // default: empty
// Configuration for the separate `scanContracts` task - reuses controllerDirs, testDirs,
// rootDocument, contractsDir, useRestDocs/useOpenApiRequestValidator/useSpringCloudContract,
// and the exclude* properties above.
includeResponseCoverage = false // default
// scanContractsReportFileName = 'contract-coverage.adoc' // default
trackResponseCoverageHistory = false // default
// responseCoverageHistoryFile = file('doppelganger-api-detector-response-coverage-history.ndjson') // default
updateResponseCoverageHistory = trackResponseCoverageHistory // default; see getUpdateResponseCoverageHistory()
}
updateContractHistory can be overridden for the whole build from the command line,
e.g. -PdoppelgangerApiDetector.updateContractHistory=true - see
getUpdateContractHistory(). updateResponseCoverageHistory has its own,
independent override - see getUpdateResponseCoverageHistory().
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault name of the persisted contract progress history file.static final StringSuggested relative path of the directory searched for Spring Cloud Contract DSL files, shown in the DSL example above.static final StringDefault relative path of the directory searched for@RestControllerclasses.static final StringDefault name of the generated AsciiDoc report file.static final StringDefault name of the persisted response coverage history file.static final StringDefault name of thescanContractstask's generated AsciiDoc report file.static final StringDefault relative path of the directory searched for test classes.static final StringExtension DSL block name, i.e.static final StringName of the Gradle project property that overridesgetUpdateContractHistory()from the command line for every project in the build, e.g.static final StringName of the Gradle project property that overridesgetUpdateResponseCoverageHistory()from the command line for every project in the build, e.g. -
Constructor Summary
ConstructorsConstructorDescriptionFor use by the Gradle-generated concrete subclass. -
Method Summary
Modifier and TypeMethodDescriptionabstract org.gradle.api.file.RegularFilePropertyFile that the persisted contract progress history is read from and, whengetUpdateContractHistory()istrue, written back to.abstract org.gradle.api.file.DirectoryPropertyDirectory searched for Spring Cloud Contract DSL files (*.groovyand*.yml), scanned recursively whengetUseSpringCloudContract()istrue.abstract org.gradle.api.file.ConfigurableFileCollectionDirectories to search recursively for@RestControllerclasses.abstract org.gradle.api.file.ConfigurableFileCollectionOne or more YAML files of exclusion rules, in the same format bundled well-known sets use:abstract org.gradle.api.provider.ListProperty<String> Exclusion rule strings, parsed byExclusionRule.parse(String)- e.g.abstract org.gradle.api.provider.ListProperty<String> Names of bundled, well-known exclusion sets to apply - e.g.abstract org.gradle.api.provider.Property<Boolean> Whether the build should fail when doppelganger APIs are found.abstract org.gradle.api.provider.Property<Boolean> Whether thescanContractstask additionally computes, for every declared response code, how many contract tests cover it.abstract org.gradle.api.file.DirectoryPropertyDirectory where OpenAPI descriptions are stored.abstract org.gradle.api.file.DirectoryPropertyDirectory 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.RegularFilePropertyFile that the persisted response coverage history is read from and, whengetUpdateResponseCoverageHistory()istrue, written back to.abstract org.gradle.api.file.RegularFilePropertyThe root OpenAPI document describing the API.abstract org.gradle.api.provider.Property<String> Name of thescanContractstask's generated AsciiDoc report file (without path), written to the samegetReportDir().abstract org.gradle.api.provider.Property<String> Version of the system under test whose@RestControllerclasses are scanned, printed in the generated report as e.g.abstract org.gradle.api.file.ConfigurableFileCollectionDirectories to search recursively for test classes, scanned by the Spring RestDocs and OpenAPI request validator verification sources when enabled.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 Mirage API Detector when they're pointed at the samegetContractHistoryFile().abstract org.gradle.api.provider.Property<Boolean> Whether to persist, across builds, a history of response code coverage - keyed by endpoint fingerprint and response code, tracking a live test-count gauge rather than milestone timestamps.abstract org.gradle.api.provider.Property<Boolean> WhethergetContractHistoryFile()is written back to disk after being updated with the current run's endpoints.abstract org.gradle.api.provider.Property<Boolean> WhethergetResponseCoverageHistoryFile()is written back to disk after being updated with the current run's coverage.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Atlassian OpenAPI request validator usage as verification evidence.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Spring RestDocs test methods as verification evidence: either aspring-restdocs-mockmvcmockMvc.perform(...)call paired with.andDo(document(...)), aspring-restdocs-webtestclientwebTestClient.get()/post()/put()/delete()/patch().uri(...).exchange()...chain paired with.consumeWith(document(...)), or aspring-restdocs-restassured.filter(document(...))paired with awhen().get(...)/post(...)/...call.abstract org.gradle.api.provider.Property<Boolean> Whether to treat Spring Cloud Contract DSL files undergetContractsDir()as verification evidence.
-
Field Details
-
NAME
Extension DSL block name, i.e. the name used to register the extension with the project.- See Also:
-
DEFAULT_CONTROLLER_DIR
Default relative path of the directory searched for@RestControllerclasses.- See Also:
-
DEFAULT_TEST_DIR
Default relative path of the directory searched for test classes.- See Also:
-
DEFAULT_CONTRACTS_DIR
Suggested relative path of the directory searched for Spring Cloud Contract DSL files, shown in the DSL example above. Not applied as a convention default - seegetContractsDir().- See Also:
-
DEFAULT_REPORT_FILE_NAME
Default name of the generated AsciiDoc report file.- See Also:
-
DEFAULT_CONTRACT_HISTORY_FILE_NAME
Default name of the persisted contract progress history file.- See Also:
-
UPDATE_CONTRACT_HISTORY_OVERRIDE_PROPERTY
Name of the Gradle project property that overridesgetUpdateContractHistory()from the command line for every project in the build, e.g.-PdoppelgangerApiDetector.updateContractHistory=true. Takes precedence over any project's own configuredupdateContractHistoryvalue. The value is parsed as a boolean.- See Also:
-
DEFAULT_SCAN_CONTRACTS_REPORT_FILE_NAME
Default name of thescanContractstask's generated AsciiDoc report file.- See Also:
-
DEFAULT_RESPONSE_COVERAGE_HISTORY_FILE_NAME
Default name of the persisted response coverage history file.- See Also:
-
UPDATE_RESPONSE_COVERAGE_HISTORY_OVERRIDE_PROPERTY
Name of the Gradle project property that overridesgetUpdateResponseCoverageHistory()from the command line for every project in the build, e.g.-PdoppelgangerApiDetector.updateResponseCoverageHistory=true. Takes precedence over any project's own configuredupdateResponseCoverageHistoryvalue. The value is parsed as a boolean.- See Also:
-
-
Constructor Details
-
DoppelgangerApiDetectorExtension
public DoppelgangerApiDetectorExtension()For use by the Gradle-generated concrete subclass.
-
-
Method Details
-
getControllerDirs
public abstract org.gradle.api.file.ConfigurableFileCollection getControllerDirs()Directories to search recursively for@RestControllerclasses. One or more directories may be configured. Defaults to "src/main/java".- Returns:
- mutable file collection of controller source directories
-
getTestDirs
public abstract org.gradle.api.file.ConfigurableFileCollection getTestDirs()Directories to search recursively for test classes, scanned by the Spring RestDocs and OpenAPI request validator verification sources when enabled. One or more directories may be configured. Defaults to "src/testContract/java".- Returns:
- mutable file collection of test source 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$reflinks 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$reflinks reachable fromgetRootDocument(). Defaults to the root document's own parent directory.- Returns:
- mutable directory property for the OpenAPI description directory
-
getContractsDir
public abstract org.gradle.api.file.DirectoryProperty getContractsDir()Directory searched for Spring Cloud Contract DSL files (*.groovyand*.yml), scanned recursively whengetUseSpringCloudContract()istrue.Deliberately has no convention default, unlike this plugin's other directory properties: enabling
getUseSpringCloudContract()without configuring this property is a DSL configuration error, not a bootstrapping gap -detectDoppelgangerApisfails eagerly in that case, rather than silently falling back to a guessed location. SeeDetectDoppelgangerApisTask.generate().- Returns:
- mutable directory property for the Spring Cloud Contract directory
-
getUseRestDocs
Whether to treat Spring RestDocs test methods as verification evidence: either aspring-restdocs-mockmvcmockMvc.perform(...)call paired with.andDo(document(...)), aspring-restdocs-webtestclientwebTestClient.get()/post()/put()/delete()/patch().uri(...).exchange()...chain paired with.consumeWith(document(...)), or aspring-restdocs-restassured.filter(document(...))paired with awhen().get(...)/post(...)/...call. Paths captured from a running-server style verification (REST Assured) have any leading segment matchinggetRootDocument()'s firstservers[].urlpath stripped before comparison, since that path is typically a servlet context path neither the OpenAPI documentation nor the@RestControllermapping itself declares. Defaults totrue.- Returns:
- mutable boolean property controlling whether the Spring RestDocs source is enabled
-
getUseOpenApiRequestValidator
Whether to treat Atlassian OpenAPI request validator usage as verification evidence. Defaults tofalse.- Returns:
- mutable boolean property controlling whether the OpenAPI request validator source is enabled
-
getUseSpringCloudContract
Whether to treat Spring Cloud Contract DSL files undergetContractsDir()as verification evidence. Defaults tofalse.- Returns:
- mutable boolean property controlling whether the Spring Cloud Contract source is enabled
-
getFailOnDoppelganger
Whether the build should fail when doppelganger APIs are found. The report is written either way. Defaults tofalse.- Returns:
- mutable boolean property controlling whether the build fails on doppelganger APIs
-
getReportDir
public abstract org.gradle.api.file.DirectoryProperty getReportDir()Directory the AsciiDoc report is written to. Defaults tobuild/reports/doppelganger-api-detector.- Returns:
- mutable directory property for the report output directory
-
getReportFileName
Name of the generated AsciiDoc report file (without path). Defaults to "doppelganger-apis.adoc".- Returns:
- mutable string property for the report file name
-
getSystemUnderTestVersion
Version of the system under test whose@RestControllerclasses are scanned, printed in the generated report as e.g.System Under Test version: v1.0.0. Defaults to the project's ownversion(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
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 Mirage API Detector when they're pointed at the samegetContractHistoryFile(). Defaults tofalse.The history file configured via
getContractHistoryFile()is always read when this property istrue, regardless ofgetUpdateContractHistory().- 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, whengetUpdateContractHistory()istrue, written back to. Defaults to "doppelganger-api-detector-contract-history.ndjson" directly in the project directory - deliberately not underbuild/, since this file is meant to be committed to version control so the history survives across checkouts. Only consulted whengetTrackContractHistory()istrue.- Returns:
- mutable file property for the contract history file
-
getUpdateContractHistory
WhethergetContractHistoryFile()is written back to disk after being updated with the current run's endpoints. Defaults to the same value asgetTrackContractHistory(). Only consulted whengetTrackContractHistory()istrue; the history file is always read regardless of this property's value, so a build with this set tofalsestill reports against the up-to-date-in-memory history, it simply doesn't persist it.The "doppelgangerApiDetector.updateContractHistory" project property, when set (e.g.
-PdoppelgangerApiDetector.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
-
getExcludePaths
Exclusion rule strings, parsed byExclusionRule.parse(String)- e.g."/actuator/health"(any verb) or"GET /actuator/**"(verb-restricted, Ant-style*/**wildcards). A declared-and-implemented, unverified endpoint matching any configured rule - from here,getExcludeFiles(), orgetExcludeWellKnown()- is still a doppelganger API in fact, but is reported under== Excluded Doppelganger APIsinstead of== Doppelganger APIs: it never failsgetFailOnDoppelganger()and never reachesgetContractHistoryFile(). Defaults to empty.- Returns:
- mutable list property of exclusion rule strings
-
getExcludeFiles
public abstract org.gradle.api.file.ConfigurableFileCollection getExcludeFiles()One or more YAML files of exclusion rules, in the same format bundled well-known sets use:exclusions: - "/actuator/health" - "GET /actuator/**"
Rules from every configured file are combined withgetExcludePaths()andgetExcludeWellKnown(). Defaults to empty.- Returns:
- mutable file collection of exclusion rule files
-
getExcludeWellKnown
Names of bundled, well-known exclusion sets to apply - e.g. "spring-boot-actuator" for Spring Boot Actuator's management endpoints. Combined withgetExcludePaths()andgetExcludeFiles(). An unrecognised name fails the build. Defaults to empty.- Returns:
- mutable list property of well-known exclusion set names
-
getIncludeResponseCoverage
Whether thescanContractstask additionally computes, for every declared response code, how many contract tests cover it. Defaults tofalse: the breakdown is not merely hidden when disabled, it is never computed - this is the more expensive of the two statisticsscanContractscan report, since it requires detecting the asserted status code of every matching contract test, not just whether one exists.For example, an endpoint
GET /v1/foobarsdeclaring response codes200and404, with two contract tests asserting200and one asserting404, reports200as covered by 2 test(s) and404as covered by 1 test(s) when this istrue.- Returns:
- mutable boolean property controlling whether response coverage is computed
-
getScanContractsReportFileName
Name of thescanContractstask's generated AsciiDoc report file (without path), written to the samegetReportDir(). Defaults to "contract-coverage.adoc".- Returns:
- mutable string property for the scanContracts report file name
-
getTrackResponseCoverageHistory
Whether to persist, across builds, a history of response code coverage - keyed by endpoint fingerprint and response code, tracking a live test-count gauge rather than milestone timestamps. Defaults tofalse. Only meaningful together withgetIncludeResponseCoverage()-scanContractsfails eagerly if this istruewhile that isfalse, since there would be no per-response-code data to persist.- Returns:
- mutable boolean property controlling whether response coverage history is tracked
-
getResponseCoverageHistoryFile
public abstract org.gradle.api.file.RegularFileProperty getResponseCoverageHistoryFile()File that the persisted response coverage history is read from and, whengetUpdateResponseCoverageHistory()istrue, written back to. Defaults to "doppelganger-api-detector-response-coverage-history.ndjson" directly in the project directory - deliberately not underbuild/, for the same reason asgetContractHistoryFile(). Only consulted whengetTrackResponseCoverageHistory()istrue. Deliberately a separate file fromgetContractHistoryFile(): response coverage is a Doppelganger-only concern with a different record schema, not shared with Shadow or Mirage API Detector.- Returns:
- mutable file property for the response coverage history file
-
getUpdateResponseCoverageHistory
WhethergetResponseCoverageHistoryFile()is written back to disk after being updated with the current run's coverage. Defaults to the same value asgetTrackResponseCoverageHistory(). Only consulted whengetTrackResponseCoverageHistory()istrue; the history file is always read regardless of this property's value.The "doppelgangerApiDetector.updateResponseCoverageHistory" project property, when set, overrides this property for every project in the build - the same per-branch-CI-pipeline pattern
getUpdateContractHistory()supports, independently of it.- Returns:
- mutable boolean property controlling whether the response coverage history file is written back
-