-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with newly introduced OpenAPI extension #703
Comments
Interesting edge case you've found. I wasn't aware of this behavior with the Can you describe your use case? What about the |
It creates a That said, I think that the library should let users extend its types the way they want. The proposed API does without much extra complexity. |
Need to fix the openapi-types version awaiting for the issue to be solved. fix #101 concerns kogosoftwarellc/open-api#703
How would your proposal do that in practice? Can you supply an example with several third-party extensions? With HEAD: const operationObject: OperationObject;
const apiGatewayIntegration = operationObject['x-amazon-apigateway-integration'] as ApiGatewayIntegration | undefined;
const expressRouter = operationObject['x-express-router'] as ExpressRouterExtension | undefined;
// ... any number of vendor-supplied extension types If I have N extensions that I want to access on the OperationObject, it seems like I would have to create N extensions of OperationObject and access them individually? I was trying to avoid forcing a user to do something like this, where they have to create a new type: interface UserSuppliedOperationObject extends OperationObject {
'x-apigateway-integration'?: ApiGatewayIntegration;
'x-express-router'?: ExpressRouterExtension;
}
const pathItemObject: PathItemObject;
const operationObjectWithExtensions = pathItemObject.get as UserSuppliedOperationObject;
const apiGatewayIntegration = operationObjectWithExtensions['x-amazon-apigateway-integration']; |
@jarruda Here (#704) is a sample config that would allow to do this: type myAPI = OpenAPI.Document<{
'x-apigateway-integration'?: ApiGatewayIntegration;
'x-express-router'?: ExpressRouterExtension;
}>; And fixes my problem: type Test = keyof OpenAPI.OperationObject<{}>; // type T = "tags" | "summary" | "description" | "externalDocs" | "operationId" | "parameters" | "requestBody" | "responses" | "callbacks" | "deprecated" | "security" | "servers" It also avoid weak typing by giving control to users. They can opt-in to OpenAPI extensions but, per default, the compiler will complain if one uses an unknown property. |
If you prefer default to weak types, just replace |
Interesting approach. I think you would want to extend it to support adding extensions at any supported level in the spec: https://swagger.io/specification/ (look for "This object MAY be extended with Specification Extensions.") Otherwise, it could create a backwards-incompatible scenario when one wants to add an extension to a new class.
I think, ideally, an extension vendor would write a package that adds their extension types to a Document. I would prefer that I, as a user, weren't able to accidentally add an |
I use this handy module but the recent changes (d0241d6) broken my code here: https://github.com/nfroidure/whook/blob/master/packages/whook-http-transaction/src/index.ts#L53-L62
Indeed, before that update, I was able to access the
OperationObject
interface keys to extend it but now, it only givesstring | number
, here is a portion of code to understand the problem:I think the commit should be reverted since it is a breaking change and instead create a major version with something like this to allow a better customization and keep a chance to access the keys of a parameter object to users:
Best would be to propagate the extension type from the OpenAPI.Document type to OperationObject downstream.
I can create a PR if you wish, just let me know.
The text was updated successfully, but these errors were encountered: