Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 6.0 #18

Merged
merged 29 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
77718c7
API spec syntax fixes.
andrew-platonov Nov 29, 2022
c1aae35
[no ci] Bug in the api spec fixed.
andrew-platonov Dec 5, 2022
085073c
RC 6.0
add2 May 20, 2023
642387b
RC 6.0
add2 May 20, 2023
c5e0a17
dependencies updated
add2 May 20, 2023
289ea61
dependencies updated
add2 May 20, 2023
a142684
[no ci] Large REST API example bug fixed.
andrew-platonov Jul 14, 2023
f79ebb7
Merge branch 'rc/6.0' into dev
add2 Jan 12, 2024
c09135e
mock OpenAPI converter
add2 Jan 12, 2024
f918000
mock OpenAPI converter
add2 Jan 15, 2024
b98439a
mock OpenAPI converter
add2 Jan 15, 2024
d1c218c
dependencies updated
add2 Jan 29, 2024
d4d7228
OpenAPI converter
add2 Apr 1, 2024
bc058d8
changed api-core dep to openapi-converter-tests
Emptyfruit Apr 2, 2024
f0d4dd3
fix yaml
add2 Apr 8, 2024
a5ec3de
upgrade api, schema deps
Emptyfruit Apr 10, 2024
522eac3
fix format output
chepil Apr 10, 2024
e010590
Merge pull request #14 from jsightapi/SERV-385_fix_json_formatter
andrew-platonov Apr 15, 2024
b21eb17
update api-core
Emptyfruit Apr 16, 2024
a8fa709
update api-core
Emptyfruit Apr 16, 2024
7692471
SERV-391 jsigth to openapi yaml, fix last line break for yaml
chepil Apr 19, 2024
fc9137e
Merge pull request #15 from jsightapi/SERV-391
add2 Apr 22, 2024
abb4a30
dep updates
Emptyfruit Apr 23, 2024
b747ea8
Merge pull request #16 from jsightapi/dev
andrew-platonov Apr 25, 2024
331b78b
update api core (serv 195, 279, 395)
Emptyfruit May 2, 2024
b67615e
Readme updated
andrew-platonov May 9, 2024
4c8f716
Readme fix.
andrew-platonov May 9, 2024
b8c841a
dependencies updated
add2 May 9, 2024
5bd9f6c
Merge pull request #17 from jsightapi/dev
andrew-platonov May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.env
/jsight-server
/local
.tool-versions
83 changes: 53 additions & 30 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
run:
go: '1.19'
timeout: 5m
issues-exit-code: 1
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: true

output:
format: tab
print-issued-lines: true
print-linter-name: true
# Print all issue on single line.
# We should set to false 'cause if one single line has issues from different
# linters we will see only one of them.
uniq-by-line: false
sort-results: true

linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
rules:
main:
list-mode: lax # allows unless explicitly denied
deny:
- pkg: "github.com/sirupsen/logrus"
desc: logging is allowed only by logutils.Log, logrus is allowed to use only in logutils package
dupl:
threshold: 100
threshold: 150
funlen:
lines: 100
statements: 50
Expand All @@ -27,11 +45,15 @@ linters-settings:
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
settings:
hugeParam:
sizeThreshold: 210
rangeValCopy:
sizeThreshold: 220
gocyclo:
min-complexity: 15
min-complexity: 30
goimports:
local-prefixes: github.com/golangci/golangci-lint
local-prefixes: github.com/jsightapi/jsight-api-core
gomnd:
# don't include the "operation" and "assign"
checks:
Expand All @@ -46,7 +68,6 @@ linters-settings:
- '3'
ignored-functions:
- strings.SplitN
- strconv.FormatUint

govet:
check-shadowing: true
Expand All @@ -58,11 +79,10 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
line-length: 120
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
Expand All @@ -83,7 +103,7 @@ linters:
- gocyclo
- gofmt
- goimports
- gomnd
# - gomnd
- goprintffuncname
- gosec
- gosimple
Expand Down Expand Up @@ -123,20 +143,23 @@ issues:
exclude-rules:
- path: _test\.go
linters:
- gomnd
- dupl
- errcheck
- goconst
- gocritic
- gocyclo
- gosec
- ifshort
- lll
- unparam
- funlen

- path: pkg/golinters/errcheck.go
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
# We already have a bunch of code with that name convention, so it's okay for now
# to skip this check.
- source: "(Json|Uuid|Uri|jApi)"
linters:
- stylecheck

run:
timeout: 5m
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.
skip-dirs:
- test/testdata_etc
- internal/cache
- internal/renameio
- internal/robustio
- text: "ST1005: error strings should not be capitalized"
linters:
- stylecheck
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: fmt lint test
.PHONY: dev
dev: fmt lint test

.PHONY: fmt
fmt:
Expand All @@ -16,3 +16,7 @@ test:
.PHONY: build
build:
go build -o jsight-server .

.PHONY: run
run:
go run .
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ API](#scroll--jsight-api-language).

Supported standards: [HTTP REST](#scroll--jsight-api-language), [JSON-RPC 2.0](#json-rpc-20-new-feature).

Currently, the **JSight Server API** allows you to perform only one task:
The **JSight Server API** allows you to perform the following tasks:

1. Parsing code in the JSight API language, which results in a JSON structure containing all
information about this API in the *JDoc Exchange Format*.
1. Parsing code in the JSight API language, checking JSight API syntax.
2. Generating a JSON structure containing all information about this API in the *JDoc Exchange
Format* (required for [JSight Online Editor
frontend](https://github.com/jsightapi/online-editor-frontend)).
3. Converting JSight API to OpenAPI (YAML or JSON).

The following features are also planned in the near future:

1. Support for other types of API: gRPC, Kafka, RabbitMQ, WebSocket.
2. Converting from JSight API to OpenAPI.
3. Converting from OpenAPI to JSight API.
4. API documentation generation in MarkDown format.
5. API documentation generation in PDF format.
6. Generation of API server code stubs for different programming languages ​​(Java, PHP, Go,
2. Converting from OpenAPI to JSight API.
3. API documentation generation in MarkDown format.
4. API documentation generation in PDF format.
5. Generation of API server code stubs for different programming languages ​​(Java, PHP, Go,
Node.js, Python, C++ etc.).
7. Generation of API clients for different programming languages ​​(JavaScript, Java, PHP, Go,
6. Generation of API clients for different programming languages ​​(JavaScript, Java, PHP, Go,
Python, C++ etc.).
8. And many other features.
7. And many other features.

> :fire: If you have any ideas or suggestions, please share with us:
>
Expand Down Expand Up @@ -1426,7 +1428,7 @@ TYPE @pet // A pet.
TYPE @cat // A cat.
{ // {allOf: "@pet"}
"status": "relaxing",
"bestFriend": @cat,
"bestFriend": @cat, // {optional: true}
"topFriends": { // {additionalProperties: true}
@petName: @cat | @pig
},
Expand Down Expand Up @@ -1767,8 +1769,8 @@ https://github.com/jsightapi/jsight-server/releases.

JSight Server depends on the following components:

- [JSight Schema Go Library](https://github.com/jsightapi/jsight-schema-go-library),
- [JSight API Go Library](https://github.com/jsightapi/jsight-api-go-library).
- [JSight Schema Go Library](https://github.com/jsightapi/jsight-schema-core),
- [JSight API Go Library](https://github.com/jsightapi/jsight-api-core).

These dependencies are described in the file [go.mod](./go.mod).

Expand Down Expand Up @@ -1804,6 +1806,8 @@ document.
<a href="https://github.com/constantine-malyshev"><img src="https://avatars.githubusercontent.com/u/101567029?v=4" width="100" height="100" alt=""/></a>
<a href="https://github.com/dshemin"><img src="https://avatars.githubusercontent.com/u/11780307?v=4" width="100" height="100" alt=""/></a>
<a href="https://github.com/bakhtinphil"><img src="https://avatars.githubusercontent.com/u/104030166?v=4" width="100" height="100" alt=""/></a>
<a href="https://github.com/tobiashochguertel"><img src="https://avatars.githubusercontent.com/u/3332669?v=4" width="100" height="100" alt=""/></a>
<a href="https://github.com/chepil"><img src="https://avatars.githubusercontent.com/u/1425370?v=4" width="100" height="100" alt=""/></a>

<div>
&nbsp;
Expand Down Expand Up @@ -1891,7 +1895,12 @@ We sincerely thank all those without whom this project would not have been possi

- [Alchemist Accelerator](https://www.alchemistaccelerator.com/),
- [Lucas Jones](https://github.com/lucasjones) for his
[reggen](https://github.com/lucasjones/reggen) library.
[reggen](https://github.com/lucasjones/reggen) library,
- [itchyny](https://github.com/itchyny) for his
[json2yaml](https://github.com/itchyny/json2yaml) library,
- [Stretchr](https://github.com/stretchr) company for
[testify](https://github.com/stretchr/testify) library,


<div align="center">

Expand Down
116 changes: 116 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package main

import (
"io"
"log"
"net/http"

"github.com/jsightapi/jsight-schema-core/fs"

"github.com/jsightapi/jsight-api-core/kit"
)

func convertJSight(w http.ResponseWriter, r *http.Request) {
to := r.FormValue("to")
format := r.FormValue("format")
log.Printf("%s %s %s %s", r.Method, r.URL.Path, to, format)

if getBoolEnv("JSIGHT_SERVER_CORS") {
cors(w)
}

wr := httpResponseWriter{writer: w}

switch r.Method {
case http.MethodOptions:

case http.MethodPost:
convertJSightPOST(wr, r)
return

default:
wr.errorStr("HTTP POST request required")
return
}
}

func convertJSightPOST(wr httpResponseWriter, r *http.Request) {
to := r.FormValue("to")
format := r.FormValue("format")

body, err := io.ReadAll(r.Body)
if err != nil {
wr.error(err)
return
}

jAPI, jErr := kit.NewJApiFromFile(fs.NewFile("root", body))

if getBoolEnv("JSIGHT_SERVER_STATISTICS") {
clientID := r.Header.Get("X-Browser-UUID")
clientIP := getIP(r)
sendDatagram(clientID, clientIP, len(body), jAPI, jErr)
}

if jErr != nil {
wr.error(jErr)
return
}

switch to {
case "jdoc-2.0":
switch format {
case "json", "":
writeJDocJSON(wr, jAPI)
return
default:
wr.errorStr("not supported format")
return
}
case "openapi-3.0.3":
switch format {
case "json", "":
writeOpenapiJSON(wr, jAPI)
return
case "yaml":
writeOpenapiYAML(wr, jAPI)
return
default:
wr.errorStr("not supported format")
return
}
default:
wr.errorStr(`you must specify the "to" parameter`)
return
}
}

func writeJDocJSON(wr httpResponseWriter, jAPI kit.JApi) {
resp, err := jdocJSON(jAPI)
if err != nil {
wr.error(err)
return
}

wr.jdocJSON(resp)
}

func writeOpenapiJSON(wr httpResponseWriter, jAPI kit.JApi) {
resp, err := openapiJSON(jAPI)
if err != nil {
wr.error(err)
return
}

wr.json(resp)
}

func writeOpenapiYAML(wr httpResponseWriter, jAPI kit.JApi) {
resp, err := openapiYAML(jAPI)
if err != nil {
wr.error(err)
return
}

wr.yaml(resp)
}
2 changes: 1 addition & 1 deletion cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_cors(t *testing.T) {
assert.Len(t, r.Header(), 3)
assert.Equal(t, "*", r.Header().Get("Access-Control-Allow-Origin"))
assert.Equal(t, "POST, GET, OPTIONS, PUT, DELETE", r.Header().Get("Access-Control-Allow-Methods"))
assert.Equal(t, "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Browser-UUID", r.Header().Get("Access-Control-Allow-Headers")) //nolint:lll
assert.Equal(t, "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Browser-UUID", r.Header().Get("Access-Control-Allow-Headers"))
})

t.Run("negative", func(t *testing.T) {
Expand Down
30 changes: 30 additions & 0 deletions datagram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"log"
"strconv"

"github.com/jsightapi/datagram"

"github.com/jsightapi/jsight-api-core/jerr"
"github.com/jsightapi/jsight-api-core/kit"
)

func sendDatagram(clientID, clientIP string, projectSize int, j kit.JApi, je *jerr.JApiError) {
d := datagram.New()
d.Append("cid", clientID)
d.Append("cip", clientIP)
d.Append("at", "1") // Application Type
d.AppendTruncatable("pt", j.Title()) // Project title
d.Append("ps", strconv.Itoa(projectSize)) // Project size
if je != nil {
d.AppendTruncatable("pem", je.Error()) // Project error message
d.Append("pel", strconv.FormatUint(uint64(je.Line), 10)) // Project error line
d.Append("pei", strconv.FormatUint(uint64(je.Index), 10)) // Project error index
}

err := sendToStatisticServer(d.Pack())
if err != nil {
log.Print("... " + err.Error())
}
}
Loading