Browse Source

Changing how types are generated from the open api spec a bit.

master
mike12345567 5 years ago
parent
commit
2603024792
  1. 2
      packages/server/package.json
  2. 2
      packages/server/src/api/controllers/public/mapping/applications.ts
  3. 2
      packages/server/src/api/controllers/public/mapping/queries.ts
  4. 2
      packages/server/src/api/controllers/public/mapping/rows.ts
  5. 2
      packages/server/src/api/controllers/public/mapping/tables.ts
  6. 2
      packages/server/src/api/controllers/public/mapping/types.ts
  7. 2
      packages/server/src/api/controllers/public/mapping/users.ts
  8. 14
      packages/server/src/api/routes/public/middleware/mapper.ts
  9. 824
      packages/server/src/definitions/openapi.ts

2
packages/server/package.json

@ -25,7 +25,7 @@
"generate:proxy:preprod": "node scripts/proxy/generateProxyConfig preprod",
"generate:proxy:prod": "node scripts/proxy/generateProxyConfig prod",
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
"specs": "node specs/generate.js && openapi-typescript specs/openapi.yaml --output src/api/controllers/public/types/openapi.ts",
"specs": "node specs/generate.js && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
"lint": "eslint --fix src/",
"lint:fix": "yarn run format && yarn run lint",
"initialise": "node scripts/initialise.js",

2
packages/server/src/api/controllers/public/mapping/applications.ts

@ -1,4 +1,4 @@
import { Application, ApplicationOutput } from "../types/components"
import { Application, ApplicationOutput } from "./types"
function application(body: any): Application {
let app = body?.application ? body.application : body

2
packages/server/src/api/controllers/public/mapping/queries.ts

@ -1,4 +1,4 @@
import { Query, ExecuteQueryOutput } from "../types/components"
import { Query, ExecuteQueryOutput } from "./types"
function query(body: any): Query {
return {

2
packages/server/src/api/controllers/public/mapping/rows.ts

@ -1,4 +1,4 @@
import { Row, RowSearch, RowOutput } from "../types/components"
import { Row, RowSearch, RowOutput } from "./types"
function row(body: any): Row {
delete body._rev

2
packages/server/src/api/controllers/public/mapping/tables.ts

@ -1,4 +1,4 @@
import { Table, TableOutput } from "../types/components"
import { Table, TableOutput } from "./types"
function table(body: any): Table {
return {

2
packages/server/src/api/controllers/public/types/components.ts → packages/server/src/api/controllers/public/mapping/types.ts

@ -1,4 +1,4 @@
import { components } from "./openapi"
import { components } from "../../../../definitions/openapi"
export type Query = components["schemas"]["query"]
export type ExecuteQueryOutput = components["schemas"]["executeQueryOutput"]

2
packages/server/src/api/controllers/public/mapping/users.ts

@ -1,4 +1,4 @@
import { User, UserOutput } from "../types/components"
import { User, UserOutput } from "./types"
function user(body: any): User {
return {

14
packages/server/src/api/routes/public/middleware/mapper.ts

@ -9,12 +9,12 @@ enum Resources {
SEARCH = "search",
}
function isSearch(ctx: any) {
return ctx.url.endsWith(Resources.SEARCH)
function isArrayResponse(ctx: any) {
return ctx.url.endsWith(Resources.SEARCH) || Array.isArray(ctx.body)
}
function processApplications(ctx: any) {
if (isSearch(ctx)) {
if (isArrayResponse(ctx)) {
return mapping.mapApplications(ctx)
} else {
return mapping.mapApplication(ctx)
@ -22,7 +22,7 @@ function processApplications(ctx: any) {
}
function processTables(ctx: any) {
if (isSearch(ctx)) {
if (isArrayResponse(ctx)) {
return mapping.mapTables(ctx)
} else {
return mapping.mapTable(ctx)
@ -30,7 +30,7 @@ function processTables(ctx: any) {
}
function processRows(ctx: any) {
if (isSearch(ctx)) {
if (isArrayResponse(ctx)) {
return mapping.mapRowSearch(ctx)
} else {
return mapping.mapRow(ctx)
@ -38,7 +38,7 @@ function processRows(ctx: any) {
}
function processUsers(ctx: any) {
if (isSearch(ctx)) {
if (isArrayResponse(ctx)) {
return mapping.mapUsers(ctx)
} else {
return mapping.mapUser(ctx)
@ -46,7 +46,7 @@ function processUsers(ctx: any) {
}
function processQueries(ctx: any) {
if (isSearch(ctx)) {
if (isArrayResponse(ctx)) {
return mapping.mapQueries(ctx)
} else {
return mapping.mapQueryExecution(ctx)

824
packages/server/src/api/controllers/public/types/openapi.ts → packages/server/src/definitions/openapi.ts

File diff suppressed because it is too large
Loading…
Cancel
Save