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

Endpoint for swagger #561

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ RUN go mod download
COPY internal internal
COPY cmd cmd
COPY pkg pkg
RUN mkdir -p /tmp/openapi
COPY api/openapi.json /tmp/openapi/openapi.json
COPY api/openapi.yml /tmp/openapi/openapi.yml

RUN apt-get update && \
apt-get install -y libsecp256k1-0 libsodium23
Expand All @@ -20,4 +23,6 @@ RUN mkdir -p /app/lib
RUN wget -O /app/lib/libemulator.so https://github.com/ton-blockchain/ton/releases/download/v2024.08/libemulator-linux-x86_64.so
ENV LD_LIBRARY_PATH=/app/lib/
COPY --from=gobuild /tmp/opentonapi /usr/bin/
COPY --from=gobuild /tmp/openapi /app/openapi
WORKDIR /app
CMD ["/usr/bin/opentonapi"]
45 changes: 45 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9829,6 +9829,51 @@
]
}
},
"/v2/openapi.json": {
"get": {
"description": "Get the openapi.json file",
"operationId": "getOpenapiJson",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
},
"tags": [
"Openapi"
]
}
},
"/v2/openapi.yml": {
"get": {
"description": "Get the openapi.yml file",
"operationId": "getOpenapiYml",
"responses": {
"200": {
"content": {
"application/x-yaml": {
"schema": {
"format": "binary",
"type": "string"
}
}
}
},
"default": {
"$ref": "#/components/responses/Error"
}
},
"tags": [
"Openapi"
]
}
},
"/v2/pubkeys/{public_key}/wallets": {
"get": {
"description": "Get wallets by public key",
Expand Down
28 changes: 28 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,34 @@ tags:
url: https://docs.tonconsole.com/tonapi/rest-api/utilities

paths:
/v2/openapi.json:
get:
description: Get the openapi.json file
operationId: getOpenapiJson
tags:
- Openapi
responses:
'200':
content:
application/json:
schema: { } # Free-form JSON value
'default':
$ref: '#/components/responses/Error'
/v2/openapi.yml:
get:
description: Get the openapi.yml file
operationId: getOpenapiYml
tags:
- Openapi
responses:
'200':
content:
application/x-yaml:
schema:
type: string
format: binary
'default':
$ref: '#/components/responses/Error'
/v2/status:
get:
description: Status
Expand Down
33 changes: 33 additions & 0 deletions pkg/api/openapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package api

import (
"bytes"
"context"
"github.com/go-faster/jx"
"github.com/tonkeeper/opentonapi/pkg/oas"
"net/http"
"os"
)

func (h *Handler) GetOpenapiJson(ctx context.Context) (jx.Raw, error) {
file, err := os.ReadFile("openapi/openapi.json")
if err != nil {
return jx.Raw{}, toError(http.StatusInternalServerError, err)
}
d := jx.DecodeBytes(file)
result, err := d.Raw()
if err != nil {
return jx.Raw{}, toError(http.StatusInternalServerError, err)
}
return result, nil
}

func (h *Handler) GetOpenapiYml(ctx context.Context) (oas.GetOpenapiYmlOK, error) {
file, err := os.ReadFile("openapi/openapi.yml")
if err != nil {
return oas.GetOpenapiYmlOK{}, toError(http.StatusInternalServerError, err)
}
return oas.GetOpenapiYmlOK{
Data: bytes.NewReader(file),
}, nil
}
197 changes: 197 additions & 0 deletions pkg/oas/oas_handlers_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions pkg/oas/oas_response_encoders_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading