Skip to content

Commit cf62e4a

Browse files
committed
endpoints for swagger files
1 parent 4519d58 commit cf62e4a

13 files changed

+18723
-0
lines changed

api/openapi.json

+48
Original file line numberDiff line numberDiff line change
@@ -9829,6 +9829,54 @@
98299829
]
98309830
}
98319831
},
9832+
"/v2/openapi.json": {
9833+
"get": {
9834+
"description": "Get the openapi.json file",
9835+
"operationId": "getOpenapiJson",
9836+
"responses": {
9837+
"200": {
9838+
"content": {
9839+
"application/json": {
9840+
"schema": {
9841+
"additionalProperties": true,
9842+
"type": "object"
9843+
}
9844+
}
9845+
}
9846+
},
9847+
"default": {
9848+
"$ref": "#/components/responses/Error"
9849+
}
9850+
},
9851+
"tags": [
9852+
"Openapi"
9853+
]
9854+
}
9855+
},
9856+
"/v2/openapi.yml": {
9857+
"get": {
9858+
"description": "Get the openapi.yml file",
9859+
"operationId": "getOpenapiYml",
9860+
"responses": {
9861+
"200": {
9862+
"content": {
9863+
"application/x-yaml": {
9864+
"schema": {
9865+
"format": "binary",
9866+
"type": "string"
9867+
}
9868+
}
9869+
}
9870+
},
9871+
"default": {
9872+
"$ref": "#/components/responses/Error"
9873+
}
9874+
},
9875+
"tags": [
9876+
"Openapi"
9877+
]
9878+
}
9879+
},
98329880
"/v2/pubkeys/{public_key}/wallets": {
98339881
"get": {
98349882
"description": "Get wallets by public key",

api/openapi.yml

+30
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,36 @@ tags:
8686
url: https://docs.tonconsole.com/tonapi/rest-api/utilities
8787

8888
paths:
89+
/v2/openapi.json:
90+
get:
91+
description: Get the openapi.json file
92+
operationId: getOpenapiJson
93+
tags:
94+
- Openapi
95+
responses:
96+
'200':
97+
content:
98+
application/json:
99+
schema:
100+
type: object
101+
additionalProperties: true
102+
'default':
103+
$ref: '#/components/responses/Error'
104+
/v2/openapi.yml:
105+
get:
106+
description: Get the openapi.yml file
107+
operationId: getOpenapiYml
108+
tags:
109+
- Openapi
110+
responses:
111+
'200':
112+
content:
113+
application/x-yaml:
114+
schema:
115+
type: string
116+
format: binary
117+
'default':
118+
$ref: '#/components/responses/Error'
89119
/v2/status:
90120
get:
91121
description: Status

gen.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ package opentonapi
22

33
//go:generate go run github.com/ogen-go/ogen/cmd/ogen -clean -config ogen.yaml -package oas -target pkg/oas api/openapi.yml
44
//go:generate go run api/jsonify.go api/openapi.yml api/openapi.json
5+
//go:generate bash -c "cp api/openapi.yml pkg/api/openapi/openapi.yml"
6+
//go:generate bash -c "cp api/openapi.json pkg/api/openapi/openapi.json"

pkg/api/openapi.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package api
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"github.com/go-faster/jx"
7+
"github.com/tonkeeper/opentonapi/pkg/oas"
8+
"io/fs"
9+
"net/http"
10+
)
11+
12+
import "embed"
13+
14+
//go:embed openapi/openapi.yml openapi/openapi.json
15+
var OpenapiFiles embed.FS
16+
17+
func (h *Handler) GetOpenapiJson(ctx context.Context) (oas.GetOpenapiJsonOK, error) {
18+
file, err := fs.ReadFile(OpenapiFiles, "openapi/openapi.json")
19+
if err != nil {
20+
return oas.GetOpenapiJsonOK{}, toError(http.StatusInternalServerError, err)
21+
}
22+
d := jx.DecodeBytes(file)
23+
result := make(map[string]jx.Raw)
24+
if err := d.ObjBytes(func(d *jx.Decoder, key []byte) error {
25+
raw, err := d.Raw()
26+
if err != nil {
27+
return err
28+
}
29+
result[string(key)] = raw
30+
return nil
31+
}); err != nil {
32+
return oas.GetOpenapiJsonOK{}, toError(http.StatusInternalServerError, err)
33+
}
34+
return result, nil
35+
}
36+
37+
func (h *Handler) GetOpenapiYml(ctx context.Context) (oas.GetOpenapiYmlOK, error) {
38+
file, err := fs.ReadFile(OpenapiFiles, "openapi/openapi.yml")
39+
if err != nil {
40+
return oas.GetOpenapiYmlOK{}, toError(http.StatusInternalServerError, err)
41+
}
42+
return oas.GetOpenapiYmlOK{
43+
Data: bytes.NewReader(file),
44+
}, nil
45+
}

0 commit comments

Comments
 (0)