swagen

package module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 2 Imported by: 0

README

swagen

What's swagen ??

swagen is the CLI tool implememted by Golang that improve your develop experiences when you use Swagger(OpenAPI).
Using swagen, you can generate API definition files on CLI without coding yourself.

Install

Use go install

$ go install github.com/Daaaai0809/swagen

If you want to use any version

$ go install github.com/Daaaai0809/swagen@vX.X.X

Usecase

When you use swagen in your project, you have to make env file in project root dir and define PATH_DIR, MODEL_DIR, MESSAGE_DIR params in that file.

env Example:

PATH_DIR="src/paths"
MODEL_DIR="src/components/models"
MESSAGE_DIR="src/components/schemas"
Path File

If you want to generate Path file, run this command:

$ swagen path <HTTP METHOD> -d <dir>

You can use http methods like below for HTTP METHOD parameter.

  • GET : get
  • POST : post
  • PUT : put
  • DELETE : delete

You can use --dir flag instead of -d flag also.

$ swagen path <HTTP METHOD> --dir=<dir>

The dir in this command is deeper directory than defined dir at PATH_DIR param.

Example:

$ swagen path get -d "front/users"

Definable fields are these:

  • OperationId
  • Summary
  • Description
  • Tags
  • Security
    • Select from these Security Types
      • APIKey
      • Bearer
      • BasicAuth
      • OAuth2
      • OpenId
  • Parameters
    • In
    • Description
    • Required
    • Schema
  • RequestBody(Only POST, PUT, DELETE)
    • Almost content-types are supported. If you need other content-type, please open issue.
    • Schema Fields
      • Type
      • Format
      • Required
      • Nullable
      • Properties(Type Object)
      • Items(Type Array)
  • Responses
    • You can use all response codes and select from those
    • Default response is supported also
    • Almost content-types are supported. If you need other content-type, please open issue.
Request/Response Schema

If you want to generate Request/Response Schema file, run this command.

$ swagen message <FileName> -d <dir>

Example schema:

TestResponse:
  type: object
  properties:
    id:
      type: integer
      format: int64
    name:
      type: string
    email:
      type: string
      format: email
      nullable: true
    tags:
      type: array
      items:
        type: object
        properties:
          id:
            type: integer
            format: int64
          name:
            type: string
        required:
        - id
        - name
  required:
  - id
  - name
  - email
  - tags
Model Schema

If you want to generate Model Schema (Data Object Definition) file, run this command.

$ swagen message <FileName> -d <dir>

Documentation

Index

Constants

View Source
const (
	PATH_DIR    = "PATH_DIR"
	MESSAGE_DIR = "MESSAGE_DIR"
	MODEL_DIR   = "MODEL_DIR"
)
View Source
const VERSION string = "0.0.1"

Variables

This section is empty.

Functions

func SetConfig

func SetConfig(c *Config)

Types

type Config

type Config struct {
	PathDir    string
	MessageDir string
	ModelDir   string
}

func GetConfig

func GetConfig() *Config

func NewConfig

func NewConfig() (*Config, error)

func (*Config) GetMessageDir

func (c *Config) GetMessageDir() string

func (*Config) GetModelDir

func (c *Config) GetModelDir() string

func (*Config) GetPathDir

func (c *Config) GetPathDir() string

Directories

Path Synopsis
cmd
run

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL