lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.54k stars 499 forks source link

Swagger schema not generated in the order declared in type or interface #1471

Closed IOUIOU50 closed 1 year ago

IOUIOU50 commented 1 year ago

Sorting

Expected Behavior

I wrote ts interface like

interface PostTestBody {
  name: string;
  value: string;
  detail: {
    first: string;
    second?: string;
    third?: string;
  };
}

and then write a controller codes

@Route("/test")
export class TestController extends Controller {
  @Post("")
  async postTest(@Body() body: PostTestBody): Promise<PostTestBody> {
    return body;
  }
}

what I expected is

// expected PostTestBody swagger schema
{
  "properties": {
    "name": {
      "type": "string"
    },
    "value": {
      "type": "string"
    },
    "detail": {
      "properties": { // properties of 'detail' is ordered in "first" -> "second" -> "third"
        "first" { 
          "type": "string"
        },
        "second": {
          "type": "string"
        },
        "third" {
          "type": "string"
        }
      },
      "required": ["first"],
      "type": "object"
    }
  },
  "required": ["name", "value", "detail"],
  "type": "object",
  "additionalProperties": false
}

Current Behavior

// actual PostTestBody swagger schema
{
  "properties": {
    "name": {
      "type": "string"
    },
    "value": {
      "type": "string"
    },
    "detail": {
      "properties": { // properties of 'detail' is reversed from what I defined in interface
        "third": { 
          "type": "string"
        },
        "second": {
          "type": "string"
        },
        "first": {
          "type": "string"
        }
      },
      "required": ["first"],
      "type": "object"
    }
  },
  "required": ["name", "value", "detail"],
  "type": "object",
  "additionalProperties": false
}

Context (Environment)

Version of the library: 5.1.1 Version of NodeJS: 16.16.0

github-actions[bot] commented 1 year ago

Hello there IOUIOU50 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

IOUIOU50 commented 1 year ago

(translated from Korean) First, I would like to thank the contributors for providing such a great framework.

I've recently been interested in backend frameworks utilizing node.js and typescript.

I came across this framework and was learning about it in depth as I really appreciate the philosophy behind TSOA and was building a project with the intention of putting it into production.

The server I'm building is very dependent on the schema order of the BODY or PARAMETERS contained in SWAGGER. Any suggestions on what alternatives I can use in this case would be greatly appreciated.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days