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

Add OpenAPI support #159

Merged
merged 41 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9ba58f9
Make dev and prod routes consistent
lukasturcani Oct 7, 2024
61d6c6a
wip
lukasturcani Oct 7, 2024
65c18fd
Update routes
lukasturcani Oct 7, 2024
9176bf6
Fix tests
lukasturcani Oct 7, 2024
60de197
Fix routes
lukasturcani Oct 7, 2024
10207c1
Run tests!
lukasturcani Oct 7, 2024
8599581
wip
lukasturcani Oct 7, 2024
8066c86
undo
lukasturcani Oct 7, 2024
4b9283d
wip
lukasturcani Oct 7, 2024
7e7e197
wip
lukasturcani Oct 8, 2024
dfe9856
wip
lukasturcani Oct 11, 2024
a5777a0
wip
lukasturcani Oct 11, 2024
0f72d51
Improve devX
lukasturcani Oct 12, 2024
5f67213
Fix tests
lukasturcani Oct 12, 2024
3fe0506
Add values
lukasturcani Oct 12, 2024
89bebe6
Merge branch 'lukas/consistent-routes' into lukas/forward
lukasturcani Oct 12, 2024
d53ddda
Merge branch 'lukas/open-api' into lukas/forward
lukasturcani Oct 12, 2024
5c486d9
wip
lukasturcani Oct 12, 2024
4af3e74
Merge branch 'lukas/forward' into lukas/open-api
lukasturcani Oct 12, 2024
226b1dc
wip
lukasturcani Oct 13, 2024
ad7a52b
Expires in should be a number
lukasturcani Oct 13, 2024
27c4dd5
Merge branch 'lukas/fix-expires-in' into lukas/forward
lukasturcani Oct 13, 2024
34eb6c9
Merge branch 'lukas/forward' into lukas/open-api
lukasturcani Oct 13, 2024
34dd6f1
Wip
lukasturcani Oct 13, 2024
7462e5e
wip
lukasturcani Oct 13, 2024
c5a2bfa
wip
lukasturcani Oct 13, 2024
80b5828
Add description
lukasturcani Oct 14, 2024
b80a1d7
Merge branch 'main' into lukas/open-api
lukasturcani Nov 6, 2024
429eb11
wip
lukasturcani Nov 6, 2024
158c5fe
wip
lukasturcani Nov 6, 2024
91ceec2
wip
lukasturcani Nov 6, 2024
3f13ed4
Merge branch 'main' into lukas/open-api
lukasturcani Nov 7, 2024
4bddca7
wip
lukasturcani Nov 7, 2024
7625b83
cleanup
lukasturcani Nov 7, 2024
9afafe9
Fix test
lukasturcani Nov 7, 2024
5422ff5
wip
lukasturcani Nov 7, 2024
6b0596d
fix test
lukasturcani Nov 7, 2024
1955d6e
fix
lukasturcani Nov 7, 2024
af260da
wip
lukasturcani Nov 7, 2024
2d3ad8a
fix error
lukasturcani Nov 7, 2024
ebb7bff
Merge branch 'main' into lukas/open-api
lukasturcani Nov 28, 2024
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
1 change: 1 addition & 0 deletions envs/dev/backend.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ NODE_ENV='dev'
PORT=8080
MONGODB_URL='mongodb://mongodb:27017/nomad'
HOST='0.0.0.0'
VITE_API_URL=http://localhost:8080
#Frontend host url
FRONT_HOST_URL='http://localhost:3003'

Expand Down
1 change: 1 addition & 0 deletions envs/example/backend.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ NODE_ENV='dev'
PORT=8080
MONGODB_URL='mongodb://mongodb:27017/nomad'
HOST='0.0.0.0'
VITE_API_URL=http://localhost:8080
#Frontend host url
FRONT_HOST_URL='http://localhost:3003'

Expand Down
5 changes: 3 additions & 2 deletions envs/example/frontend.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
VITE_API_URL=http://localhost:8080
VITE_API_URL=http://localhost:8080/api
VITE_SOCKETS_URL=http://localhost:8080
VITE_NMRIUM_URL=http://localhost:3000

#Set true if corresponding NOMAD modules are used
VITE_SUBMIT_ON=true
VITE_BATCH_SUBMIT_ON=true
VITE_DATASTORE_ON=true
VITE_DATASTORE_ON=true
43 changes: 43 additions & 0 deletions nomad-rest-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import bodyParser from 'body-parser'
import helmet from 'helmet'
import moment from 'moment'
import momentDurationFormatSetup from 'moment-duration-format'
import swaggerUi from "swagger-ui-express";

import trackerRoutes from './routes/tracker.js'
import instrumentsRoutes from './routes/admin/insruments.js'
import dashRoutes from './routes/dashboard.js'
import { authLoginOpenApiDoc } from "./controllers/auth.js";
import authRoutes from './routes/auth.js'
import usersRoutes from './routes/admin/users.js'
import groupsRoutes from './routes/admin/groups.js'
Expand All @@ -26,6 +28,12 @@ import datasetsRoutes from './routes/datasets.js'
import statsRoutes from './routes/admin/stats.js'
import collectionRoutes from './routes/collections.js'

import autoExperimentRoutes from "./routes/v2/auto-experiments.js";
import {
autoExperimentsOpenApiDoc,
downloadAutoExperimentOpenApiDoc,
} from "./controllers/v2/auto-experiments.js";

// file deepcode ignore UseCsurfForExpress: <Unclear how to fix>
const app = express()
momentDurationFormatSetup(moment)
Expand Down Expand Up @@ -61,6 +69,41 @@ app.use('/api/datasets', datasetsRoutes)
app.use('/api/stats', statsRoutes)
app.use('/api/collections', collectionRoutes)

const swaggerDocument = {
openapi: "3.0.0",
info: {
title: "NOMAD REST API",
version: "2.0.0",
description: "REST API documentation",
},
servers: [
{
url: process.env.VITE_API_URL,
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
security: [
{ bearerAuth: [] },
],
paths: {
"/api/auth/login": authLoginOpenApiDoc,
"/api/v2/auto-experiments": autoExperimentsOpenApiDoc,
"/api/v2/auto-experiments/download": downloadAutoExperimentOpenApiDoc,
},
}

app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use("/api/v2/auto-experiments", autoExperimentRoutes);


app.use((req, res) => {
res.status(404).send()
})
Expand Down
61 changes: 61 additions & 0 deletions nomad-rest-api/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,67 @@ import transporter from '../utils/emailTransporter.js'

const { verify } = jsonwebtoken

export const authLoginOpenApiDoc = {
post: {
summary: 'Login to NOMAD',
description: 'Returns an access token for the user',
tags: ['Auth'],
requestBody: {
required: true,
content: {
'application/json': {
schema: {
type: 'object',
properties: {
username: {
type: 'string',
},
password: {
type: 'string',
},
},
},
},
},
},
responses: {
200: {
description: 'Login successful',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
username: {
type: 'string',
},
accessLevel: {
type: 'string',
},
manualAccess: {
type: 'boolean',
},
groupName: {
type: 'string',
},
token: {
type: 'string',
},
expiresIn: {
type: 'number',
},
},
},
},
},
},
400: {
description: 'Wrong username or password',
},
},
},
}

export async function postLogin(req, res) {
try {
const user = await User.findOne({ username: req.body.username })
Expand Down
Loading