Skip to content

Commit

Permalink
Fixing strange URL format exception when referencing open source Zala…
Browse files Browse the repository at this point in the history
…ndo Problem object at the very beginning of a document. (#85)

Now validates the document URLs of external schemas and skips over them
  • Loading branch information
cjbooms authored Nov 24, 2021
1 parent b928f75 commit 4ed9241
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asTypeName
import java.io.Serializable
import java.net.MalformedURLException
import java.net.URL

class JacksonModelGenerator(
Expand Down Expand Up @@ -127,12 +128,12 @@ class JacksonModelGenerator(
fun generatedType(basePackage: String, modelName: String) = ClassName(modelsPackage(basePackage), modelName)
}

private val externalApiSchemas = mutableMapOf<String, MutableSet<String>>()
private val externalApiSchemas = mutableMapOf<URL, MutableSet<String>>()

fun generate(): Models {
val models: MutableSet<TypeSpec> = createModels(sourceApi.openApi3, sourceApi.allSchemas)
externalApiSchemas.forEach { externalReferences ->
val api = OpenApi3Parser().parse(URL(externalReferences.key))
val api = OpenApi3Parser().parse(externalReferences.key)
val schemas = api.schemas.entries.map { it.key to it.value }
.map { (key, schema) -> SchemaInfo(key, schema) }
.filter { apiSchema -> externalReferences.value.contains(apiSchema.name) }
Expand Down Expand Up @@ -249,7 +250,11 @@ class JacksonModelGenerator(
nestedSchemas().forEach { schema ->
val docUrl = schema.getDocumentUrl()
if (docUrl != apiDocUrl) {
externalApiSchemas.getOrPut(docUrl) { mutableSetOf() }.add(schema.safeName())
try {
externalApiSchemas.getOrPut(URL(docUrl)) { mutableSetOf() }.add(schema.safeName())
} catch (ex: MalformedURLException) {
// skip
}
}
if (depth < 10) schema.captureMissingExternalSchemas(apiDocUrl, depth + 1)
}
Expand Down

0 comments on commit 4ed9241

Please sign in to comment.