Skip to content

ADB: modified OpenAPI @extension decorator to accept path array for key#3

Open
drpump wants to merge 3 commits intomainfrom
feat/ADB-extension-array
Open

ADB: modified OpenAPI @extension decorator to accept path array for key#3
drpump wants to merge 3 commits intomainfrom
feat/ADB-extension-array

Conversation

@drpump
Copy link
Owner

@drpump drpump commented Jun 5, 2025

No description provided.

"vitest": "^3.1.2",
"yaml": "~2.7.0"
"yaml": "~2.7.0",
"es-toolkit": "~1.36.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we didn't need to add another dependency just for this small use case.
It should also be added to the packages/openapi3/package.json here this is just for our workspace dev dependency which have no effect in published packages

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will replace this with a function once we have the other parts sorted out.

{
"path": "library-ts/package-lock.json",
"destination": "package-lock.json"
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should be reverted, if you did that just for testing

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the pnpm build created it. Can remove.

* In OpenAPI only unknown properties starting with `x-` are allowed.
* Type for extension keys, allowing both single string keys and arrays of strings.
*/
export type ExtensionKey = `x-${string}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would keep ExtensionKey to be this format as this does define accurately what you are allowed to do in openapi but instead just make it that the map of extension key to value is just a Map<string, unknown>

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in my other comment, this tends to suggest that we shouldn’t be using the @extension decorator to add attributes deep within the (non-extension) nested structure of the OpenAPI op mapping.

*/
export function getExtensions(program: Program, entity: Type): ReadonlyMap<ExtensionKey, any> {
return program.stateMap(openApiExtensionKey).get(entity) ?? new Map<ExtensionKey, any>();
export function getExtensions(program: Program, entity: Type): Array<ExtensionRecord> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing that will be quite a breaking change for anyone using the API.

was there an issue with saving the new data into program.stateMap(openApiDeepExtensionKey); or something like that and exposing a separate function that return those.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I preferred the approach of mapping string to a singleton array in the statemap: avoids semantic messiness. That said, if we have third-party apps calling this function then I agree that it makes backwards compatibility a problem. Have you discussed yet with your colleagues? If we are to distinguish the “deep” extensions then I’d prefer to have a different decorator to avoid that messiness.

Note that the need to bypass the “x-“ constraint on OpenAPI extensions also suggests we might consider a different decorator.

}

function isExtensionKey(key: string): key is ExtensionKey {
function isExtensionKey(key: string): boolean {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline with the other comments with ExtensionKey I think that should be reverted too

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. Will resolve according to the resolution of questions posed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants