open-api icon indicating copy to clipboard operation
open-api copied to clipboard

openapi-types: Fixed OpenAPIV3_1.PathItemObject to accept OpenAPIV3_1…

Open AdrianMachado opened this issue 3 years ago • 6 comments

….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

AdrianMachado avatar Apr 08 '22 23:04 AdrianMachado

@jsdevel care to take a look?

AdrianMachado avatar Apr 11 '22 18:04 AdrianMachado

@AdrianMachado please fix the build

jsdevel avatar Apr 13 '22 17:04 jsdevel

@AdrianMachado can you fix the build?

jsdevel avatar May 11 '22 20:05 jsdevel

Sorry I forgot about this. I will take a look this weekend

AdrianMachado avatar May 11 '22 20:05 AdrianMachado

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 avatar May 18 '23 05:05 soul-codes

@soul-codes hey - I haven't really had time to fix this - feel free to take it over

AdrianMachado avatar May 26 '23 21:05 AdrianMachado