Skip to content

Commit

Permalink
Merge pull request #1869 from aml-org/W-14105863/override-union-ranges
Browse files Browse the repository at this point in the history
W-14105863: when overriding properties if the ranges are both uniones…
  • Loading branch information
pope1838 authored Sep 13, 2023
2 parents 0492005 + f6abf8f commit ec251a5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
ModelId: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml
Profile: RAML 1.0
Conforms: false
Number of results: 4

Level: Violation

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#string
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml#/declares/shape/NumberOrString/property/property/name/union/name/0
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(30,14)-(30,20)]
Location: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml#/declares/shape/NumberOrString/property/property/name/union/name/2
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(30,14)-(30,20)]
Location: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://a.ml/vocabularies/shapes#number
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml#/declares/shape/NumberOrString/property/property/name/union/name/4
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(30,21)-(30,27)]
Location: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml#/declares/shape/NumberOrString/property/property/name/union/name/5
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(30,21)-(30,27)]
Location: file://amf-cli/shared/src/test/resources/org/raml/parser/types/inheritance/override/input.raml
#%RAML 1.0
title: valid property type inheritance
types:
Anything:
properties:
name:
type: any
StringOrNumber:
properties:
name:
type: string | number
NumberOrNil:
properties:
name:
type: number | nil
Integer:
properties:
name:
type: integer
StringOrNumberOrBoolean:
properties:
name:
type: string | number | boolean
NumberOrString:
properties:
name:
type: number | string
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#%RAML 1.0 Library

types:

SuperType:
properties:
unionProp?:
type: date-only | nil

BaseType:
type: SuperType
properties:
unionProp?:
type: date-only | nil

Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
ModelId: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml
Profile: RAML 1.0
Conforms: false
Number of results: 4

Level: Violation

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#string
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/0
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,14)-(48,20)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/2
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,14)-(48,20)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://a.ml/vocabularies/shapes#number
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/4
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,21)-(48,27)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/5
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,21)-(48,27)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml
Conforms: true
Number of results: 0
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
ModelId: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml
Profile: RAML 1.0
Conforms: false
Number of results: 4

Level: Violation

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#string
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/0
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,14)-(48,20)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://a.ml/vocabularies/shapes#number < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/2
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,14)-(48,20)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://a.ml/vocabularies/shapes#number
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/4
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,21)-(48,27)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml

- Constraint: http://a.ml/vocabularies/amf/resolution#invalid-type-inheritance
Message: Resolution error: Invalid scalar inheritance base type http://www.w3.org/2001/XMLSchema#string < http://www.w3.org/2001/XMLSchema#boolean
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml#/declares/shape/NumberOrString/property/property/name/union/name/5
Property: http://a.ml/vocabularies/shapes#inherits
Range: [(48,21)-(48,27)]
Location: file://amf-cli/shared/src/test/resources/validations/production/inheritance.raml
Conforms: true
Number of results: 0
16 changes: 16 additions & 0 deletions amf-cli/shared/src/test/scala/amf/validation/ValidationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ class ValidationTest extends AsyncFunSuite with PlatformSecrets {
}

}

test("Test override property with same union range than super") {
val source = productionPath + "simple-union-override/library.raml"

val config = RAMLConfiguration.RAML10()
for {
report <- config.baseUnitClient().parse(source)
transform <- Future.successful(config.baseUnitClient().transform(report.baseUnit, PipelineId.Editing))
validation <- config.baseUnitClient().validate(transform.baseUnit)
} yield {
val parseReport = AMFValidationReport.unknownProfile(report)
val transformReport = AMFValidationReport.unknownProfile(transform)
println(transformReport.toString)
assert(validation.merge(transformReport).merge(parseReport).conforms)
}
}
private def parseAndValidate(url: String, config: => AMFGraphConfiguration): Future[AMFValidationReport] = {
val client = config.baseUnitClient()
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,15 @@ private[resolution] class MinShapeAlgorithm()(implicit val resolver: ShapeNormal
} else {
val shouldComputeMinRange =
(baseProperty.range, superProperty.range) match {
case (c, p) if c.id == p.id => false
case (c, p) if c.id == p.id => false
// Almost a hack. Spec says that a property can be overrided by a narrowed type. We should analyze each
// bu union member against the whole list of super union members and check that is equal or more restricted that all
// the types of the same meta type.
case (_: UnionShape, _: UnionShape) => false

// same question that above, should be the same of all range of overrided properties?
// the range that works is the one of the base shape?? maybe just properties of iinner objects?
// what about arrays? items should be merged?
case (_: ScalarShape, _: UnionShape) =>
// if scalar is not a member of union.anyOf should throw violation
// should extend to all shapes?
Expand Down

0 comments on commit ec251a5

Please sign in to comment.