Skip to content

Commit

Permalink
Fix schema regex and generation
Browse files Browse the repository at this point in the history
  • Loading branch information
StarKhan6368 committed Dec 13, 2024
1 parent 816bff6 commit 8d32e1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class ExamplesInteractiveServer(
override fun close() {
server.stop(0, 0)
}

fun extractBreadcrumbs(input: String): List<String> {
val breadCrumbPrefix = ">> "

Expand All @@ -242,8 +243,6 @@ class ExamplesInteractiveServer(
return breadcrumbs
}



fun getJsonNodeLineNumbersUsingJsonPath(
jsonFilePath: String,
jsonPaths: List<String>,
Expand Down Expand Up @@ -398,9 +397,15 @@ class ExamplesInteractiveServer(
val examplesDir = getExamplesDirPath(contractFile).also { if (it.exists()) it.mkdirs() }
val allExistingExamples = examplesDir.getExamplesFromDir()

val schemaExamples = emptyList<TableRow>().withSchemaExamples(feature, examplesDir.getSchemaExamplesWithValidation(feature)).flatMap {
if (it.example != null) {
listOf(ExamplePathInfo(path = it.example, created = false, status = ExampleGenerationStatus.EXISTED))
} else generateForSchemaBased(contractFile, it.rawPath, it.method)
}

val allExamples = feature.scenarios.flatMap { scenario ->
generateAndLogScenarioExamples(contractFile, feature, scenario, allExistingExamples, allowOnlyMandatoryKeysInJSONObject)
}
}.plus(schemaExamples)

generationSummary(contractFile, allExamples).map { it.path }
} catch (e: StackOverflowError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.File

data class SchemaExample(val json: Value, val file: File) {
companion object {
val SCHEMA_IDENTIFIER_REGEX = Regex("^resource\\.(.*)\\.example\\.json$")
val SCHEMA_IDENTIFIER_REGEX = Regex("^resource(?:\\.(\\w+))?\\.(\\w+)\\.example\\.json\$")

fun toSchemaExampleFileName(parentPattern: String, patternName: String): String {
if (patternName.isBlank()) return "resource.$parentPattern.example.json"
Expand Down

0 comments on commit 8d32e1a

Please sign in to comment.