generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PI-2268 Auto-generate AsyncAPI specs * Update schemas
- Loading branch information
1 parent
ea0657a
commit 7c43079
Showing
133 changed files
with
1,437 additions
and
1,211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...saging/src/main/kotlin/uk/gov/justice/digital/hmpps/documentation/AsyncApiCommonConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package uk.gov.justice.digital.hmpps.documentation | ||
|
||
import org.openfolder.kotlinasyncapi.springweb.service.AsyncApiExtension | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class AsyncApiCommonConfig { | ||
@Bean | ||
fun asyncApiCommonInfo() = AsyncApiExtension.builder { | ||
info { | ||
title("Async API Reference") | ||
version("1.0") | ||
contact { | ||
name("Probation Integration Team") | ||
email("[email protected]") | ||
url("https://mojdt.slack.com/archives/C02HQ4M2YQN") // #probation-integration-tech Slack channel | ||
} | ||
license { | ||
name("MIT") | ||
url("https://github.com/ministryofjustice/hmpps-probation-integration-services/blob/main/LICENSE") | ||
} | ||
} | ||
externalDocs { | ||
url("https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/") | ||
} | ||
defaultContentType("application/json") | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/main/kotlin/uk/gov/justice/digital/hmpps/documentation/AsyncApiReferencingSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uk.gov.justice.digital.hmpps.documentation | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.openfolder.kotlinasyncapi.model.AsyncApi | ||
import org.openfolder.kotlinasyncapi.model.channel.* | ||
import org.openfolder.kotlinasyncapi.springweb.service.AsyncApiSerializer | ||
import org.springframework.context.annotation.Primary | ||
import org.springframework.stereotype.Component | ||
|
||
@Primary | ||
@Component | ||
class AsyncApiReferencingSerializer(val objectMapper: ObjectMapper) : AsyncApiSerializer { | ||
override fun AsyncApi.serialize(): String = objectMapper.writeValueAsString(this.also { asyncApi -> | ||
asyncApi.components?.channels?.values?.forEach { value -> | ||
val channel = value as Channel | ||
listOfNotNull(channel.publish, channel.subscribe).forEach { it.replaceMessagesWithReferences() } | ||
} | ||
}) | ||
|
||
private fun Operation.replaceMessagesWithReferences() { | ||
val messages = (message as OneOfReferencableMessages?)?.oneOf | ||
val messageNames = messages?.filterIsInstance<Message>()?.mapNotNull { it.name } | ||
messageNames?.forEach { messages.replaceWithReference(it) } | ||
} | ||
|
||
private fun ReferencableMessagesList.replaceWithReference(name: String) { | ||
reference { ref("https://raw.githubusercontent.com/ministryofjustice/hmpps-domain-events/main/spec/schemas/$name.yml") } | ||
removeIf { it is Message && it.name == name } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/AsyncApiConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.justice.digital.hmpps.config | ||
|
||
import org.openfolder.kotlinasyncapi.springweb.service.AsyncApiExtension | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class AsyncApiConfig { | ||
@Bean | ||
fun asyncApiExtension(asyncApiCommonInfo: AsyncApiExtension) = AsyncApiExtension.builder(order = 1) { | ||
info.title("approved-premises-and-delius") | ||
info.description("Reflect progress of approved premises referrals in Delius") | ||
servers { | ||
server("dev") { | ||
url("https://sqs.eu-west-2.amazonaws.com/754256621582/probation-integration-dev-approved-premises-and-delius-queue") | ||
protocol("sqs") | ||
} | ||
server("preprod") { | ||
url("https://sqs.eu-west-2.amazonaws.com/754256621582/probation-integration-preprod-approved-premises-and-delius-queue") | ||
protocol("sqs") | ||
} | ||
server("prod") { | ||
url("https://sqs.eu-west-2.amazonaws.com/754256621582/probation-integration-prod-approved-premises-and-delius-queue") | ||
protocol("sqs") | ||
} | ||
} | ||
externalDocs { | ||
url("https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/approved-premises-and-delius/") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
projects/approved-premises-and-delius/tech-docs/source/async-api-reference.html.md.erb
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
projects/approved-premises-and-delius/tech-docs/source/asyncapi-reference.html.md.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: AsyncAPI Reference | ||
source_url: 'https://github.com/ministryofjustice/hmpps-probation-integration-services/blob/main/projects/approved-premises-and-delius/tech-docs/source/asyncapi-reference.html.md.erb' | ||
weight: 30 | ||
--- | ||
|
||
# AsyncAPI Reference | ||
|
||
<iframe src="https://studio.asyncapi.com/?url=https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/approved-premises-and-delius/asyncapi-docs.json&readOnly" title="AsyncAPI Spec" width="100%" height="100%" frameborder=0 style="position: absolute; bottom: 0; background: white"></iframe> | ||
|
||
<style>.app-pane__content { position: relative }</style> | ||
<script>document.querySelector('main').parentElement.appendChild(document.querySelector('main > iframe'))</script> |
Oops, something went wrong.