openapi-types: Fixed OpenAPIV3_1.PathItemObject to accept OpenAPIV3_1…
….OperationObject
Problem
In my project, I was trying to construct a OpenAPIV3_1 object as follows
type OperationObjects = {
[method in OpenAPIV3_1.HttpMethods]?: OpenAPIV3_1.OperationObject;
};
const summary = "blah";
const description = "blah";
const operationObjects = getOperationObjects(routeConfig, routeData); // Returns OperationObjects
const parameterObjects = getParamsFromPath(path); // Return OpenAPIV3_1.ParameterObject
return {
...operationObjects,
parameters: parameterObjects,
summary, // string
description, // string
};
When spreading the object I get the following error: https://pastebin.com/XwXWuavS
Solution
I wouldn't consider myself a savvy typescript guy, but I assume the issue is due to the way the method -> OperationObject gets tacked on as a intersection on both V3 and V3_1. This will probably result in typescript interpreting
{
[method in HttpMethods]?: OpenAPIV3.OperationObject<T>
} &
{
[method in HttpMethods]?: OpenAPIV3_1.OperationObject<T>
}
Which I assume would just boil down to
{
[method in HttpMethods]?: OpenAPIV3.OperationObject<T>
}
To solve this, I Omit the original mapping of method to OpenAPIV3.OperationObject and add it back as method to OpenAPIV3_1.OperationObject as an intersection at the end. I am not sure if this is the most elegant solution, but it does work.
Sidenote: I also noticed a typescript error on PathsWebhooksComponents which I think I fixed too
@jsdevel care to take a look?
@AdrianMachado please fix the build
@AdrianMachado can you fix the build?
Sorry I forgot about this. I will take a look this weekend
I just came across this PR after pulling my hair on the same problem upgrading to OpenAPI 3.1. What can we do to help get this merged @AdrianMachado @jsdevel?
@soul-codes hey - I haven't really had time to fix this - feel free to take it over