1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 11:24:35 +00:00

Merge pull request #69 from sasjs/route-code-fixes

fix: code api is updated return type
This commit is contained in:
Muhammad Saad
2022-02-20 03:13:19 +04:00
committed by GitHub
4 changed files with 64 additions and 31 deletions

View File

@@ -92,6 +92,29 @@ components:
- clientSecret
type: object
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:
properties:
code:
@@ -368,21 +391,6 @@ components:
- description
type: object
additionalProperties: false
ExecuteReturnJsonResponse:
properties:
status:
type: string
_webout:
type: string
log:
type: string
message:
type: string
required:
- status
- _webout
type: object
additionalProperties: false
ExecuteReturnJsonPayload:
properties:
_program:
@@ -520,7 +528,7 @@ paths:
content:
application/json:
schema:
type: string
$ref: '#/components/schemas/ExecuteReturnJsonResponse'
description: 'Execute SAS code.'
summary: 'Run SAS Code and returns log'
tags:
@@ -1060,6 +1068,9 @@ paths:
application/json:
schema:
$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."
summary: 'Execute Stored Program, return JSON'
tags:

View File

@@ -1,7 +1,8 @@
import express from 'express'
import { Request, Security, Route, Tags, Post, Body } from 'tsoa'
import { ExecuteReturnRaw, ExecutionController } from './internal'
import { ExecuteReturnJson, ExecutionController } from './internal'
import { PreProgramVars } from '../types'
import { ExecuteReturnJsonResponse } from '.'
interface ExecuteSASCodePayload {
/**
@@ -23,25 +24,28 @@ export class CodeController {
public async executeSASCode(
@Request() request: express.Request,
@Body() body: ExecuteSASCodePayload
): Promise<string> {
): Promise<ExecuteReturnJsonResponse> {
return executeSASCode(request, body)
}
}
const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => {
try {
const { result, httpHeaders } =
const { webout, log, httpHeaders } =
(await new ExecutionController().executeProgram(
code,
getPreProgramVariables(req),
{ ...req.query, _debug: 131 },
undefined,
true
)) as ExecuteReturnRaw
)) as ExecuteReturnJson
req.res?.set(httpHeaders)
return result
return {
status: 'success',
_webout: webout,
log,
httpHeaders
}
} catch (err: any) {
throw {
code: 400,

View File

@@ -1,6 +1,16 @@
import express from 'express'
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 {
ExecuteReturnJson,
ExecuteReturnRaw,
@@ -8,7 +18,7 @@ import {
ExecutionVars
} from './internal'
import { PreProgramVars } from '../types'
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
import { getTmpFilesFolderPath, HTTPHeaders, makeFilesNamesMap } from '../utils'
interface ExecuteReturnJsonPayload {
/**
@@ -17,11 +27,12 @@ interface ExecuteReturnJsonPayload {
*/
_program?: string
}
interface ExecuteReturnJsonResponse {
export interface ExecuteReturnJsonResponse {
status: string
_webout: string
log?: string
message?: string
httpHeaders: HTTPHeaders
}
@Security('bearerAuth')
@@ -56,6 +67,14 @@ export class STPController {
* @query _program Location of SAS program
* @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')
public async executeReturnJson(
@Request() request: express.Request,
@@ -119,12 +138,11 @@ const executeReturnJson = async (
true
)) as ExecuteReturnJson
req.res?.set(httpHeaders)
return {
status: 'success',
_webout: webout as string,
log
_webout: webout,
log,
httpHeaders
}
} catch (err: any) {
throw {

View File

@@ -1,7 +1,7 @@
const headerUtils = require('http-headers-validation')
export interface HTTPHeaders {
[key: string]: string | undefined
[key: string]: string
}
export const extractHeaders = (content: string): HTTPHeaders => {