Skip to content

Commit da698bb

Browse files
committed
Json Schema for Message Docs
1 parent 4ace47d commit da698bb

6 files changed

Lines changed: 150 additions & 14 deletions

File tree

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ declare module 'vue' {
4545
GlossarySearchNav: typeof import('./src/components/GlossarySearchNav.vue')['default']
4646
HeaderNav: typeof import('./src/components/HeaderNav.vue')['default']
4747
Menu: typeof import('./src/components/Menu.vue')['default']
48+
MessageDocsJsonSchemaSearchNav: typeof import('./src/components/MessageDocsJsonSchemaSearchNav.vue')['default']
4849
MessageDocsSearchNav: typeof import('./src/components/MessageDocsSearchNav.vue')['default']
4950
Preview: typeof import('./src/components/Preview.vue')['default']
5051
RouterLink: typeof import('vue-router')['RouterLink']

src/components/HeaderNav.vue

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
HEADER_LINKS_HOVER_COLOR as headerLinksHoverColorSetting,
3737
HEADER_LINKS_BACKGROUND_COLOR as headerLinksBackgroundColorSetting
3838
} from '../obp/style-setting'
39-
import { obpApiActiveVersionsKey, obpGroupedMessageDocsKey, obpMyCollectionsEndpointKey } from '@/obp/keys'
39+
import { obpApiActiveVersionsKey, obpGroupedMessageDocsKey, obpGroupedMessageDocsJsonSchemaKey, obpMyCollectionsEndpointKey } from '@/obp/keys'
4040
import SvelteDropdown from './SvelteDropdown.vue'
4141
4242
const route = useRoute()
@@ -51,6 +51,14 @@ const loginUsername = ref('')
5151
const logoffurl = ref('')
5252
const obpApiVersions = ref(inject(obpApiActiveVersionsKey) || [])
5353
const obpMessageDocs = ref(Object.keys(inject(obpGroupedMessageDocsKey) || {}))
54+
const obpMessageDocsJsonSchema = ref(Object.keys(inject(obpGroupedMessageDocsJsonSchemaKey) || {}))
55+
56+
// Combine message docs with JSON Schema items (with "J Schema" postfix)
57+
const combinedMessageDocs = computed(() => {
58+
const regularDocs = obpMessageDocs.value || []
59+
const jsonSchemaDocs = (obpMessageDocsJsonSchema.value || []).map(connector => `${connector} J Schema`)
60+
return [...regularDocs, ...jsonSchemaDocs]
61+
})
5462
5563
// Debug menu items
5664
const debugMenuItems = ref(['/debug/providers-status', '/debug/oidc'])
@@ -189,8 +197,8 @@ const setActive = (target: HTMLElement | null) => {
189197
}
190198
}
191199
192-
const handleMore = (command: string) => {
193-
console.log('handleMore called with command:', command)
200+
const handleMore = (command: string, source?: string) => {
201+
console.log('handleMore called with command:', command, 'source:', source)
194202
195203
// Ignore divider
196204
if (command === '---') {
@@ -201,11 +209,22 @@ const handleMore = (command: string) => {
201209
if (element !== null) {
202210
element.textContent = command;
203211
}
204-
if (command === '/message-docs') {
212+
213+
// Check if command ends with " J Schema" - if so, it's a JSON Schema message doc
214+
if (command.endsWith(' J Schema')) {
215+
const connector = command.replace(' J Schema', '')
216+
console.log('Navigating to message docs JSON schema:', connector)
217+
router.push({ name: 'message-docs-json-schema', params: { id: connector } })
218+
} else if (command === '/message-docs') {
205219
// Navigate to message docs list
206220
console.log('Navigating to message docs list')
207221
router.push({ name: 'message-docs-list' })
222+
} else if (command === '/message-docs-json-schema') {
223+
// Navigate to message docs JSON schema list
224+
console.log('Navigating to message docs JSON schema list')
225+
router.push({ name: 'message-docs-json-schema-list' })
208226
} else if (command.includes('_')) {
227+
// Regular message docs (connector names contain underscores)
209228
console.log('Navigating to message docs:', command)
210229
router.push({ name: 'message-docs', params: { id: command } })
211230
} else if (command.startsWith('/debug/')) {
@@ -292,7 +311,7 @@ const getCurrentPath = () => {
292311
class="menu-right"
293312
id="header-nav-message-docs"
294313
label="Message Docs"
295-
:items="obpMessageDocs"
314+
:items="combinedMessageDocs"
296315
:hover-color="headerLinksHoverColor"
297316
:background-color="headerLinksBackgroundColor"
298317
@select="handleMore"

src/main.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ import { createI18n } from 'vue-i18n'
3838
import { languages, defaultLocale } from './language'
3939

4040
import { cache as cacheResourceDocs, cacheDoc as cacheResourceDocsDoc } from './obp/resource-docs'
41-
import { cache as cacheMessageDocs, cacheDoc as cacheMessageDocsDoc } from './obp/message-docs'
41+
import {
42+
cache as cacheMessageDocs,
43+
cacheDoc as cacheMessageDocsDoc,
44+
cacheJsonSchema as cacheMessageDocsJsonSchema,
45+
cacheDocJsonSchema as cacheMessageDocsJsonSchemaDoc
46+
} from './obp/message-docs'
4247
import { OBP_API_VERSION, getMyAPICollections, getMyAPICollectionsEndpoint } from './obp'
4348
import { getOBPGlossary } from './obp/glossary'
4449

@@ -47,16 +52,18 @@ import './assets/main.css'
4752
import '@fontsource/roboto/300.css'
4853
import '@fontsource/roboto/400.css'
4954
import '@fontsource/roboto/700.css'
55+
56+
import { getCacheStorageInfo } from './obp/common-functions'
5057
import {
5158
obpApiActiveVersionsKey,
5259
obpApiHostKey,
5360
obpGlossaryKey,
5461
obpGroupedMessageDocsKey,
62+
obpGroupedMessageDocsJsonSchemaKey,
5563
obpGroupedResourceDocsKey,
5664
obpMyCollectionsEndpointKey,
5765
obpResourceDocsKey
5866
} from './obp/keys'
59-
import { getCacheStorageInfo } from './obp/common-functions'
6067
;(async () => {
6168
const app = createApp(App)
6269
const router = await appRouter()
@@ -272,6 +279,13 @@ async function setupData(app: App<Element>, worker: Worker) {
272279
const cacheStorageOfMessageDocs = await caches.open('obp-message-docs-cache') // Please note: The global 'caches' read-only property returns the 'CacheStorage' object associated with the current context.
273280
// 'match': Checks if a given Request is a key in any of the Cache objects that the CacheStorage object tracks, and returns a Promise that resolves to that match.
274281
const cachedResponseOfMessageDocs = await cacheStorageOfMessageDocs.match('/')
282+
// 'open': Returns a Promise that resolves to the Cache object matching the cacheName(obp-message-docs-json-schema-cache) (a new cache is created if it doesn't already exist.)
283+
const cacheStorageOfMessageDocsJsonSchema = await caches.open(
284+
'obp-message-docs-json-schema-cache'
285+
) // Please note: The global 'caches' read-only property returns the 'CacheStorage' object associated with the current context.
286+
// 'match': Checks if a given Request is a key in any of the Cache objects that the CacheStorage object tracks, and returns a Promise that resolves to that match.
287+
const cachedResponseOfMessageDocsJsonSchema =
288+
await cacheStorageOfMessageDocsJsonSchema.match('/')
275289

276290
// Listen to Web worker
277291
worker.onmessage = async (event) => {
@@ -286,6 +300,10 @@ async function setupData(app: App<Element>, worker: Worker) {
286300
await cacheMessageDocsDoc(cacheStorageOfMessageDocs)
287301
console.log('Message Docs cache was updated.')
288302
}
303+
if (event.data === 'update-message-docs-json-schema') {
304+
await cacheMessageDocsJsonSchemaDoc(cacheStorageOfMessageDocsJsonSchema)
305+
console.log('Message Docs JSON Schema cache was updated.')
306+
}
289307
}
290308

291309
const { resourceDocs, groupedDocs } = await cacheResourceDocs(
@@ -298,6 +316,11 @@ async function setupData(app: App<Element>, worker: Worker) {
298316
cachedResponseOfMessageDocs,
299317
worker
300318
)
319+
const messageDocsJsonSchema = await cacheMessageDocsJsonSchema(
320+
cacheStorageOfMessageDocsJsonSchema,
321+
cachedResponseOfMessageDocsJsonSchema,
322+
worker
323+
)
301324

302325
// Provide data to a component's descendants
303326
// App-level provides are available to all components rendered in the app
@@ -306,6 +329,7 @@ async function setupData(app: App<Element>, worker: Worker) {
306329
app.provide(obpApiActiveVersionsKey, Object.keys(resourceDocs).sort())
307330
app.provide(obpGroupedResourceDocsKey, groupedDocs)
308331
app.provide(obpGroupedMessageDocsKey, messageDocs)
332+
app.provide(obpGroupedMessageDocsJsonSchemaKey, messageDocsJsonSchema)
309333
app.provide(obpApiHostKey, import.meta.env.VITE_OBP_API_HOST)
310334
const glossary = await getOBPGlossary()
311335
app.provide(obpGlossaryKey, glossary)

src/obp/keys.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const obpResourceDocsKey = Symbol('OBP-ResourceDocs') as InjectionKey<any
3131
export const obpApiActiveVersionsKey = Symbol('OBP-APIActiveVersions') as InjectionKey<any>
3232
export const obpGroupedResourceDocsKey = Symbol('OBP-GroupedResourceDocs') as InjectionKey<any>
3333
export const obpGroupedMessageDocsKey = Symbol('OBP-GroupedMessageDocs') as InjectionKey<any> // This cause an issue
34+
export const obpGroupedMessageDocsJsonSchemaKey = Symbol(
35+
'OBP-GroupedMessageDocsJsonSchema'
36+
) as InjectionKey<any>
3437
export const obpApiHostKey = Symbol('OBP-API-Host') as InjectionKey<any>
3538
export const obpGlossaryKey = Symbol('OBP-Glossary') as InjectionKey<any>
36-
export const obpMyCollectionsEndpointKey = Symbol('OBP-MyCollectionsEndpoint') as InjectionKey<any>
39+
export const obpMyCollectionsEndpointKey = Symbol('OBP-MyCollectionsEndpoint') as InjectionKey<any>

src/obp/message-docs.ts

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,55 @@ export async function getOBPMessageDocs(item: string): Promise<any> {
4343
return await get(`obp/${OBP_API_VERSION}/message-docs/${item}`)
4444
}
4545

46-
export function getGroupedMessageDocs(docs: any): Promise<any> {
46+
// Get Message Docs JSON Schema
47+
export async function getOBPMessageDocsJsonSchema(item: string): Promise<any> {
48+
const logMessage = `Loading message docs JSON schema { connector: ${item} }`
49+
console.log(logMessage)
50+
updateLoadingInfoMessage(logMessage)
51+
return await get(`obp/v6.0.0/message-docs/${item}/json-schema`)
52+
}
53+
54+
export function getGroupedMessageDocs(docs: any): any {
4755
return docs.message_docs.reduce((values: any, doc: any) => {
4856
const tag = doc.adapter_implementation.group.replace('-', '').trim()
4957
;(values[tag] = values[tag] || []).push(doc)
5058
return values
5159
}, {})
5260
}
5361

62+
export function getGroupedMessageDocsJsonSchema(docs: any): any {
63+
if (!docs.definitions || typeof docs.definitions !== 'object') {
64+
return {}
65+
}
66+
67+
// Convert definitions object to array format and group by InBound/OutBound prefix
68+
const grouped: any = {}
69+
Object.keys(docs.definitions).forEach((methodName: string) => {
70+
const schema = docs.definitions[methodName]
71+
72+
// Determine category based on method name prefix
73+
let category = 'Uncategorized'
74+
if (methodName.startsWith('InBound')) {
75+
category = 'Inbound Methods'
76+
} else if (methodName.startsWith('OutBound')) {
77+
category = 'Outbound Methods'
78+
}
79+
80+
if (!grouped[category]) {
81+
grouped[category] = []
82+
}
83+
84+
grouped[category].push({
85+
method_name: methodName,
86+
category: category,
87+
request_schema: schema,
88+
response_schema: schema
89+
})
90+
})
91+
92+
return grouped
93+
}
94+
5495
export async function cacheDoc(cacheStorageOfMessageDocs: any): Promise<any> {
5596
const messageDocs = await connectors.reduce(async (agroup: any, connector: any) => {
5697
const logMessage = `Caching message docs { connector: ${connector} }`
@@ -71,11 +112,30 @@ async function getCacheDoc(cacheStorageOfMessageDocs: any): Promise<any> {
71112
return await cacheDoc(cacheStorageOfMessageDocs)
72113
}
73114

74-
export async function cache(
75-
cacheStorage: any,
76-
cachedResponse: any,
77-
worker: any
78-
): Promise<any> {
115+
export async function cacheDocJsonSchema(cacheStorageOfMessageDocsJsonSchema: any): Promise<any> {
116+
const messageDocsJsonSchema = await connectors.reduce(async (agroup: any, connector: any) => {
117+
const logMessage = `Caching message docs JSON schema { connector: ${connector} }`
118+
console.log(logMessage)
119+
updateLoadingInfoMessage(logMessage)
120+
const group = await agroup
121+
const docs = await getOBPMessageDocsJsonSchema(connector)
122+
if (!Object.keys(docs).includes('code')) {
123+
group[connector] = getGroupedMessageDocsJsonSchema(docs)
124+
}
125+
return group
126+
}, Promise.resolve({}))
127+
await cacheStorageOfMessageDocsJsonSchema.put(
128+
'/',
129+
new Response(JSON.stringify(messageDocsJsonSchema))
130+
)
131+
return messageDocsJsonSchema
132+
}
133+
134+
async function getCacheDocJsonSchema(cacheStorageOfMessageDocsJsonSchema: any): Promise<any> {
135+
return await cacheDocJsonSchema(cacheStorageOfMessageDocsJsonSchema)
136+
}
137+
138+
export async function cache(cacheStorage: any, cachedResponse: any, worker: any): Promise<any> {
79139
try {
80140
worker.postMessage('update-message-docs')
81141
return await cachedResponse.json()
@@ -87,3 +147,20 @@ export async function cache(
87147
return await getCacheDoc(cacheStorage)
88148
}
89149
}
150+
151+
export async function cacheJsonSchema(
152+
cacheStorage: any,
153+
cachedResponse: any,
154+
worker: any
155+
): Promise<any> {
156+
try {
157+
worker.postMessage('update-message-docs-json-schema')
158+
return await cachedResponse.json()
159+
} catch (error) {
160+
console.warn('No message docs JSON schema cache or malformed cache.')
161+
console.log('Caching message docs JSON schema...')
162+
const isServerActive = await isServerUp()
163+
if (!isServerActive) throw new Error('API Server is not responding.')
164+
return await getCacheDocJsonSchema(cacheStorage)
165+
}
166+
}

src/router/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import GlossaryView from '../views/GlossaryView.vue'
3030
import HelpView from '../views/HelpView.vue'
3131
import MessageDocsView from '../views/MessageDocsView.vue'
3232
import MessageDocsListView from '../views/MessageDocsListView.vue'
33+
import MessageDocsJsonSchemaView from '../views/MessageDocsJsonSchemaView.vue'
34+
import MessageDocsJsonSchemaListView from '../views/MessageDocsJsonSchemaListView.vue'
3335
import BodyView from '../views/BodyView.vue'
3436
import Content from '../components/Content.vue'
3537
import Preview from '../components/Preview.vue'
@@ -86,6 +88,16 @@ export default async function router(): Promise<any> {
8688
name: 'message-docs',
8789
component: isServerActive ? MessageDocsView : InternalServerErrorView
8890
},
91+
{
92+
path: '/message-docs-json-schema',
93+
name: 'message-docs-json-schema-list',
94+
component: isServerActive ? MessageDocsJsonSchemaListView : InternalServerErrorView
95+
},
96+
{
97+
path: '/message-docs-json-schema/:id',
98+
name: 'message-docs-json-schema',
99+
component: isServerActive ? MessageDocsJsonSchemaView : InternalServerErrorView
100+
},
89101
{
90102
path: '/resource-docs',
91103
redirect: () => {

0 commit comments

Comments
 (0)