Skip to content

Commit

Permalink
Merge pull request #1056 from aml-org/publish-4.7.6
Browse files Browse the repository at this point in the history
Publish 4.7.6
  • Loading branch information
looseale committed Jul 27, 2021
2 parents a8088f8 + 17a4468 commit ef46177
Show file tree
Hide file tree
Showing 40 changed files with 544 additions and 300 deletions.
2 changes: 1 addition & 1 deletion amf-client/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"typings": "./typings/amf-client-js.d.ts",
"dependencies": {
"amf-shacl-node": "2.0.0",
"ajv": "6.5.2"
"ajv": "6.12.6"
},
"devDependencies": {
"webpack": "^4.43.0",
Expand Down
6 changes: 3 additions & 3 deletions amf-client/js/src/main/resources/ajv.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package amf.client.validation

import amf.client.model.DataTypes
import amf.client.model.domain.{NodeShape, ScalarShape}
import amf.client.model.domain.ScalarShape
import amf.convert.NativeOpsFromJvm
import amf.core.AMF
import amf.plugins.document.webapi.validation.PayloadValidatorPlugin
import org.json.JSONException
import org.scalatest.Matchers.a
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.Matchers._

class JvmPayloadValidationTest extends ClientPayloadValidationTest with NativeOpsFromJvm {
test("Test unexpected type error") {
Expand Down Expand Up @@ -41,4 +37,16 @@ class JvmPayloadValidationTest extends ClientPayloadValidationTest with NativeOp
report.results.asSeq.head.message shouldBe "Regex defined in schema could not be processed"
}
}

test("Validation against a number with multipleOf 0 should throw violation") {
amf.Core.init().asFuture.flatMap { _ =>
amf.Core.registerPlugin(PayloadValidatorPlugin)
val shape = new ScalarShape().withDataType(DataTypes.Number).withMultipleOf(0)
val validator = shape.payloadValidator("application/json").asOption.get
val positiveNumberReport = validator.syncValidate("application/json", "5")
val zeroReport = validator.syncValidate("application/json", "0")
positiveNumberReport.results.asSeq.head.message shouldBe "Can't divide by 0"
zeroReport.results.asSeq.head.message shouldBe "Can't divide by 0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ employees[2].name should be string
Location: file://amf-client/shared/src/test/resources/org/raml/parser/types/builtin/array/input.raml

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: should NOT have less than 2 items
Message: should NOT have fewer than 2 items
Level: Violation
Target: file://amf-client/shared/src/test/resources/org/raml/parser/types/builtin/array/input.raml#/declarations/types/array/Colors/example/bad-min
Property: file://amf-client/shared/src/test/resources/org/raml/parser/types/builtin/array/input.raml#/declarations/types/array/Colors/example/bad-min
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Number of results: 1
Level: Violation

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: should NOT have less than 2 properties
Message: should NOT have fewer than 2 properties
Level: Violation
Target: file://amf-client/shared/src/test/resources/org/raml/parser/types/min-and-max-properties/min-properties-error/input.raml#/declarations/types/Initial_comments/example/default-example
Property: file://amf-client/shared/src/test/resources/org/raml/parser/types/min-and-max-properties/min-properties-error/input.raml#/declarations/types/Initial_comments/example/default-example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Number of results: 1
Level: Violation

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: should NOT have less than 4 properties
Message: should NOT have fewer than 4 properties
Level: Violation
Target: file://amf-client/shared/src/test/resources/org/raml/parser/types/min-and-max-properties/with-additional-prop-error/input.raml#/declarations/types/Initial_comments/example/default-example
Property: file://amf-client/shared/src/test/resources/org/raml/parser/types/min-and-max-properties/with-additional-prop-error/input.raml#/declarations/types/Initial_comments/example/default-example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#%RAML 1.0
title: test API to be extended

types:
TestObject:
type: object

/test:
get:
responses:
200:
body:
application/json:
type: TestObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#%RAML 1.0 Extension
extends: /api.raml
types:
TestObject:
properties:
testObjectProperty:
enum:
- A
- B
example:
testObjectProperty: A

/test:
get:
responses:
200:
body:
application/json:
type: TestObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#%RAML 1.0
title: test API to be extended
/test:
get:
responses:
"200":
body:
application/json:
type: object
example:
testObjectProperty: A
additionalProperties: true
properties:
testObjectProperty:
enum:
- A
- B
type: string
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#%RAML 1.0
title: test-duplicated-properties-raml10

types:
test-duplicated-properties:
type: object
properties:
a: string
a?: string
b: string
b?: string
c: string
d: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#%RAML 1.0 Library

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#%RAML 1.0
title: test-multiple-uses-pointing-to-same-file
version: 1.0

uses:
first: library.raml
second: library.raml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Number of results: 1
Level: Violation

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: recipients should NOT have less than 1 items
Message: recipients should NOT have fewer than 1 items
Level: Violation
Target: file://amf-client/shared/src/test/resources/validations/examples/arrayItems1.raml#/web-api/end-points/%2Fnotifications%2Femails/post/request/application%2Fjson/schema/example/default-example
Property: file://amf-client/shared/src/test/resources/validations/examples/arrayItems1.raml#/web-api/end-points/%2Fnotifications%2Femails/post/request/application%2Fjson/schema/example/default-example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Number of results: 2
Level: Violation

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: should NOT have less than 2 items
Message: should NOT have fewer than 2 items
Level: Violation
Target: file://amf-client/shared/src/test/resources/validations/examples/min-max-items.raml#/declarations/types/array/Colors/example/bad-min
Property: file://amf-client/shared/src/test/resources/validations/examples/min-max-items.raml#/declarations/types/array/Colors/example/bad-min
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Number of results: 2
Level: Violation

- Source: http://a.ml/vocabularies/amf/validation#example-validation-error
Message: should NOT have less than 2 properties
Message: should NOT have fewer than 2 properties
Level: Violation
Target: file://amf-client/shared/src/test/resources/validations/examples/min-max-properties-example.raml#/declarations/types/InvalidMax/example/badMin
Property: file://amf-client/shared/src/test/resources/validations/examples/min-max-properties-example.raml#/declarations/types/InvalidMax/example/badMin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Model: file://amf-client/shared/src/test/resources/validations/duplicate-property/api.raml
Profile: RAML 1.0
Conforms? false
Number of results: 1

Level: Violation

- Source: http://a.ml/vocabularies/amf/parser#NodeShape-properties-duplicatePropertyNames
Message: Duplicated property names: a, b
Level: Violation
Target: file://amf-client/shared/src/test/resources/validations/duplicate-property/api.raml#/declarations/types/test-duplicated-properties
Property: http://www.w3.org/ns/shacl#property
Position: Some(LexicalInformation([(8,6)-(9,0)]))
Location: file://amf-client/shared/src/test/resources/validations/duplicate-property/api.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#%RAML 1.0
title: test API to be extended

types:
TestObject:
type: object

/test:
get:
responses:
200:
body:
application/json:
type: TestObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#%RAML 1.0 Extension
extends: /api.raml

types:
TestObject:
properties:
unionDate: datetime-only|nil
example:
unionDate: null

/test:
get:
responses:
200:
body:
application/json:
type: TestObject
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import amf.client.convert.{NativeOps, WebApiRegister}
import amf.client.model.DataTypes
import amf.client.model.domain._
import amf.core.AMF
import amf.plugins.document.webapi.validation.PayloadValidatorPlugin
import org.scalatest.{AsyncFunSuite, Matchers}
import amf.core.model.domain.{RecursiveShape => InternalRecursiveShape}
import amf.core.parser.{Annotations, Fields}
import amf.plugins.document.webapi.validation.PayloadValidatorPlugin
import amf.plugins.domain.shapes.models.{ScalarShape => InternalScalarShape}
import org.scalatest.{AsyncFunSuite, Matchers}

import scala.concurrent.ExecutionContext

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package amf.resolution

import amf.client.parse.DefaultParserErrorHandler
import amf.core.emitter.RenderOptions
import amf.core.model.document.BaseUnit
import amf.core.parser.errorhandler.UnhandledParserErrorHandler
import amf.core.remote.Syntax.Yaml
import amf.core.remote.Vendor.{AMF, ASYNC20, OAS20, OAS30}
import amf.core.remote._
import amf.core.resolution.pipelines.ResolutionPipeline
import amf.emit.AMFRenderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class ProductionValidationTest extends RamlResolutionTest {
}

multiGoldenTest("Recursive union raml to amf", "recursive-union.raml.%s") { config =>
cycle("recursive-union.raml", config.golden, RamlYamlHint, target = Amf, renderOptions = Some(config.renderOptions))
cycle("recursive-union.raml",
config.golden,
RamlYamlHint,
target = Amf,
renderOptions = Some(config.renderOptions))
}

test("Recursive union raml to raml") {
Expand All @@ -35,4 +39,7 @@ class ProductionValidationTest extends RamlResolutionTest {
cycle("api.raml", "api.raml.raml", RamlYamlHint, Raml, directory = basePath + "patch-method/")
}

test("Override enum in extension raml to raml") {
cycle("extension.raml", "result.raml", RamlYamlHint, Raml, directory = basePath + "override-enum/")
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package amf.resolution

import amf.core.errorhandling.UnhandledErrorHandler
import amf.core.model.document.BaseUnit
import amf.core.remote._
import amf.core.resolution.pipelines.ResolutionPipeline
import amf.io.{FunSuiteCycleTests, MultiJsonldAsyncFunSuite}
import amf.plugins.document.webapi.resolution.pipelines.{AmfEditingPipeline, AmfResolutionPipeline}
import amf.plugins.document.webapi.{Async20Plugin, Oas20Plugin, Oas30Plugin, Raml08Plugin, Raml10Plugin}
import amf.io.FunSuiteCycleTests

abstract class ResolutionTest extends FunSuiteCycleTests with ResolutionCapabilities {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import amf.client.parse.DefaultParserErrorHandler
import amf.client.plugins.{StrictValidationMode, ValidationMode}
import amf.core.model.document.{BaseUnit, Document}
import amf.core.model.domain.Shape
import amf.core.parser.errorhandler.UnhandledParserErrorHandler
import amf.core.remote._
import amf.core.unsafe.PlatformSecrets
import amf.core.validation.{AMFValidationReport, SeverityLevels}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,15 @@ class RamlModelUniquePlatformReportTest extends UniquePlatformReportGenTest {
Raml10Profile)
}

test("RAML union type with nil when applying extension") {
validate("valid-extension/extension.raml")
}

test("multiple uses objects pointing to the same library file") {
validate("multiple-uses/multiple-uses.raml")
}

test("invalid duplicated nullable property") {
validate("duplicate-property/api.raml", Some("raml/duplicated-property.report"))
}
}
6 changes: 3 additions & 3 deletions amf-webapi.versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
amf.webapi=4.7.5
amf.core=4.2.221
amf.custom.validations=5.1.7
amf.webapi=4.7.6
amf.core=4.2.223
amf.custom.validations=5.1.8
amf.model=3.1.0
6 changes: 3 additions & 3 deletions amf-webapi/js/src/main/resources/ajv.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@ import amf.validations.PayloadValidations.{
ExampleValidationErrorSpecification,
SchemaException => InternalSchemaException
}
import org.everit.json.schema.internal.{
DateFormatValidator,
DateTimeFormatValidator,
EmailFormatValidator,
HostnameFormatValidator,
IPV4Validator,
IPV6Validator,
RegexFormatValidator,
URIFormatValidator,
URIV4FormatValidator
}
import org.everit.json.schema.internal._
import org.everit.json.schema.loader.SchemaLoader
import org.everit.json.schema.regexp.{JavaUtilRegexpFactory, Regexp}
import org.everit.json.schema.{Schema, SchemaException, ValidationException, Validator}
import org.json.JSONException

import java.util.regex.PatternSyntaxException
import scala.collection.convert.ImplicitConversions.`collection AsScalaIterable`
import scala.collection.mutable.ArrayBuffer

class JvmPayloadValidator(val shape: Shape, val validationMode: ValidationMode, val env: Environment)
extends PlatformPayloadValidator(shape, env) {
Expand All @@ -60,7 +49,7 @@ class JvmPayloadValidator(val shape: Shape, val validationMode: ValidationMode,
} catch {
case validationException: ValidationException =>
validationProcessor.processException(validationException, fragment.map(_.encodes))
case exception: Error =>
case exception: Throwable =>
validationProcessor.processException(exception, fragment.map(_.encodes))
}
}
Expand Down Expand Up @@ -175,6 +164,9 @@ case class JvmReportValidationProcessor(override val profileName: ProfileName,
case e: InvalidJsonValue =>
Seq(invalidJsonValidation("Invalid json value was provided", element, e))

case e: ArithmeticException if e.getMessage == "Division undefined" || e.getMessage == "Division by zero" =>
Seq(invalidJsonValidation("Can't divide by 0", element, e))

case other =>
super.processCommonException(other, element)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package amf.plugins.document.webapi

import amf._
import amf.core.client.ParsingOptions
import amf.client.remod.amfcore.config.RenderOptions
import amf.client.remod.amfcore.plugins.parse.AMFParsePluginAdapter
import amf.core.Root
import amf.core.client.ParsingOptions
import amf.core.errorhandling.ErrorHandler
import amf.core.exception.InvalidDocumentHeaderException
import amf.core.model.document._
Expand All @@ -15,13 +16,11 @@ import amf.core.parser.{
ParsedReference,
ParserContext,
RefContainer,
ReferenceKind,
UnspecifiedReference
}
import amf.core.remote.{Platform, Raml, Vendor}
import amf.core.resolution.pipelines.ResolutionPipeline
import amf.core.validation.core.ValidationProfile
import amf.core.{CompilerContext, Root}
import amf.plugins.document.webapi.contexts.emitter.raml.{
Raml08SpecEmitterContext,
Raml10SpecEmitterContext,
Expand Down Expand Up @@ -108,7 +107,7 @@ sealed trait RamlPlugin extends BaseWebApiPlugin with CrossSpecRestriction {
private def validateReferencesToLibraries(reference: ParsedReference, ctx: ParserContext): Unit = {
val refs: Seq[RefContainer] = reference.origin.refs
val allKinds = refs.map(_.linkType)
val definedKind = if (allKinds.size > 1) UnspecifiedReference else allKinds.head
val definedKind = if (allKinds.distinct.size > 1) UnspecifiedReference else allKinds.head
val nodes = refs.map(_.node)
reference.unit match {
case _: Module => // if is a library, kind should be LibraryReference
Expand Down
Loading

0 comments on commit ef46177

Please sign in to comment.