Skip to content

Commit

Permalink
PIL-1578: Adjust API definition to publish as Alpha (#60)
Browse files Browse the repository at this point in the history
* PIL-1578: Adjust API definition to publish as Alpha

* add unit test

* use dynamic schema

* refactor
  • Loading branch information
MoDweik authored Jan 17, 2025
1 parent d7876d6 commit 572a3ab
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
7 changes: 4 additions & 3 deletions resources/public/api/definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"versions": [
{
"version": "1.0",
"status": "BETA",
"endpointsEnabled": true,
"status": "ALPHA",
"endpointsEnabled": false,
"access": {
"type": "PUBLIC"
"type": "PRIVATE",
"isTrial": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.gov.hmrc.pillar2submissionapi.resources

import com.github.fge.jackson.JsonLoader
import com.github.fge.jsonschema.core.report.LogLevel
import com.github.fge.jsonschema.main.JsonSchemaFactory
import play.twirl.api.TwirlHelperImports.twirlJavaCollectionToScala
import uk.gov.hmrc.pillar2submissionapi.base.UnitTestBaseSpec

import scala.io.Source

class DefinitionSpec extends UnitTestBaseSpec {

private val schemaUrl = "https://raw.githubusercontent.com/hmrc/api-publisher/main/app/resources/api-definition-schema.json"

"API Definition" should {
"conform to api-publisher schema" in {
val source = Source.fromURL(schemaUrl)
val schemaJson =
try source.mkString
finally source.close()
val schema = JsonLoader.fromString(schemaJson)
val definition = JsonLoader.fromResource("/public/api/definition.json")
val validator = JsonSchemaFactory.byDefault().getJsonSchema(schema)

val report = validator.validate(definition)

val errors = report
.filter(_.getLogLevel == LogLevel.ERROR)
.map(error => s"${error.asJson().get("instance")}: ${error.getMessage}")
.toList

errors mustEqual List.empty
}
}
}

0 comments on commit 572a3ab

Please sign in to comment.