Skip to content

Commit

Permalink
feat(schema): add sortPaths option to sort swagger paths by alphabeti…
Browse files Browse the repository at this point in the history
…cal order
  • Loading branch information
Romakita committed Oct 24, 2024
1 parent 2720e6a commit 968aff8
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 102 deletions.
7 changes: 2 additions & 5 deletions docs/tutorials/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ The path option for Swagger will be used to expose the documentation:
Ts.ED will print the swagger-ui url in the console.
:::

::: warning
OpenSpec 2 support will be removed in v7.
:::

::: warning
When using helmet, there may be a problem with CSP, to solve this collision, configure the CSP as shown below:

Expand Down Expand Up @@ -92,7 +88,7 @@ export class Server {}
Some options are available to configure Swagger-ui, Ts.ED and the default spec information.

| Key | Example | Description |
| -------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|----------------------|---------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| path | `/api-doc` | The url subpath to access to the documentation. |
| specVersion | `2.0`, `3.0.1` | The OpenSpec version. |
| fileName | `swagger.json` | Swagger file name. By default swagger.json. |
Expand All @@ -110,6 +106,7 @@ Some options are available to configure Swagger-ui, Ts.ED and the default spec i
| operationIdFormatter | `(name: string, propertyKey: string, path: string) => string` | A function to generate the operationId. |
| operationIdPattern | `%c_%m` | A pattern to generate the operationId. Format of operationId field (%c: class name, %m: method name). |
| pathPatterns | `[]` | Include only controllers whose paths match the pattern list provided. |
| sortPaths | `true` | Sort paths by alphabetical order. |

### Multi documentations

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generateSpec() > OS 3.0.1 > should generate spec with sorted paths 1`] = `
{
"info": {
"title": "Api documentation",
"version": "1.0.0",
},
"openapi": "3.0.1",
"paths": {
"/rest/controller1": {
"get": {
"operationId": "controller1Method",
"parameters": [],
"responses": {
"200": {
"description": "Success",
},
},
"tags": [
"Controller1",
],
},
},
"/rest/controller1/test": {
"post": {
"operationId": "controller1Method5",
"parameters": [],
"responses": {
"200": {
"description": "Success",
},
},
"tags": [
"Controller1",
],
},
},
"/rest/controller1/{id}": {
"get": {
"operationId": "controller1MethodById",
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string",
},
},
],
"responses": {
"200": {
"description": "Success",
},
},
"tags": [
"Controller1",
],
},
},
"/rest/controller2": {
"get": {
"operationId": "controller2Method",
"parameters": [],
"responses": {
"200": {
"description": "Success",
},
},
"tags": [
"Controller2",
],
},
},
"/rest/controller2/{id}": {
"get": {
"operationId": "controller2MethodById",
"parameters": [
{
"in": "path",
"name": "id",
"required": true,
"schema": {
"type": "string",
},
},
],
"responses": {
"200": {
"description": "Success",
},
},
"tags": [
"Controller2",
],
},
},
},
"tags": [
{
"name": "Controller2",
},
{
"name": "Controller1",
},
],
}
`;
Loading

0 comments on commit 968aff8

Please sign in to comment.