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

Using a Type/Interface in "body" resulted in new declaration instead of a $ref #58

Open
programatix opened this issue Jun 10, 2024 · 0 comments
Assignees

Comments

@programatix
Copy link

Describe the bug
Take the following example,

interface MyResquest {
   title: string;
}
interface MyResponse {...}

type ApiSpec = Tspec.DefineApiSpec<{
     paths: {
        "/endpoint": {
            post: {
                summary: "summary",
                description: "description",
                body: MyResquest ,
                responses: { 201: MyResponse },
            }
        }
    },
}>;

will result in the following,

  "paths": {
    "/tasks": {
      "post": {
        "operationId": "...",
        "summary": "summary",
        "description": "description,
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "title"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TaskResponse"
                }
              }
            }
          }
        }
      }
   }
}

I'm expecting it to use $ref instead, as such,

  "paths": {
    "/tasks": {
      "post": {
        "operationId": "...",
        "summary": "summary",
        "description": "description,
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyResponse"
                }
              }
            }
          }
        }
      }
   }
}

Desktop (please complete the following information):

  • OS: Windows
  • Browser chrome

Additional context

  • "tspec": "^0.1.114"
@hyeonss0417 hyeonss0417 self-assigned this Jun 12, 2024
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

No branches or pull requests

2 participants