Skip to content

Commit

Permalink
Load _overlay.yaml file by convention
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed Oct 31, 2024
1 parent 9e09638 commit 3bb613f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,20 @@ class OpenApiSpecification(
specmaticConfig: SpecmaticConfig = SpecmaticConfig(),
overlayContent: String = ""
): OpenApiSpecification {
val implicitOverlayFile = File(openApiFilePath).let { openApiFile ->
if(!openApiFile.isFile)
return@let ""

val overlayFile = openApiFile.canonicalFile.parentFile.resolve(openApiFile.nameWithoutExtension + "_overlay.yaml")
if(overlayFile.isFile)
return@let overlayFile.readText()

return@let ""
}

val parseResult: SwaggerParseResult =
OpenAPIV3Parser().readContents(
yamlContent.applyOverlay(overlayContent),
yamlContent.applyOverlay(overlayContent).applyOverlay(implicitOverlayFile),
null,
resolveExternalReferences(),
openApiFilePath
Expand Down Expand Up @@ -194,6 +205,9 @@ class OpenApiSpecification(
private fun resolveExternalReferences(): ParseOptions = ParseOptions().also { it.isResolve = true }

private fun String.applyOverlay(overlayContent: String): String {
if(overlayContent.isBlank())
return this

return OverlayMerger().merge(this, OverlayParser.parse(overlayContent))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ExamplesInteractiveServer(

val request = call.receive<ExampleTestRequest>()
try {
val feature = OpenApiSpecification.fromFile(getContractFile().path).toFeature()
val feature = parseContractFileToFeature(getContractFile())

val contractTest = feature.createContractTestFromExampleFile(request.exampleFile).value

Expand Down

0 comments on commit 3bb613f

Please sign in to comment.