Skip to content

Commit

Permalink
[adonis v6]: add swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
llucasspot committed Jan 26, 2024
1 parent 1d59322 commit 66470fe
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 191 deletions.
1 change: 1 addition & 0 deletions adonisrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default defineConfig({
() => import('@adonisjs/session/session_provider'),
() => import('@adonisjs/auth/auth_provider'),
() => import('@adonisjs/ally/ally_provider'),
() => import('adonisjs-6-swagger/swagger_provider'),
],

/*
Expand Down
6 changes: 2 additions & 4 deletions config/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TODO v6 block the swagger v5 lib
// import { SwaggerConfig } from '@ioc:Adonis/Addons/Swagger'
import { SwaggerConfig } from 'adonisjs-6-swagger'

export default {
uiEnabled: true, //disable or enable swaggerUi route
Expand Down Expand Up @@ -33,5 +32,4 @@ export default {
},
mode: process.env.NODE_ENV === 'production' ? 'PRODUCTION' : 'RUNTIME',
specFilePath: 'docs/swagger.json',
// } as SwaggerConfig
}
} as SwaggerConfig
335 changes: 166 additions & 169 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,173 +5,6 @@
"version": "1.0.0",
"description": "My application with swagger docs"
},
"components": {
"securitySchemes": {
"bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" }
},
"schemas": {
"SerializedTrack": {
"type": "object",
"properties": {
"uri": { "type": "string" },
"popularity": { "type": "number" },
"name": { "type": "string" },
"trackId": { "type": "string" },
"album": { "type": "string" },
"image": {
"type": "object",
"properties": {
"height": { "type": "number" },
"url": { "type": "string" },
"width": { "type": "number" }
}
},
"artistName": { "type": "string" }
}
},
"ProfileToShow": {
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"id": { "$ref": "#/components/schemas/User/properties/id" },
"name": { "$ref": "#/components/schemas/User/properties/name" },
"image": { "type": "string" }
}
},
"songs": { "type": "array", "items": { "$ref": "#/components/schemas/Track" } }
}
},
"SerializedUser": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"email": { "type": "string" },
"dateOfBirth": { "type": "string", "format": "date-time" },
"description": { "type": "string" },
"avatarUrl": { "type": "string" },
"genderId": { "type": "string" },
"preferedGenderId": { "type": "string" }
}
},
"Gender": {
"type": "object",
"properties": {
"id": { "type": "number" },
"name": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" }
}
},
"Match": {
"type": "object",
"properties": {
"id": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"matcherUserId": { "type": "string" },
"matchedUserId": { "type": "string" }
}
},
"MatchRequest": {
"type": "object",
"properties": {
"id": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"matcherUserId": { "type": "string" },
"matchedUserId": { "type": "string" }
}
},
"Profile": {
"type": "object",
"properties": {
"id": { "type": "string" },
"dateOfBirth": { "type": "string", "format": "date-time" },
"description": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"preferedGender": { "type": "number" },
"gender": { "type": "number" },
"userId": { "type": "string" }
}
},
"Track": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"albumName": { "type": "string" },
"spotifyUri": { "type": "string" },
"spotifyImage": { "type": "string" },
"spotifyId": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"userId": { "type": "string" }
}
},
"User": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"email": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"profileId": { "type": "string" }
}
}
},
"responses": {
"NotFountException": {
"description": "Not Fount Exception",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": { "type": "string", "example": "NOT_FOUND: NOT_FOUND" }
}
}
}
}
}
}
}
},
"UnAuthorizedException": {
"description": "Unauthorized access",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "E_UNAUTHORIZED_ACCESS: Unauthorized access"
}
}
}
}
}
}
}
}
}
}
},
"paths": {
"/api/matches/": {
"get": {
Expand Down Expand Up @@ -290,6 +123,9 @@
}
}
},
"/api/auth/spotify": {
"get": { "tags": ["Spotify OAuth"], "responses": { "200": { "description": "Success" } } }
},
"/api/auth/logout": {
"get": {
"security": [{ "bearerAuth": [] }],
Expand Down Expand Up @@ -342,9 +178,170 @@
"401": { "$ref": "#/components/responses/UnAuthorizedException" }
}
}
}
},
"components": {
"schemas": {
"SerializedTrack": {
"type": "object",
"properties": {
"uri": { "type": "string" },
"popularity": { "type": "number" },
"name": { "type": "string" },
"trackId": { "type": "string" },
"album": { "type": "string" },
"image": {
"type": "object",
"properties": {
"height": { "type": "number" },
"url": { "type": "string" },
"width": { "type": "number" }
}
},
"artistName": { "type": "string" }
}
},
"ProfileToShow": {
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"id": { "$ref": "#/components/schemas/User/properties/id" },
"name": { "$ref": "#/components/schemas/User/properties/name" },
"image": { "type": "string" }
}
},
"songs": { "type": "array", "items": { "$ref": "#/components/schemas/Track" } }
}
},
"SerializedUser": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"email": { "type": "string" },
"dateOfBirth": { "type": "string", "format": "date-time" },
"description": { "type": "string" },
"avatarUrl": { "type": "string" },
"genderId": { "type": "string" },
"preferedGenderId": { "type": "string" }
}
},
"Gender": {
"type": "object",
"properties": {
"id": { "type": "number" },
"name": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" }
}
},
"MatchRequest": {
"type": "object",
"properties": {
"id": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"matcherUserId": { "type": "string" },
"matchedUserId": { "type": "string" }
}
},
"Match": {
"type": "object",
"properties": {
"id": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"matcherUserId": { "type": "string" },
"matchedUserId": { "type": "string" }
}
},
"Profile": {
"type": "object",
"properties": {
"id": { "type": "string" },
"dateOfBirth": { "type": "string", "format": "date-time" },
"description": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"preferedGender": { "type": "number" },
"gender": { "type": "number" },
"userId": { "type": "string" }
}
},
"Track": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"albumName": { "type": "string" },
"spotifyUri": { "type": "string" },
"spotifyImage": { "type": "string" },
"spotifyId": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"userId": { "type": "string" }
}
},
"User": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"email": { "type": "string" },
"createdAt": { "type": "string", "format": "date-time" },
"updatedAt": { "type": "string", "format": "date-time" },
"profileId": { "type": "string" }
}
}
},
"/api/auth/spotify": {
"get": { "tags": ["Spotify OAuth"], "responses": { "200": { "description": "Success" } } }
"responses": {
"NotFountException": {
"description": "Not Fount Exception",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": { "type": "string", "example": "NOT_FOUND: NOT_FOUND" }
}
}
}
}
}
}
}
},
"UnAuthorizedException": {
"description": "Unauthorized access",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "E_UNAUTHORIZED_ACCESS: Unauthorized access"
}
}
}
}
}
}
}
}
}
}
},
"tags": []
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@adonisjs/lucid": "^19.0.0",
"@adonisjs/session": "^7.1.1",
"@vinejs/vine": "^1.7.0",
"adonis5-swagger": "^1.4.1",
"adonisjs-6-swagger": "^1.0.0",
"axios": "^1.6.5",
"better-sqlite3": "^9.3.0",
"luxon": "^3.4.4",
Expand Down
Loading

0 comments on commit 66470fe

Please sign in to comment.