Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AdrianMachado
Copy link

….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
Copy link
Author

@jsdevel care to take a look?

@jsdevel
Copy link
Contributor

jsdevel commented Apr 13, 2022

@AdrianMachado please fix the build

@jsdevel
Copy link
Contributor

jsdevel commented May 11, 2022

@AdrianMachado can you fix the build?

@AdrianMachado
Copy link
Author

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

@soul-codes
Copy link

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?

@AdrianMachado
Copy link
Author

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

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.

None yet

3 participants