Skip to content

Commit e7a6e2b

Browse files
committedMar 5, 2025·
fix(schema.org): support name'd addresses
Fixes #509
1 parent fc1fb9e commit e7a6e2b

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
 

‎packages/schema-org/src/nodes/Event/index.test.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { defineEvent, defineOrganization, useSchemaOrg } from '../../'
2+
import { defineEvent, defineOrganization, definePlace, useSchemaOrg } from '../../'
33
import { injectSchemaOrg, useSetup } from '../../../test'
44

55
describe('defineEvent', () => {
@@ -262,4 +262,45 @@ describe('defineEvent', () => {
262262
currency: 'USD',
263263
})
264264
})
265+
266+
it('handles short address', async () => {
267+
await useSetup(async (head) => {
268+
useSchemaOrg(head, [
269+
defineEvent({
270+
name: 'The Adventures of Kira and Morrison',
271+
location: [
272+
definePlace({
273+
name: 'Snickerpark Stadium',
274+
address: {
275+
name: 'test',
276+
},
277+
}),
278+
],
279+
}),
280+
])
281+
282+
const graphNodes = await injectSchemaOrg(head)
283+
284+
expect(graphNodes).toMatchInlineSnapshot(`
285+
[
286+
{
287+
"@id": "https://example.com/#event",
288+
"@type": "Event",
289+
"inLanguage": "en-AU",
290+
"location": {
291+
"@type": "Place",
292+
"address": {
293+
"@type": "PostalAddress",
294+
"name": "test",
295+
},
296+
"name": "Snickerpark Stadium",
297+
},
298+
"name": "The Adventures of Kira and Morrison",
299+
},
300+
]
301+
`)
302+
}, {
303+
currency: 'USD',
304+
})
305+
})
265306
})

‎packages/schema-org/src/nodes/PostalAddress/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export interface PostalAddressSimple extends Thing {
2828
postOfficeBoxNumber?: string
2929
}
3030

31-
export interface PostalAddress extends PostalAddressSimple {}
31+
interface PostalAddressStrict extends PostalAddressSimple {}
32+
interface PostalAddressName extends Partial<PostalAddressSimple> {}
33+
34+
export type PostalAddress = PostalAddressStrict | PostalAddressName
3235

3336
export const addressResolver = defineSchemaOrgResolver<PostalAddress>({
3437
defaults: {

0 commit comments

Comments
 (0)
Please sign in to comment.