Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,13 @@ import amf.aml.client.scala.model.document.Dialect
import amf.apicontract.internal.annotations.{APISerializableAnnotations, WebAPISerializableAnnotations}
import amf.apicontract.internal.convert.ApiRegister
import amf.apicontract.internal.entities.{APIEntities, FragmentEntities}
import amf.apicontract.internal.plugins.{
ExternalJsonYamlRefsParsePlugin,
JsonSchemaParsePlugin,
JsonSchemaRenderPlugin
}
import amf.apicontract.internal.plugins.{ExternalJsonYamlRefsParsePlugin, JsonSchemaParsePlugin, JsonSchemaRenderPlugin}
import amf.apicontract.internal.spec.async.{Async20ParsePlugin, Async20RenderPlugin}
import amf.apicontract.internal.spec.oas.{Oas20ParsePlugin, Oas20RenderPlugin, Oas30ParsePlugin, Oas30RenderPlugin}
import amf.apicontract.internal.spec.payload.{PayloadParsePlugin, PayloadRenderPlugin}
import amf.apicontract.internal.spec.raml.{
Raml08ParsePlugin,
Raml08RenderPlugin,
Raml10ParsePlugin,
Raml10RenderPlugin
}
import amf.apicontract.internal.spec.raml.{Raml08ParsePlugin, Raml08RenderPlugin, Raml10ParsePlugin, Raml10RenderPlugin}
import amf.apicontract.internal.transformation._
import amf.apicontract.internal.transformation.compatibility.{
Oas20CompatibilityPipeline,
Oas3CompatibilityPipeline,
Raml08CompatibilityPipeline,
Raml10CompatibilityPipeline
}
import amf.apicontract.internal.transformation.compatibility.{Oas20CompatibilityPipeline, Oas3CompatibilityPipeline, Raml08CompatibilityPipeline, Raml10CompatibilityPipeline}
import amf.apicontract.internal.validation.model.ApiValidationProfiles._
import amf.apicontract.internal.validation.payload.{JsonSchemaShapePayloadValidationPlugin, PayloadValidationPlugin}
import amf.apicontract.internal.validation.shacl.{CustomShaclModelValidationPlugin, FullShaclModelValidationPlugin}
Expand All @@ -45,7 +31,7 @@ import amf.shapes.internal.entities.ShapeEntities

import scala.concurrent.Future

sealed trait APIConfigurationBuilder {
trait APIConfigurationBuilder {

// will also define APIDomainPlugin, DataShapesDomainPlugin
private[amf] def common(): AMFConfiguration = {
Expand Down Expand Up @@ -144,7 +130,11 @@ object OASConfiguration extends APIConfigurationBuilder {

/** Merged [[OASConfiguration]] and [[RAMLConfiguration]] configurations */
object WebAPIConfiguration {
def WebAPI(): AMFConfiguration = OASConfiguration.OAS().merge(RAMLConfiguration.RAML())
def WebAPI(): AMFConfiguration = {
val config = OASConfiguration.OAS().merge(RAMLConfiguration.RAML())
//config.merge(GRPCConfiguration.GRPC())
config
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ class EndPoint(override val fields: Fields, override val annotations: Annotation
override def meta: EndPointModel.type = EndPointModel

/** Value , path + field value that is used to compose the id when the object its adopted */
private[amf] override def componentId: String = "/end-points/" + path.value().urlComponentEncoded
override def nameField: Field = Name
private[amf] override def componentId: String = "/end-points/" + {
path.option() match {
case Some(value) => value.urlComponentEncoded
case _ => name.value().urlComponentEncoded
}
}
override def nameField: Field = Name
}

object EndPoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ case class Operation(fields: Fields, annotations: Annotations)
override def meta: OperationModel.type = OperationModel

/** Value , path + field value that is used to compose the id when the object its adopted */
private[amf] override def componentId: String =
"/" + method.option().getOrElse("default-operation").urlComponentEncoded
override def nameField: Field = Name
private[amf] override def componentId: String = {
val name = if (operationId.option().isDefined) {
operationId.value().urlComponentEncoded
} else {
method.option().getOrElse("default-operation").urlComponentEncoded
}
"/" + name
}
override def nameField: Field = Name

override protected def classConstructor: (Fields, Annotations) => Linkable with DomainElement = Operation.apply
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package amf.apicontract.internal.plugins

import amf.core.client.scala.errorhandling.AMFErrorHandler
import amf.core.client.scala.parse.document.{ParserContext, Reference}
import amf.core.client.scala.parse.document.{ASTRefContainer, ParserContext, Reference}
import amf.core.internal.parser.Root
import amf.core.internal.remote.Vendor
import amf.core.internal.validation.CoreValidations.InvalidCrossSpec
import org.mulesoft.lexer.SourceLocation

trait CrossSpecRestriction { this: ApiParsePlugin =>

Expand All @@ -14,8 +15,8 @@ trait CrossSpecRestriction { this: ApiParsePlugin =>
val possibleReferencedVendors = mediaTypes ++ validMediaTypesToReference
optionalReferencedVendor.foreach { referencedVendor =>
if (!possibleReferencedVendors.contains(referencedVendor.mediaType)) {
referenceNodes(reference).foreach(node =>
errorHandler.violation(InvalidCrossSpec, "", "Cannot reference fragments of another spec", node))
referenceNodes(reference).foreach(position =>
errorHandler.violation(InvalidCrossSpec, "", "Cannot reference fragments of another spec", position))
}
}
}
Expand All @@ -26,5 +27,5 @@ trait CrossSpecRestriction { this: ApiParsePlugin =>
}
}

private def referenceNodes(reference: Reference) = reference.refs.map(_.node)
private def referenceNodes(reference: Reference): Seq[SourceLocation] = reference.refs.collect { case ref: ASTRefContainer => ref.pos }
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class AsyncBindingsParser(entryLike: YMapEntryLike, parent: String)(imp
ctx.eh.violation(CoreValidations.UnresolvedReference,
"",
s"Cannot find link reference $fullRef",
entryLike.asMap)
entryLike.asMap.location)
val errorBinding = errorBindings(fullRef, entryLike)
nameAndAdopt(errorBinding.link(fullRef, errorBinding.annotations), entryLike.key)
}
Expand Down Expand Up @@ -140,7 +140,7 @@ abstract class AsyncBindingsParser(entryLike: YMapEntryLike, parent: String)(imp
ctx.eh.violation(ParserSideValidations.NonEmptyBindingMap,
node,
s"Reserved name binding '${`type`}' must have an empty map",
value)
value.location)
}

protected def parseBindingVersion(binding: BindingVersion, field: Field, map: YMap)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case class AsyncCorrelationIdParser(entryLike: YMapEntryLike, parentId: String)(
val external = AsyncCorrelationIdParser(YMapEntryLike(correlationIdNode), parentId).parse()
nameAndAdopt(external.link(AmfScalar(fullRef), Annotations(map), Annotations.synthesized()), entryLike.key)
case None =>
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find link reference $fullRef", map)
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find link reference $fullRef", map.location)
val errorCorrelation = new ErrorCorrelationId(fullRef, map)
nameAndAdopt(errorCorrelation.link(fullRef, errorCorrelation.annotations), entryLike.key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ abstract class AsyncMessagePopulator()(implicit ctx: AsyncWebApiContext) extends
ctx.eh.violation(ParserSideValidations.HeaderMustBeObject,
message.id,
ParserSideValidations.HeaderMustBeObject.message,
entry.value)
entry.value.location)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ case class AsyncOperationTraitRefParser(node: YNode, adopt: Operation => Operati
}

private def expectedRef(node: YNode, name: String): Operation = {
ctx.eh.violation(ParserSideValidations.ExpectedReference, "", s"Expected reference", node)
ctx.eh.violation(ParserSideValidations.ExpectedReference, "", s"Expected reference", node.location)
new ErrorOperationTrait(name, node).link(name, Annotations(node)).asInstanceOf[Operation].withAbstract(true)
}

private def linkError(url: String, node: YNode): Operation = {
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find operation trait reference $url", node)
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find operation trait reference $url", node.location)
val t: ErrorOperationTrait = new ErrorOperationTrait(url, node).link(url, Annotations(node))
t

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ case class AsyncParameterParser(parentId: String, entryLike: YMapEntryLike)(impl
val external = AsyncParameterParser(parentId, YMapEntryLike(paramNode)).parse()
nameAndAdopt(external.link(AmfScalar(fullRef), Annotations(map), Annotations.synthesized()))
case None =>
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find link reference $fullRef", map)
ctx.eh.violation(CoreValidations.UnresolvedReference, "", s"Cannot find link reference $fullRef", map.location)
nameAndAdopt(ErrorParameter(fullRef, map).link(fullRef, annotations = Annotations(map)))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class WebApiDeclarations(val alias: Option[String],
findParameter(key, scope) match {
case Some(result) => result
case _ =>
error(s"Parameter '$key' not found", ast)
error(s"Parameter '$key' not found", ast.location)
ErrorParameter(key, ast)
}

Expand Down Expand Up @@ -309,7 +309,7 @@ class WebApiDeclarations(val alias: Option[String],
findResourceType(key, scope) match {
case Some(result) => result
case _ =>
error(s"ResourceType $key not found", ast)
error(s"ResourceType $key not found", ast.location)
ErrorResourceType(key, ast)
}

Expand Down Expand Up @@ -340,7 +340,7 @@ class WebApiDeclarations(val alias: Option[String],
def findTraitOrError(ast: YPart)(key: String, scope: SearchScope.Scope): Trait = findTrait(key, scope) match {
case Some(result) => result
case _ =>
error(s"Trait $key not found", ast)
error(s"Trait $key not found", ast.location)
ErrorTrait(key, ast)
}

Expand Down Expand Up @@ -368,7 +368,7 @@ class WebApiDeclarations(val alias: Option[String],
findSecurityScheme(key, scope) match {
case Some(result) => result
case _ =>
error(s"SecurityScheme '$key' not found", ast)
error(s"SecurityScheme '$key' not found", ast.location)
ErrorSecurityScheme(key, ast)
}

Expand All @@ -388,14 +388,14 @@ class WebApiDeclarations(val alias: Option[String],
findResponse(key, searchScope) match {
case Some(result) => result
case _ =>
error(s"Response '$key' not found", ast)
error(s"Response '$key' not found", ast.location)
ErrorResponse(key, ast)
}

def findNamedExampleOrError(ast: YPart)(key: String): Example = findNamedExample(key) match {
case Some(result) => result
case _ =>
error(s"NamedExample '$key' not found", ast)
error(s"NamedExample '$key' not found", ast.location)
ErrorNamedExample(key, ast)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ case class AbstractDeclarationsParser(key: String,
ctx.eh.violation(InvalidAbstractDeclarationType,
customProperties,
s"Invalid type $t for '$key' node.",
e.value)
e.value.location)
}
}
)
Expand All @@ -71,7 +71,7 @@ case class AbstractDeclarationParser(declaration: AbstractDeclaration, parent: S
ctx.eh.warning(NullAbstractDeclaration,
parent,
"Generating abstract declaration (resource type / trait) with null value",
entryValue)
entryValue.location)

ctx.link(entryValue) match {
case Left(link) => parseReferenced(declaration, link, entryValue, map.annotations).adopted(parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait SpecParserOps extends QuickFieldParserOps {
node,
Some(property),
"Invalid path template syntax",
value
value.location
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ case class Raml10ParameterParser(entry: YMapEntry,
ctx.eh.violation(UnresolvedReference,
parameter.id,
"Cannot declare unresolved parameter",
entry.value)
entry.value.location)
parameter
}
case _ =>
ctx.eh.violation(UnresolvedReference, parameter.id, "Cannot declare unresolved parameter", entry.value)
ctx.eh.violation(UnresolvedReference, parameter.id, "Cannot declare unresolved parameter", entry.value.location)
parameter

}
Expand Down Expand Up @@ -299,7 +299,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
ParameterNameRequired,
element.id,
"'name' property is required in a parameter.",
map
map.location
)
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
invalidExampleFieldWarning,
p.domainElement.id,
s"Property 'example' not supported in a parameter node",
map
map.location
)
case _ =>
}
Expand All @@ -362,7 +362,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
UnresolvedParameter,
parameter.id,
"Cannot find valid schema for parameter",
map
map.location
)
None
}
Expand Down Expand Up @@ -398,7 +398,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
ctx.eh.violation(MissingParameterType,
container.id,
s"'type' is required in a parameter with binding '$binding'",
map)
map.location)
case Some(entry) =>
checkItemsField(entry, container)
typeParsing()
Expand All @@ -413,7 +413,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
ctx.eh.warning(ItemsFieldRequiredWarning, // TODO: Should be violation
container.id,
"'items' field is required when schema type is array",
map)
map.location)
}

private def parseFormDataPayload(bindingRange: Option[Range]): Payload = {
Expand All @@ -439,7 +439,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
UnresolvedParameter,
payload.id,
"Cannot find valid schema for parameter",
map
map.location
)
None
}
Expand Down Expand Up @@ -486,7 +486,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
schema
}
case None =>
ctx.eh.warning(OasInvalidParameterSchema, "", s"Schema is required for a parameter in body", map)
ctx.eh.warning(OasInvalidParameterSchema, "", s"Schema is required for a parameter in body", map.location)
}
payload
}
Expand All @@ -497,7 +497,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
ctx.eh.violation(OasInvalidParameterBinding,
"",
s"Invalid parameter binding '$binding'",
bindingEntry.map(_.value).getOrElse(map))
bindingEntry.map(_.value).getOrElse(map).location)

parameter.domainElement match {
case p: Parameter =>
Expand All @@ -521,7 +521,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
OasFormDataNotFileSpecification,
schema.id,
"File types in parameters must be declared in formData params",
map
map.location
)
}

Expand Down Expand Up @@ -558,7 +558,7 @@ case class Oas2ParameterParser(entryOrNode: YMapEntryLike,
ctx.eh.violation(UnresolvedParameter,
parameter.id,
s"Cannot find parameter or payload reference $refUrl",
ref)
ref.location)
OasParameter(parameter, Some(ref))
}
}
Expand Down Expand Up @@ -769,7 +769,7 @@ case class OasParametersParser(values: Seq[YNode], parentId: String)(implicit ct
OasBodyAndFormDataParameterSpecification,
bodyParam.domainElement.id,
"Cannot declare 'body' and 'formData' params at the same time for a request or resource",
bodyParam.ast.get
bodyParam.ast.get.location
)
}

Expand Down Expand Up @@ -818,7 +818,7 @@ case class OasParametersParser(values: Seq[YNode], parentId: String)(implicit ct
DuplicatedParameters,
oasParam.domainElement.id,
s"Parameter $name of type $binding was found duplicated",
ast
ast.location
)
case None =>
ctx.eh.violation(
Expand Down Expand Up @@ -846,7 +846,7 @@ case class OasParametersParser(values: Seq[YNode], parentId: String)(implicit ct
id,
param.domainElement.id,
"Cannot declare more than one 'body' parameter for a request or a resource",
param.ast.get
param.ast.get.location
)
}
}
Expand Down
Loading