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

This commit is contained in:
mike12345567 2022-03-01 19:00:28 +00:00
parent fa41548e13
commit 60acca5d95
9 changed files with 426 additions and 426 deletions

View File

@ -25,7 +25,7 @@
"generate:proxy:preprod": "node scripts/proxy/generateProxyConfig preprod", "generate:proxy:preprod": "node scripts/proxy/generateProxyConfig preprod",
"generate:proxy:prod": "node scripts/proxy/generateProxyConfig prod", "generate:proxy:prod": "node scripts/proxy/generateProxyConfig prod",
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write", "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": "eslint --fix src/",
"lint:fix": "yarn run format && yarn run lint", "lint:fix": "yarn run format && yarn run lint",
"initialise": "node scripts/initialise.js", "initialise": "node scripts/initialise.js",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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