-
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.
feat: Add routePath to Resource and blueprint.events (#141)
Co-authored-by: Seam Bot <[email protected]>
- Loading branch information
1 parent
87880b2
commit 8e09da6
Showing
12 changed files
with
10,293 additions
and
2,421 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
38 changes: 38 additions & 0 deletions
38
src/lib/openapi/find-common-openapi-schema-properties.test.ts
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,38 @@ | ||
import test from 'ava' | ||
|
||
import type { OpenapiSchema } from 'lib/openapi/types.js' | ||
|
||
import { findCommonOpenapiSchemaProperties } from './find-common-openapi-schema-properties.js' | ||
|
||
test('findCommonOpenapiSchemaProperties: extracts common properties from openapi schemas', (t) => { | ||
const schemas: OpenapiSchema[] = [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
event_id: { type: 'string', format: 'uuid' }, | ||
event_type: { type: 'string' }, | ||
created_at: { type: 'string', format: 'date-time' }, | ||
foo_id: { type: 'string' }, | ||
}, | ||
}, | ||
{ | ||
type: 'object', | ||
properties: { | ||
event_id: { type: 'string', format: 'uuid' }, | ||
event_type: { type: 'string' }, | ||
created_at: { type: 'string', format: 'date-time' }, | ||
bar_id: { type: 'string' }, | ||
}, | ||
}, | ||
] | ||
|
||
const commonProps = findCommonOpenapiSchemaProperties(schemas) | ||
const commonKeys = Object.keys(commonProps) | ||
|
||
t.is(commonKeys.length, 3) | ||
t.true( | ||
['event_id', 'event_type', 'created_at'].every((key) => | ||
commonKeys.includes(key), | ||
), | ||
) | ||
}) |
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,36 @@ | ||
import type { OpenapiSchema } from 'lib/openapi/types.js' | ||
|
||
export function findCommonOpenapiSchemaProperties( | ||
schemas: OpenapiSchema[], | ||
): Record<string, OpenapiSchema> { | ||
const firstSchema = schemas[0] | ||
if (schemas.length === 0 || firstSchema?.properties == null) { | ||
return {} | ||
} | ||
|
||
return Object.entries(firstSchema.properties).reduce< | ||
Record<string, OpenapiSchema> | ||
>((commonProps, [propKey, propValue]) => { | ||
const isPropInAllSchemas = schemas.every((schema) => | ||
Object.keys(schema.properties ?? {}).includes(propKey), | ||
) | ||
|
||
if (!isPropInAllSchemas) { | ||
return commonProps | ||
} | ||
|
||
if ('enum' in propValue) { | ||
const mergedEnumValues = schemas.reduce<string[]>((allEnums, schema) => { | ||
const enumValues = schema.properties?.[propKey]?.enum ?? [] | ||
return [...new Set([...allEnums, ...enumValues])] | ||
}, []) | ||
|
||
return { | ||
...commonProps, | ||
[propKey]: { ...propValue, enum: mergedEnumValues }, | ||
} | ||
} | ||
|
||
return { ...commonProps, [propKey]: propValue } | ||
}, {}) | ||
} |
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,3 @@ | ||
export * from './find-common-openapi-schema-properties.js' | ||
export * from './schemas.js' | ||
export * from './types.js' |
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
Oops, something went wrong.