Skip to content

Commit

Permalink
W-15570769: fix oas components unresolved ref violations
Browse files Browse the repository at this point in the history
  • Loading branch information
arielmirra committed May 10, 2024
1 parent 3271bf4 commit 062d8d1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ case class Oas3ComponentParser(root: Root)(implicit val ctx: OasWebApiContext) e
assertPaths(rootMap, module)
ctx.closedShape(module, rootMap, "root")
}
ctx.futureDeclarations.resolve()
module
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: oas components test

paths: { }

components:
schemas:
RequestTypeTOPaged:
description: "RequestTypeTOPaged"
type: "object"
allOf:
- $ref: "#/components/responses/PageResponse"
- type: "string"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ModelId: file://amf-cli/shared/src/test/resources/components/oas3/oas-component-unresolved-ref.yaml
Profile:
Conforms: false
Number of results: 1

Level: Violation

- Constraint: http://a.ml/vocabularies/amf/core#unresolved-reference
Message: Unresolved reference '#/components/responses/PageResponse'
Severity: Violation
Target: file://amf-cli/shared/src/test/resources/components/oas3/oas-component-unresolved-ref.yaml#/declares/shape/RequestTypeTOPaged/and/unresolved
Property:
Range: [(14,10)-(15,0)]
Location: file://amf-cli/shared/src/test/resources/components/oas3/oas-component-unresolved-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: oas components test

paths: { }

components:
schemas:
RequestTypeTOPaged:
description: "RequestTypeTOPaged"
type: "object"
allOf:
- $ref: "#/components/responses/PageResponse"
- type: "string"
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ class AMFModelAssertionTest extends AsyncFunSuite with Matchers {

override implicit val executionContext: ExecutionContext = ExecutionContext.Implicits.global

val basePath = "file://amf-cli/shared/src/test/resources/validations"
val ro: RenderOptions = RenderOptions().withCompactUris.withPrettyPrint.withSourceMaps
val graphqlConfig: AMFConfiguration = GraphQLConfiguration.GraphQL().withRenderOptions(ro)
val ramlConfig: AMFConfiguration = RAMLConfiguration.RAML10().withRenderOptions(ro)
val ramlClient: AMFBaseUnitClient = ramlConfig.baseUnitClient()
val raml08Config: AMFConfiguration = RAMLConfiguration.RAML08().withRenderOptions(ro)
val raml08Client: AMFBaseUnitClient = raml08Config.baseUnitClient()
val oasConfig: AMFConfiguration = OASConfiguration.OAS30().withRenderOptions(ro)
val oasClient: AMFBaseUnitClient = oasConfig.baseUnitClient()
val asyncConfig: AMFConfiguration = AsyncAPIConfiguration.Async20().withRenderOptions(ro)
val asyncClient: AMFBaseUnitClient = asyncConfig.baseUnitClient()
val basePath = "file://amf-cli/shared/src/test/resources/validations"
val ro: RenderOptions = RenderOptions().withCompactUris.withPrettyPrint.withSourceMaps
val graphqlConfig: AMFConfiguration = GraphQLConfiguration.GraphQL().withRenderOptions(ro)
val ramlConfig: AMFConfiguration = RAMLConfiguration.RAML10().withRenderOptions(ro)
val ramlClient: AMFBaseUnitClient = ramlConfig.baseUnitClient()
val raml08Config: AMFConfiguration = RAMLConfiguration.RAML08().withRenderOptions(ro)
val raml08Client: AMFBaseUnitClient = raml08Config.baseUnitClient()
val oasConfig: AMFConfiguration = OASConfiguration.OAS30().withRenderOptions(ro)
val oasClient: AMFBaseUnitClient = oasConfig.baseUnitClient()
val oasComponentsConfig: AMFConfiguration = OASConfiguration.OAS30Component().withRenderOptions(ro)
val oasComponentsClient: AMFBaseUnitClient = oasComponentsConfig.baseUnitClient()
val asyncConfig: AMFConfiguration = AsyncAPIConfiguration.Async20().withRenderOptions(ro)
val asyncClient: AMFBaseUnitClient = asyncConfig.baseUnitClient()

def modelAssertion(
path: String,
Expand Down Expand Up @@ -665,4 +667,14 @@ class AMFModelAssertionTest extends AsyncFunSuite with Matchers {
operationSecurityScopes.size shouldBe 2
}
}

// W-13014769
test("OAS components parsing should throw unresolved references like OAS 3") {
val api = s"$basePath/oas3/oas-components-unresolved-ref.yaml"
oasComponentsClient.parse(api).flatMap { parseResultComponents =>
oasClient.parse(api).map { parseResultOas =>
parseResultOas.toString() shouldEqual parseResultComponents.toString()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package amf.validation

import amf.core.internal.remote.{Hint, Oas20JsonHint, Oas30JsonHint, Oas30YamlHint}
import org.scalatest.matchers.should.Matchers

class Oas30UniquePlatformUnitValidationsTest extends UniquePlatformReportGenTest with Matchers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,13 @@ class OasComponentValidationsTest extends UniquePlatformReportGenTest {
configOverride = Some(componentConfig)
)
}

// W-13014769
test("OAS components parsing should throw unresolved references like OAS 3") {
validate(
"oas-component-unresolved-ref.yaml",
Some("oas-component-unresolved-ref.report"),
configOverride = Some(componentConfig)
)
}
}

0 comments on commit 062d8d1

Please sign in to comment.