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

feat: add swagger /docs to localhost:1337 #1268

Merged
merged 1 commit into from
Dec 31, 2023
Merged
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
2 changes: 1 addition & 1 deletion docs/docs/guides/05-using-server/01-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Jan runs on port `1337` by default, but this can be changed in Settings.
Check out the [API Reference](/api-reference) for more information on the API endpoints.

```
curl https://localhost:1337/v1/chat/completions
curl http://localhost:1337/v1/chat/completions

```
14 changes: 7 additions & 7 deletions docs/openapi/jan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license:
name: AGPLv3
url: "https://github.com/janhq/nitro/blob/main/LICENSE"
servers:
- url: "https://localhost:1337/v1/"
- url: "http://localhost:1337/v1/"
tags:
- name: Models
description: List and describe the various models available in the API.
Expand Down Expand Up @@ -100,7 +100,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl https://localhost:1337/v1/models
curl http://localhost:1337/v1/models
post:
operationId: downloadModel
tags:
Expand All @@ -118,7 +118,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl -X POST https://localhost:1337/v1/models
curl -X POST http://localhost:1337/v1/models
"/models/{model_id}":
get:
operationId: retrieveModel
Expand Down Expand Up @@ -149,7 +149,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl https://localhost:1337/v1/models/{model_id}
curl http://localhost:1337/v1/models/{model_id}
delete:
operationId: deleteModel
tags:
Expand Down Expand Up @@ -178,7 +178,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl -X DELETE https://localhost:1337/v1/models/{model_id}
curl -X DELETE http://localhost:1337/v1/models/{model_id}
"/models/{model_id}/start":
put:
operationId: startModel
Expand Down Expand Up @@ -206,7 +206,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl -X PUT https://localhost:1337/v1/models/{model_id}/start
curl -X PUT http://localhost:1337/v1/models/{model_id}/start
"/models/{model_id}/stop":
put:
operationId: stopModel
Expand All @@ -233,7 +233,7 @@ paths:
x-codeSamples:
- lang: cURL
source: |
curl -X PUT https://localhost:1337/v1/models/{model_id}/stop
curl -X PUT http://localhost:1337/v1/models/{model_id}/stop
/threads:
post:
operationId: createThread
Expand Down
17 changes: 17 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ const JAN_API_PORT = Number.parseInt(process.env.JAN_API_PORT || "1337");

const server = fastify();
server.register(require("@fastify/cors"), {});
server.register(require("@fastify/swagger"), {
mode: "static",
specification: {
path: "./../docs/openapi/jan.yaml",
baseDir: "./../docs/openapi",
},
});
server.register(require("@fastify/swagger-ui"), {
routePrefix: "/docs",
baseDir: path.join(__dirname, "../..", "./docs/openapi"),
uiConfig: {
docExpansion: "full",
deepLinking: false,
},
staticCSP: true,
transformSpecificationClone: true,
});
server.register(
(childContext, _, done) => {
childContext.register(require("@fastify/static"), {
Expand Down
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"dependencies": {
"@fastify/cors": "^8.4.2",
"@fastify/static": "^6.12.0",
"@fastify/swagger": "^8.13.0",
"@fastify/swagger-ui": "^2.0.1",
"@janhq/core": "link:./core",
"dotenv": "^16.3.1",
"fastify": "^4.24.3",
Expand Down
Loading