Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-13599698: skip computing min shape between shapes that share the same ID #1811

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions amf-cli/shared/src/test/resources/overriden-cyclic-properties.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#%RAML 1.0

title: I am a title

types:
Element:
type: object
properties:
extension?:
type: Extension[]
Extension:
type: Element
properties:
extension?:
type: Extension[]
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ import amf.core.client.platform.config.RenderOptions
import amf.core.client.platform.model.document.{BaseUnit, DeclaresModel, Document, EncodesModel}
import amf.core.client.platform.model.domain._
import amf.core.client.platform.parse.AMFParser
import amf.core.client.platform.parse.AMFParser.parseStartingPoint
import amf.core.client.platform.parse.AMFParser.{parse, parseStartingPoint}
import amf.core.client.platform.resource.{ResourceNotFound, ResourceLoader => ClientResourceLoader}
import amf.core.client.scala.errorhandling.DefaultErrorHandler
import amf.core.client.scala.exception.UnsupportedVendorException
import amf.core.client.scala.model.document.{Document => InternalDocument}
import amf.core.client.scala.model.domain.extensions.{DomainExtension => InternalDomainExtension}
import amf.core.client.scala.model.domain.{
ArrayNode => InternalArrayNode,
ObjectNode => InternalObjectNode,
ScalarNode => InternalScalarNode
}
import amf.core.client.scala.model.domain.{ArrayNode => InternalArrayNode, ObjectNode => InternalObjectNode, ScalarNode => InternalScalarNode}
import amf.core.client.scala.resource.ResourceLoader
import amf.core.client.scala.validation.AMFValidationReport
import amf.core.client.scala.vocabulary.Namespace
Expand Down Expand Up @@ -2171,6 +2167,18 @@ trait WrapperTests extends MultiJsonldAsyncFunSuite with Matchers with NativeOps
}
}

test("Stackoverflow in minShape with overriden cyclic properties") {
val client = RAMLConfiguration.RAML10().baseUnitClient()
val path = "file://amf-cli/shared/src/test/resources/overriden-cyclic-properties.raml"
for {
parsingResult <- client.parse(path).asFuture
resolutionResult <- Future.successful(client.transform(parsingResult.baseUnit, PipelineId.Editing))
} yield {
assert(parsingResult.conforms)
assert(resolutionResult.conforms)
}
}

//
// // todo: move to common (file system)
def getAbsolutePath(path: String): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,10 @@ private[resolution] class MinShapeAlgorithm()(implicit val context: Normalizatio
case _ => false
}

private def areSameShape(child: Shape, parent: Shape): Boolean = child.id == parent.id && child.id != null
def computeMinShape(child: Shape, parent: Shape): Shape = {
if(areSameShape(child, parent)) return child

val parentCopy = parent.copyShape()
val childClone = child.cloneElement(mutable.Map.empty).asInstanceOf[Shape] // this is destructive, we need to clone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private[resolution] class NormalizationContext(
TransformationValidation,
derivedShape.id,
Some(ShapeModel.Inherits.value.iri()),
other.getMessage,
Option(other.getMessage()).getOrElse(other.toString),
derivedShape.position(),
derivedShape.location()
)
Expand Down