-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from naohito-T/feature/openapi
Feature/openapi
- Loading branch information
Showing
20 changed files
with
410 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
components: | ||
schemas: | ||
ErrorDetail: | ||
additionalProperties: false | ||
properties: | ||
location: | ||
description: Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id' | ||
type: string | ||
message: | ||
description: Error message text | ||
type: string | ||
value: | ||
description: The value at the given location | ||
type: object | ||
ErrorModel: | ||
additionalProperties: false | ||
properties: | ||
$schema: | ||
description: A URL to the JSON Schema for this object. | ||
examples: | ||
- http://localhost:6500/api/v1/schemas/ErrorModel.json | ||
format: uri | ||
readOnly: true | ||
type: string | ||
detail: | ||
description: A human-readable explanation specific to this occurrence of the problem. | ||
examples: | ||
- Property foo is required but is missing. | ||
type: string | ||
errors: | ||
description: Optional list of individual error details | ||
items: | ||
$ref: "#/components/schemas/ErrorDetail" | ||
type: array | ||
instance: | ||
description: A URI reference that identifies the specific occurrence of the problem. | ||
examples: | ||
- https://example.com/error-log/abc123 | ||
format: uri | ||
type: string | ||
status: | ||
description: HTTP status code | ||
examples: | ||
- 400 | ||
format: int64 | ||
type: integer | ||
title: | ||
description: A short, human-readable summary of the problem type. This value should not change between occurrences of the error. | ||
examples: | ||
- Bad Request | ||
type: string | ||
type: | ||
default: about:blank | ||
description: A URI reference to human-readable documentation for the error. | ||
examples: | ||
- https://example.com/errors/example | ||
format: uri | ||
type: string | ||
type: object | ||
GreetingOutput3Body: | ||
additionalProperties: false | ||
properties: | ||
$schema: | ||
description: A URL to the JSON Schema for this object. | ||
examples: | ||
- http://localhost:6500/api/v1/schemas/GreetingOutput3Body.json | ||
format: uri | ||
readOnly: true | ||
type: string | ||
message: | ||
description: Greeting message | ||
examples: | ||
- Hello, world! | ||
type: string | ||
required: | ||
- message | ||
type: object | ||
HealthCheckParams2Body: | ||
additionalProperties: false | ||
properties: | ||
$schema: | ||
description: A URL to the JSON Schema for this object. | ||
examples: | ||
- http://localhost:6500/api/v1/schemas/HealthCheckParams2Body.json | ||
format: uri | ||
readOnly: true | ||
type: string | ||
message: | ||
description: Greeting message | ||
examples: | ||
- Hello, world! | ||
type: string | ||
required: | ||
- message | ||
type: object | ||
securitySchemes: | ||
bearer: | ||
bearerFormat: JWT | ||
scheme: bearer | ||
type: http | ||
info: | ||
title: TinyURL | ||
version: 1.0.0 | ||
openapi: 3.1.0 | ||
paths: | ||
/greeting/{name}: | ||
get: | ||
description: Get a greeting for a person by name. | ||
operationId: get-greeting | ||
parameters: | ||
- description: Name to greet | ||
example: world | ||
in: path | ||
name: name | ||
required: true | ||
schema: | ||
description: Name to greet | ||
examples: | ||
- world | ||
maxLength: 30 | ||
type: string | ||
responses: | ||
"200": | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/GreetingOutput3Body" | ||
description: OK | ||
default: | ||
content: | ||
application/problem+json: | ||
schema: | ||
$ref: "#/components/schemas/ErrorModel" | ||
description: Error | ||
summary: Get a greeting | ||
tags: | ||
- Greetings | ||
/health: | ||
get: | ||
description: Check the health of the service. | ||
operationId: health | ||
responses: | ||
"200": | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/HealthCheckParams2Body" | ||
description: OK | ||
default: | ||
content: | ||
application/problem+json: | ||
schema: | ||
$ref: "#/components/schemas/ErrorModel" | ||
description: Error | ||
summary: Health Check | ||
tags: | ||
- Greetings | ||
servers: | ||
- url: http://localhost:6500/api/v1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
package configs | ||
|
||
const ( | ||
// ApplicationPort is the port the application listens on. | ||
ApplicationPort = ":6500" | ||
OpenAPITitle = "TinyURL" | ||
OpenAPIVersion = "1.0.0" | ||
// OpenAPITitle is the title of the OpenAPI spec. | ||
OpenAPITitle = "TinyURL API" | ||
// OpenAPIVersion is the version of the OpenAPI spec. | ||
OpenAPIVersion = "1.0.0" | ||
// OpenAPIServerPath is the base URL for the OpenAPI spec. | ||
OpenAPIDocServerPath = "http://localhost:6500/api/v1" | ||
) | ||
|
||
// OperationID: このAPI操作の一意の識別子。これは、API内で操作を参照する際に使用されます。 | ||
// Method: HTTPメソッドを指定します。この例では http.MethodGet が使われており、これはHTTPのGETリクエストを示します。 | ||
// Path: エンドポイントのURLパスを指定します。ここでは "/greeting/{name}" となっており、{name} はパスパラメータを表しています。 | ||
// Summary: 短い説明文です。APIのドキュメントに表示され、APIの目的を簡潔に説明します。 | ||
// Description: APIエンドポイントの詳細な説明です。ここでは操作の詳細や動作についての追加情報を提供します。 | ||
// Tags: このAPI操作に関連付けられたタグのリストです。これにより、APIドキュメント内で類似の操作をグループ化することができます。 | ||
|
||
// huma.Register(app, huma.Operation{ | ||
// OperationID: "health", | ||
// Method: http.MethodGet, | ||
// Path: Router.Health, | ||
// Summary: "Health Check", | ||
// Description: "Check the health of the service.", | ||
// Tags: []string{"Public"}, | ||
// }, func(_ context.Context, _ *HealthCheckParams) (*HealthCheckQuery, error) { | ||
// resp := &HealthCheckQuery{ | ||
// Body: struct{ | ||
// Message string `json:"message,omitempty" example:"Hello, world!" doc:"Greeting message"` | ||
// }{ | ||
// Message: "ok", | ||
// }, | ||
// } | ||
// fmt.Printf("Health Check: %v\n", resp.Body.Message) | ||
// return resp, nil | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
package domain | ||
|
||
import ( | ||
"crypto/sha1" | ||
"encoding/base64" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type ShortURL struct { | ||
ID string `json:"id"` | ||
OriginalURL string `json:"original"` | ||
OriginalURL string `json:"original_url"` | ||
CreatedAt string `json:"created_at"` | ||
} | ||
|
||
func GenerateShortURL(originalURL string) *ShortURL { | ||
hasher := sha1.New() | ||
hasher.Write([]byte(originalURL)) | ||
sha := base64.URLEncoding.EncodeToString(hasher.Sum(nil)) | ||
return &ShortURL{ | ||
ID: strings.TrimRight(sha, "=")[:7], | ||
OriginalURL: originalURL, | ||
CreatedAt: time.Now().Format(time.RFC3339), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.