mirror of
https://github.com/sasjs/server.git
synced 2026-01-05 05:40:06 +00:00
Merge pull request #69 from sasjs/route-code-fixes
fix: code api is updated return type
This commit is contained in:
@@ -92,6 +92,29 @@ components:
|
|||||||
- clientSecret
|
- clientSecret
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
|
HTTPHeaders:
|
||||||
|
properties: {}
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
type: string
|
||||||
|
ExecuteReturnJsonResponse:
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
_webout:
|
||||||
|
type: string
|
||||||
|
log:
|
||||||
|
type: string
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
httpHeaders:
|
||||||
|
$ref: '#/components/schemas/HTTPHeaders'
|
||||||
|
required:
|
||||||
|
- status
|
||||||
|
- _webout
|
||||||
|
- httpHeaders
|
||||||
|
type: object
|
||||||
|
additionalProperties: false
|
||||||
ExecuteSASCodePayload:
|
ExecuteSASCodePayload:
|
||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
@@ -368,21 +391,6 @@ components:
|
|||||||
- description
|
- description
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
ExecuteReturnJsonResponse:
|
|
||||||
properties:
|
|
||||||
status:
|
|
||||||
type: string
|
|
||||||
_webout:
|
|
||||||
type: string
|
|
||||||
log:
|
|
||||||
type: string
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- status
|
|
||||||
- _webout
|
|
||||||
type: object
|
|
||||||
additionalProperties: false
|
|
||||||
ExecuteReturnJsonPayload:
|
ExecuteReturnJsonPayload:
|
||||||
properties:
|
properties:
|
||||||
_program:
|
_program:
|
||||||
@@ -520,7 +528,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: string
|
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
||||||
description: 'Execute SAS code.'
|
description: 'Execute SAS code.'
|
||||||
summary: 'Run SAS Code and returns log'
|
summary: 'Run SAS Code and returns log'
|
||||||
tags:
|
tags:
|
||||||
@@ -1060,6 +1068,9 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
|
||||||
|
examples:
|
||||||
|
'Example 1':
|
||||||
|
value: {status: success, _webout: 'webout content', httpHeaders: {Content-type: application/zip, Cache-Control: 'public, max-age=1000'}}
|
||||||
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
description: "Trigger a SAS program using it's location in the _program parameter.\nEnable debugging using the _debug parameter.\nAdditional URL parameters are turned into SAS macro variables.\nAny files provided are placed into the session and\ncorresponding _WEBIN_XXX variables are created."
|
||||||
summary: 'Execute Stored Program, return JSON'
|
summary: 'Execute Stored Program, return JSON'
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
|
import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
|
||||||
import { ExecuteReturnRaw, ExecutionController } from './internal'
|
import { ExecuteReturnJson, ExecutionController } from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
|
import { ExecuteReturnJsonResponse } from '.'
|
||||||
|
|
||||||
interface ExecuteSASCodePayload {
|
interface ExecuteSASCodePayload {
|
||||||
/**
|
/**
|
||||||
@@ -23,25 +24,28 @@ export class CodeController {
|
|||||||
public async executeSASCode(
|
public async executeSASCode(
|
||||||
@Request() request: express.Request,
|
@Request() request: express.Request,
|
||||||
@Body() body: ExecuteSASCodePayload
|
@Body() body: ExecuteSASCodePayload
|
||||||
): Promise<string> {
|
): Promise<ExecuteReturnJsonResponse> {
|
||||||
return executeSASCode(request, body)
|
return executeSASCode(request, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => {
|
const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => {
|
||||||
try {
|
try {
|
||||||
const { result, httpHeaders } =
|
const { webout, log, httpHeaders } =
|
||||||
(await new ExecutionController().executeProgram(
|
(await new ExecutionController().executeProgram(
|
||||||
code,
|
code,
|
||||||
getPreProgramVariables(req),
|
getPreProgramVariables(req),
|
||||||
{ ...req.query, _debug: 131 },
|
{ ...req.query, _debug: 131 },
|
||||||
undefined,
|
undefined,
|
||||||
true
|
true
|
||||||
)) as ExecuteReturnRaw
|
)) as ExecuteReturnJson
|
||||||
|
|
||||||
req.res?.set(httpHeaders)
|
return {
|
||||||
|
status: 'success',
|
||||||
return result
|
_webout: webout,
|
||||||
|
log,
|
||||||
|
httpHeaders
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
throw {
|
throw {
|
||||||
code: 400,
|
code: 400,
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { Request, Security, Route, Tags, Post, Body, Get, Query } from 'tsoa'
|
import {
|
||||||
|
Request,
|
||||||
|
Security,
|
||||||
|
Route,
|
||||||
|
Tags,
|
||||||
|
Post,
|
||||||
|
Body,
|
||||||
|
Get,
|
||||||
|
Query,
|
||||||
|
Example
|
||||||
|
} from 'tsoa'
|
||||||
import {
|
import {
|
||||||
ExecuteReturnJson,
|
ExecuteReturnJson,
|
||||||
ExecuteReturnRaw,
|
ExecuteReturnRaw,
|
||||||
@@ -8,7 +18,7 @@ import {
|
|||||||
ExecutionVars
|
ExecutionVars
|
||||||
} from './internal'
|
} from './internal'
|
||||||
import { PreProgramVars } from '../types'
|
import { PreProgramVars } from '../types'
|
||||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
import { getTmpFilesFolderPath, HTTPHeaders, makeFilesNamesMap } from '../utils'
|
||||||
|
|
||||||
interface ExecuteReturnJsonPayload {
|
interface ExecuteReturnJsonPayload {
|
||||||
/**
|
/**
|
||||||
@@ -17,11 +27,12 @@ interface ExecuteReturnJsonPayload {
|
|||||||
*/
|
*/
|
||||||
_program?: string
|
_program?: string
|
||||||
}
|
}
|
||||||
interface ExecuteReturnJsonResponse {
|
export interface ExecuteReturnJsonResponse {
|
||||||
status: string
|
status: string
|
||||||
_webout: string
|
_webout: string
|
||||||
log?: string
|
log?: string
|
||||||
message?: string
|
message?: string
|
||||||
|
httpHeaders: HTTPHeaders
|
||||||
}
|
}
|
||||||
|
|
||||||
@Security('bearerAuth')
|
@Security('bearerAuth')
|
||||||
@@ -56,6 +67,14 @@ export class STPController {
|
|||||||
* @query _program Location of SAS program
|
* @query _program Location of SAS program
|
||||||
* @example _program "/Public/somefolder/some.file"
|
* @example _program "/Public/somefolder/some.file"
|
||||||
*/
|
*/
|
||||||
|
@Example<ExecuteReturnJsonResponse>({
|
||||||
|
status: 'success',
|
||||||
|
_webout: 'webout content',
|
||||||
|
httpHeaders: {
|
||||||
|
'Content-type': 'application/zip',
|
||||||
|
'Cache-Control': 'public, max-age=1000'
|
||||||
|
}
|
||||||
|
})
|
||||||
@Post('/execute')
|
@Post('/execute')
|
||||||
public async executeReturnJson(
|
public async executeReturnJson(
|
||||||
@Request() request: express.Request,
|
@Request() request: express.Request,
|
||||||
@@ -119,12 +138,11 @@ const executeReturnJson = async (
|
|||||||
true
|
true
|
||||||
)) as ExecuteReturnJson
|
)) as ExecuteReturnJson
|
||||||
|
|
||||||
req.res?.set(httpHeaders)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'success',
|
status: 'success',
|
||||||
_webout: webout as string,
|
_webout: webout,
|
||||||
log
|
log,
|
||||||
|
httpHeaders
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
throw {
|
throw {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const headerUtils = require('http-headers-validation')
|
const headerUtils = require('http-headers-validation')
|
||||||
|
|
||||||
export interface HTTPHeaders {
|
export interface HTTPHeaders {
|
||||||
[key: string]: string | undefined
|
[key: string]: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const extractHeaders = (content: string): HTTPHeaders => {
|
export const extractHeaders = (content: string): HTTPHeaders => {
|
||||||
|
|||||||
Reference in New Issue
Block a user