Open lah-wag opened 10 months ago
We don't support multiple content-types yet, but we'll work on it in the near future.
I'm thinking of working with the following format, what do you think?
export type UserApiSpec = Tspec.DefineApiSpec<{
tags: ["Users"];
paths: {
"/api/users": {
get: {
summary: "Get all users";
responses: {
/** @mediaType ["application/json", "text/xml"] */
200: Users[];
};
};
};
};
}>;
We don't support multiple content-types yet, but we'll work on it in the near future.
I'm thinking of working with the following format, what do you think?
export type UserApiSpec = Tspec.DefineApiSpec<{ tags: ["Users"]; paths: { "/api/users": { get: { summary: "Get all users"; responses: { /** @mediaType ["application/json", "text/xml"] */ 200: Users[]; }; }; }; }; }>;
Glad that you find it useful and will consider adding the feature. To align with OpenAPI I think that individual mediatypes should have their own response object. Something like this:
export type UserApiSpec = Tspec.DefineApiSpec<{
tags: ["Users"];
paths: {
"/api/users": {
get: {
summary: "Get all users";
responses: {
200: {
"application/json": Users[],
"application/xml": UsersXML[],
"text/plain": string,
}
};
};
};
};
}>;
Obviously this example should be reworked to use annotations instead.
any updates on this? @hyeonss0417 we'd appreciate update on multipart/form-data
@yeonjoon-ridi If you only want to use multipart/form-data, you can follow the instructions below, as described in the Tspec official documentation.
export type FileApiSpec = Tspec.DefineApiSpec<{
paths: {
'/files/upload': {
post: {
summary: 'Upload File',
/** @mediaType multipart/form-data */
body: {
file: Tspec.BinaryString;
},
responses: { 200: { fileName: string } },
},
},
},
}>;
Or do you want to create schemas with multiple response formats within the same status code, as discussed above?
Hey,
Is it possible to describe a response with multiple content-types using tspec? Example from: https://swagger.io/docs/specification/describing-responses/
It seems that I would add the mediatype as js-doc to the reponse like in this example: https://ts-spec.github.io/tspec/guide/file-upload-download#file-download
But that just takes the last value: