Input / output missing parameters in openapi.json
Hi,
hi I'm using openapi docs as input for ASM security. but the output from openapi does not correspond to the endpoints that are called within the application
trpc.record.find.useQuery({ id: 123 }) // called url /api/trpc/record.find?=input={"id":123}
this does not match the openapi docs
"/record.find": {
"get": {
"operationId": "query.record.find",
"parameters": [
{
"name": "id",
"in": "query",
"required": true,
"schema": {
"type": "number"
}
}
],
}
}
according to the trpc.io documentation
input: https://trpc.io/docs/rpc#methods---type-mapping output: https://trpc.io/docs/rpc#successful-response
these parameters are not in the openapi json, I cannot use this output when verifying requests and responses
is this problem solvable? Thanks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I'm experiencing the same issue, any update on this?
My workaround
utils/openapi.ts
import { OpenAPIV3 } from 'openapi-types';
import PathsObject = OpenAPIV3.PathsObject;
import ParameterObject = OpenAPIV3.ParameterObject;
export function getModifiedOpenApiDocs(openApiDocument: OpenAPIV3.Document) {
const newOpenApiDocument: OpenAPIV3.Document = { ...openApiDocument };
const newPaths: PathsObject<{}, {}> = {};
Object.entries(openApiDocument?.paths)?.map(([key, value]) => {
newPaths[key] = { ...value };
if (value.get) {
const properties = {};
value.get.parameters?.map((parameter: ParameterObject) => {
properties[parameter.name] = {
...parameter.schema,
description: parameter.description,
};
});
if (Object.values(properties).length > 0) {
newPaths[key].get.parameters = [
{
name: 'input',
in: 'query',
content: {
'application/json': {
schema: {
type: 'object',
properties: properties,
},
},
},
},
];
} else {
newPaths[key].get.parameters = [];
}
}
});
newOpenApiDocument.paths = newPaths;
return newOpenApiDocument;
}
Usage
export const openApiDocument = getModifiedOpenApiDocs(
generateOpenApiDocument(appRouter, {
title: 'Title',
version: '1.0.0',
baseUrl: 'your_url'
})
);
I don't understand the issue, could you clarify & provide a reproduction?
I think you might have misunderstood that trpc-openapi is a server-side adapter for your tRPC routers & it does not change the behavior of @trpc/client?