Skip to content

Commit

Permalink
update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
susumutomita committed May 21, 2024
1 parent 2572e3e commit 4145337
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __test__/example.http
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Content-Type: application/json
"title": "Test Post",
"body": "This is a test post.",
"tags": ["test", "example"],
"author_id": 10
"author_id": 335
}

###
Expand Down
54 changes: 54 additions & 0 deletions src/app/api-docs/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Tailwind CSSのクラスを使用してカスタムスタイルを追加します */

/* 背景色を白に設定 */
body {
@apply bg-white text-black;
}

.swagger-ui .topbar {
@apply bg-white;
}

.swagger-ui .info {
@apply bg-white text-black;
}

.swagger-ui .opblock {
@apply bg-white;
}

.swagger-ui .opblock .opblock-summary {
@apply bg-white border-gray-300;
}

.swagger-ui .opblock .opblock-summary-method {
@apply bg-gray-300 text-black;
}

.swagger-ui .opblock .opblock-summary-path {
@apply text-black;
}

.swagger-ui .opblock .opblock-summary-description {
@apply text-black;
}

.swagger-ui a {
@apply text-blue-600;
}

.swagger-ui .opblock-get .opblock-summary-method {
@apply bg-green-500;
}

.swagger-ui .opblock-post .opblock-summary-method {
@apply bg-blue-500;
}

.swagger-ui .opblock-put .opblock-summary-method {
@apply bg-yellow-500;
}

.swagger-ui .opblock-delete .opblock-summary-method {
@apply bg-red-500;
}
1 change: 1 addition & 0 deletions src/app/api-docs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
import './custom.css';

const ApiDocs = () => {
return <SwaggerUI url="/api/swagger" />;
Expand Down
14 changes: 6 additions & 8 deletions src/swagger/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const postsSwagger = {
paths: {
'/api/posts': {
get: {
tags: ['Posts'],
summary: 'Retrieve all posts',
responses: {
200: {
Expand Down Expand Up @@ -36,6 +37,7 @@ const postsSwagger = {
},
},
post: {
tags: ['Posts'],
summary: 'Create a new post',
requestBody: {
required: true,
Expand Down Expand Up @@ -70,6 +72,7 @@ const postsSwagger = {
},
'/api/posts/{id}': {
get: {
tags: ['Posts'],
summary: 'Retrieve a post by ID',
parameters: [
{
Expand All @@ -82,22 +85,15 @@ const postsSwagger = {
},
],
responses: {
200: {
201: {
description: 'A post object',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
id: { type: 'integer' },
createdAt: { type: 'string', format: 'date-time' },
updatedAt: { type: 'string', format: 'date-time' },
title: { type: 'string' },
body: { type: 'string' },
draft: { type: 'boolean' },
notice: { type: 'boolean' },
scope: { type: 'string' },
publishedAt: { type: 'string', format: 'date-time' },
authorId: { type: 'integer' },
tags: {
type: 'array',
Expand All @@ -114,6 +110,7 @@ const postsSwagger = {
},
},
put: {
tags: ['Posts'],
summary: 'Update a post by ID',
parameters: [
{
Expand Down Expand Up @@ -158,6 +155,7 @@ const postsSwagger = {
},
},
delete: {
tags: ['Posts'],
summary: 'Delete a post by ID',
parameters: [
{
Expand Down
5 changes: 5 additions & 0 deletions src/swagger/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const usersSwagger = {
paths: {
'/api/users': {
get: {
tags: ['Users'],
summary: 'Retrieve all users',
responses: {
200: {
Expand All @@ -25,6 +26,7 @@ const usersSwagger = {
},
},
post: {
tags: ['Users'],
summary: 'Create a new user',
requestBody: {
required: true,
Expand All @@ -50,6 +52,7 @@ const usersSwagger = {
},
'/api/users/{id}': {
get: {
tags: ['Users'],
summary: 'Retrieve a user by ID',
parameters: [
{
Expand Down Expand Up @@ -80,6 +83,7 @@ const usersSwagger = {
},
},
put: {
tags: ['Users'],
summary: 'Update a user by ID',
parameters: [
{
Expand Down Expand Up @@ -113,6 +117,7 @@ const usersSwagger = {
},
},
delete: {
tags: ['Users'],
summary: 'Delete a user by ID',
parameters: [
{
Expand Down

0 comments on commit 4145337

Please sign in to comment.