swagger: "2.0" info: description: {{ .Description }} title: {{.Name}} version: 1.0.0 consumes: - application/json produces: - application/json schemes: - http securityDefinitions: {{- if eq .AuthPath "bearer"}} authKey: description: Session token inside Authorization header. type: apiKey in: header name: Authorization {{- end}} {{- if eq .AuthPath "cookie"}} cookieKey: description: Session token inside cookie. type: apiKey in: header name: Cookie csrfToken: description: Token for CSRF protection (tied to session token). type: apiKey in: header name: X-CSRFTokenBound {{- end}} security: {{- if eq .AuthPath "bearer"}} - authKey: [] {{- end}} {{- if eq .AuthPath "cookie"}} - cookieKey: [] - cookieKey: [] csrfToken: [] {{- end}} paths: /healthCheck: get: tags: - Standard security: - {} operationId: healthCheck responses: 200: description: OK schema: type: object properties: ok: type: boolean {{- if .Debug}} /addTestData: post: tags: - Standard operationId: addTestData responses: 200: description: OK default: description: error schema: $ref: "#/definitions/error" {{- end}} {{- range $modelName, $model := $.Models}} {{- range $i, $method := $model.Methods}} /{{LowerTitle $modelName}}/{{LowerTitle (ToAppMethodName $method)}}: {{(index $model.MethodsProps $i).HTTPMethod}}: tags: {{- range $_, $tag := $model.Tags}} - {{$tag}} {{- end}} {{- if IsNoSecureMethod $method}} security: [] {{- end}} operationId: {{LowerTitle (ToAppMethodName $method)}}{{$model.TitleName}} {{- if or (IsValidateMethod $method) (not (or (and (IsGet $method) (IsMyMethod $method)) (and (IsDelete $method) (IsMyMethod $method))))}} parameters: {{- end}} {{- if IsValidateMethod $method}} - name: Validate in: header description: validation token required: true type: string {{- end}} {{- if not (or (and (IsGet $method) (IsMyMethod $method)) (and (IsDelete $method) (IsMyMethod $method)))}} - name: body in: body schema: {{- if or (and (IsGet $method) (not (IsMyMethod $method))) (and (IsDelete $method) (not (IsMyMethod $method)))}} type: object properties: id: type: {{if $model.IDIsUUID}}string{{else}}{{(index $model.Columns "id").Type}}{{end}} {{- else}} {{- if IsList $method}} $ref: "#/definitions/listParams" {{- else}} {{- if IsEdit $method}} type: object properties: {{- if not (and (IsEdit $method) (IsMyMethod $method))}} id: type: {{if $model.IDIsUUID}}string{{else}}int64{{end}} {{- end}} data: {{- if IsAdjustEdit $method}} type: object {{- $first := true}} {{- range $_, $column := $model.RequiredColumns}} {{- if ContainsStr (index $model.MethodsProps $i).EditableFields $column}} {{- if $first}} required: {{- $first = false}} {{- end}} - {{$column}} {{- end}} {{- end}} properties: {{- range $_, $name := (SortColumns $model.Columns)}} {{- $options := (index $model.Columns $name)}} {{- if ContainsStr (index $model.MethodsProps $i).EditableFields $name}} {{- if $options.IsStruct}} {{- if $options.IsArray}} {{$name}}: type: array items: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} {{- else}} {{$name}}: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} {{- end}} {{- else}} {{$name}}: {{- if $options.IsArray}} type: array items: {{- end}} {{- if $options.IsCustom}} $ref: "#/definitions/{{$options.Type}}" {{- else}} type: {{if eq $options.Type "uuid"}}string{{else}}{{$options.Type}}{{end}} {{- if $options.Format}} format: {{$options.Format}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- end}} {{- end}} {{- end}} {{- end}} {{- end}} {{- end}} {{- if not (IsAdjustEdit $method)}} $ref: "#/definitions/{{LowerTitle $modelName}}Add" {{- end}} {{- end}} {{- end}} {{- end}} responses: {{- if IsDelete $method}} 204: description: Deleted {{- else}} {{- if IsAdd $method}} 201: description: Created schema: $ref: "#/definitions/{{LowerTitle $modelName}}" {{- else}} 200: description: OK {{- end}} {{- end}} {{- if or (IsList $method) (IsGet $method) (and (IsEdit $method) $model.ReturnWhenEdit)}} schema: {{- if IsList $method}} type: object properties: {{- if $model.DetailedPagination}} count: type: integer format: int32 {{- end}} warnings: type: array items: type: string items: type: array items: {{- end}} $ref: "#/definitions/{{LowerTitle $modelName}}" {{- end}} default: description: error schema: $ref: "#/definitions/error" {{- end}} {{- range $_, $column := (SortColumns $model.Columns)}} {{- $options := (index $model.Columns $column)}} {{- if and $options.IsStruct $options.IsArray}} /{{LowerTitle $modelName}}/add{{Title $column}}: post: tags: {{- range $_, $tag := $model.Tags}} - {{$tag}} {{- end}} operationId: add{{Title $column}}{{$modelName}} parameters: - name: body in: body schema: type: object properties: id: type: {{if $model.IDIsUUID}}string{{else}}int64{{end}} itemsID: type: array items: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} items: type: array items: $ref: "#/definitions/{{LowerTitle $options.BusinessType}}Add" responses: 200: description: OK default: description: error schema: $ref: "#/definitions/error" /{{LowerTitle $modelName}}/delete{{Title $column}}: post: tags: {{- range $_, $tag := $model.Tags}} - {{$tag}} {{- end}} operationId: delete{{Title $column}}{{$modelName}} parameters: - name: body in: body schema: type: object properties: id: type: {{if $model.IDIsUUID}}string{{else}}int64{{end}} items: type: array items: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} responses: 200: description: OK default: description: error schema: $ref: "#/definitions/error" {{- end}} {{- end}} {{- range $funcName, $func := $.Functions}} /{{LowerTitle $modelName}}/{{$funcName}}: post: operationId: {{LowerTitle $modelName}}{{$funcName}} parameters: - name: body in: body schema: $ref: "#/definitions/{{$funcName}}Params" responses: 200: description: OK schema: $ref: "#/definitions/{{$funcName}}Params" default: description: error schema: $ref: "#/definitions/error" {{- end}} {{- end}} definitions: error: type: object required: - code - message properties: code: description: Either same as HTTP Status Code OR >= 600. type: integer format: int32 message: type: string {{range $modelName, $model := $.Models}} {{LowerTitle $modelName}}: type: object description: "{{.Description}}" {{- range $i, $column := $model.RequiredColumns}} {{- if eq $i 0}} required: {{- end}} - {{$column}} {{- end}} properties: {{- range $_, $name := (SortColumns $model.Columns)}} {{- $options := (index $model.Columns $name)}} {{- if or $options.IsStruct $options.IsCustom}} {{- if $options.IsArray}} {{$name}}: type: array items: $ref: "#/definitions/{{$options.Type}}" {{- else}} {{$name}}: $ref: "#/definitions/{{$options.Type}}" {{- end}} {{- else}} {{- if $options.IsArray}} {{$name}}: type: array items: type: {{if eq $options.Type "uuid"}}string{{else}}{{$options.Type}}{{end}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- else}} {{$name}}: type: {{if eq $options.Type "uuid"}}string{{else}}{{$options.Type}}{{end}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- end}} {{- end}} {{- end}} {{LowerTitle $modelName}}Add: type: object description: "{{LowerTitle $modelName}} model for add and edit methods" {{- range $i, $column := $model.RequiredColumns}} {{- if eq $i 0}} required: {{- end}} - {{$column}} {{- end}} properties: {{- range $_, $name := (SortColumns $model.Columns)}} {{- $options := (index $model.Columns $name)}} {{- if and (ne $name "id") (not (IsStandardColumn $name))}} {{- if $options.IsStruct}} {{- if $options.IsArray}} {{$name}}: type: array items: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} {{- else}} {{$name}}: type: {{if (index $.Models $options.BusinessType).IDIsUUID}}string{{else}}int64{{end}} {{- end}} {{- else}} {{- if $options.IsCustom}} {{- if $options.IsArray}} {{$name}}: type: array items: $ref: "#/definitions/{{$options.Type}}" {{- else}} {{$name}}: $ref: "#/definitions/{{$options.Type}}" {{- end}} {{- else}} {{$name}}: {{- if $options.IsArray}} type: array items: type: {{if eq $options.Type "uuid"}}string{{else}}{{$options.Type}}{{end}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- else}} type: {{if eq $options.Type "uuid"}}string{{else}}{{$options.Type}}{{end}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- end}} {{- end}} {{- end}} {{- end}} {{- end}} {{end}} {{range $customTypeName, $customType := $.CustomTypes}} {{$customTypeName}}: type: object description: "{{$customType.Description}}" {{- range $i, $field := $customType.RequiredFields}} {{- if eq $i 0}} required: {{- end}} - {{$field}} {{- end}} properties: {{- range $fieldName, $options := $customType.Fields}} {{- if $options.IsCustom}} {{- if $options.IsArray}} {{$fieldName}}: type: array items: $ref: "#/definitions/{{$options.Type}}" {{- else}} {{$fieldName}}: $ref: "#/definitions/{{$options.Type}}" {{- end}} {{- else}} {{- if $options.IsArray}} {{$fieldName}}: type: array items: type: {{$options.Type}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- else}} {{$fieldName}}: type: {{$options.Type}} {{- if $options.Format}} format: {{$options.Format}} {{- if (IsTimeFormat $options.Format)}} x-nullable: true {{- end}} {{- end}} {{- if $options.Pattern}} pattern: {{$options.Pattern}} {{- end}} {{- if $options.Length}} maxLength: {{$options.Length}} {{- end}} {{- if $options.Default}} default: {{$options.Default}} {{- end}} {{- if $options.Enum}} enum: {{EnumPrint $options.Enum}} {{- end}} {{- end}} {{- end}} {{- end}} {{end}} {{if .HaveListMethod}} listParams: type: object description: params for list method properties: limit: type: integer minimum: 1 offset: type: integer minimum: 0 filterGroups: type: array items: $ref: "#/definitions/filterGroup" sortBy: type: string orderBy: type: string enum: [ASC, DESC] filterGroup: type: object description: params for grouping filters properties: key: type: string logicFilter: description: "Comparing option: true == 'AND', false == 'OR'" type: boolean filters: type: array items: $ref: "#/definitions/filter" filter: type: object properties: value: type: string operator: description: "enum ==, !=, <, >, <=, >=, in, !in" type: string ignoreCase: type: boolean {{end}} {{- range $funcName, $func := $.Functions}} {{$funcName}}Params: type: object description: params for {{$funcName}} method properties: {{- range $param, $paramType := $func.In}} {{$param}}: type: {{$paramType}} {{- end}} {{- range $param, $paramType := $func.Out}} {{$param}}: type: {{$paramType}} {{- end}} {{- end}}