mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
refactor: split api into api, api-cli & api-plugin
This commit is contained in:
@@ -65,7 +65,7 @@ commander
|
||||
|
||||
// change url path parameters to openapi notation
|
||||
for (const routeWithMetaInformation of routes) {
|
||||
routeWithMetaInformation.route.urlPath = routeWithMetaInformation.route.urlPath.replace(
|
||||
routeWithMetaInformation.route.urlPath = routeWithMetaInformation.route.urlPath.replaceAll(
|
||||
/:\w+/g,
|
||||
(match: string) => `{${match.replace(':', '')}}`,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@ import {existsSync} from 'fs';
|
||||
|
||||
/**
|
||||
* Get path that contains a tsconfig.json
|
||||
*
|
||||
* @param startPath Path from where to start searching "upwards"
|
||||
*/
|
||||
export function getTsconfigPath(startPath: string): string {
|
||||
|
||||
@@ -77,7 +77,6 @@ export async function gatherRouteInformation(path: string): Promise<RouteWithMet
|
||||
|
||||
/**
|
||||
* Generate documentation snippet for one route
|
||||
*
|
||||
* @param routeWithInfo A route instance with its meta information
|
||||
* @param outDirectorySchemasPath Path to directory that will contain relevant schemas for the route
|
||||
* @param schemasToCopy Schemas identified as relevant for this route
|
||||
@@ -136,7 +135,8 @@ export function generateOpenAPIForRoute(
|
||||
for (const error of route.errors) {
|
||||
schemasToCopy.push(error.name);
|
||||
openapiPath[route.method.toLowerCase() as OpenAPIV3.HttpMethods]!.responses![error.statusCode] = {
|
||||
description: error.message ?? capitalize(error.name.replace(/([A-Z][a-z])/g, ' $1').replace('SC ', '')),
|
||||
description:
|
||||
error.message ?? capitalize(error.name.replaceAll(/([A-Z][a-z])/g, ' $1').replace('SC ', '')),
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
|
||||
@@ -42,7 +42,6 @@ export class Converter {
|
||||
|
||||
/**
|
||||
* Create a new converter
|
||||
*
|
||||
* @param projectPath Path to the project
|
||||
* @param sourcePath Path to optionally point to a different directory of / or single source file
|
||||
*/
|
||||
@@ -69,7 +68,6 @@ export class Converter {
|
||||
|
||||
/**
|
||||
* Get schema for specific StAppsCore type
|
||||
*
|
||||
* @param type Type to get the schema for
|
||||
* @param version Version to set for the schema
|
||||
* @returns Generated schema
|
||||
|
||||
@@ -30,7 +30,6 @@ import {writeFile} from 'fs/promises';
|
||||
* Converts the lightweight class/enum definitions according to the configuration,
|
||||
* to valid PlantUML Code, which will then be encoded, converted by the plantuml server
|
||||
* and saved as a .svg file in directory, in which this method was called
|
||||
*
|
||||
* @param definitions all type definitions of the project
|
||||
* @param config contains information on how the PlantUML should be generated
|
||||
* @param plantUmlBaseURL Hostname of the PlantUML-Server
|
||||
@@ -71,7 +70,6 @@ export async function createDiagram(
|
||||
/**
|
||||
* This will encode the plantuml code and post the code to the plantuml server
|
||||
* The server will then parse the code and create a corresponding diagram
|
||||
*
|
||||
* @param modelPlantUMLCode raw PlantUML code
|
||||
* @param plantUmlBaseURL PlantUML server address that shall be used
|
||||
* @param outputFile filename of the output file without file extension
|
||||
@@ -100,7 +98,7 @@ export async function createDiagramFromString(
|
||||
throw error;
|
||||
}
|
||||
// attach file extension
|
||||
const fileName = `${outputFile.replace(/[^\w-]/g, '_')}.svg`;
|
||||
const fileName = `${outputFile.replaceAll(/[^\w-]/g, '_')}.svg`;
|
||||
|
||||
await writeFile(fileName, response.body);
|
||||
Logger.log(`Writen data to file: ${fileName}`);
|
||||
@@ -110,7 +108,6 @@ export async function createDiagramFromString(
|
||||
|
||||
/**
|
||||
* Recursively iterates over all types, to find implemented generic types and parents
|
||||
*
|
||||
* @param definitions all type definitions of the project
|
||||
* @param abstractionNames currently known string values of inherited classes
|
||||
*/
|
||||
@@ -143,7 +140,6 @@ export async function createDiagramFromString(
|
||||
* Collects all reference information of this type.
|
||||
*
|
||||
* Reference information is everything that is indirectly referencing a type or class by name.
|
||||
*
|
||||
* @param type Type with references to other types
|
||||
*/
|
||||
function getReferenceTypes(type: LightweightType): string[] {
|
||||
@@ -173,7 +169,6 @@ function getReferenceTypes(type: LightweightType): string[] {
|
||||
|
||||
/**
|
||||
* Creates Plant UML code according to the config for the provided class
|
||||
*
|
||||
* @param config Configuration for how the UML should be tweaked
|
||||
* @param readerClass Class or interface representation
|
||||
*/
|
||||
@@ -235,7 +230,6 @@ function createPlantUMLCodeForClass(config: UMLConfig, readerClass: LightweightC
|
||||
|
||||
/**
|
||||
* Creates PlantUML code according to the config for the provided enum/-like definition
|
||||
*
|
||||
* @param config Configuration for how the UML should be tweaked
|
||||
* @param readerEnum Enum/-like representation
|
||||
*/
|
||||
|
||||
@@ -33,5 +33,5 @@ export function expandPathToFilesSync(sourcePath: string, accept: (fileName: str
|
||||
* Take a Windows path and make a Unix path out of it
|
||||
*/
|
||||
export function toUnixPath(pathString: string): string {
|
||||
return pathString.replace(/\\/g, '/');
|
||||
return pathString.replaceAll('\\', '/');
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ export class Validator {
|
||||
|
||||
/**
|
||||
* A wrapper function for Ajv that transforms the error into the compatible old error
|
||||
*
|
||||
* @param schema the schema that will be validated against
|
||||
* @param instance the instance that will be validated
|
||||
*/
|
||||
@@ -57,7 +56,6 @@ export class Validator {
|
||||
|
||||
/**
|
||||
* Feed the schema files to the validator
|
||||
*
|
||||
* @param schemaDirectory Path to directory that contains schema files
|
||||
*/
|
||||
public async addSchemas(schemaDirectory: string): Promise<string[]> {
|
||||
@@ -87,7 +85,6 @@ export class Validator {
|
||||
|
||||
/**
|
||||
* Validates anything against a given schema name or infers schema name from object
|
||||
*
|
||||
* @param instance Instance to validate
|
||||
* @param schema Name of schema to validate instance against or the schema itself
|
||||
*/
|
||||
@@ -125,7 +122,6 @@ export class Validator {
|
||||
* Creates a ValidationResult from ajv
|
||||
*
|
||||
* Implemented for compatibility purposes
|
||||
*
|
||||
* @param result the result, now a ValidationResult
|
||||
* @param schema the schema that has been validated against
|
||||
* @param instance the data that has been validated
|
||||
@@ -166,7 +162,6 @@ function fromAjvResult(
|
||||
|
||||
/**
|
||||
* Validate all test files in the given resources directory against schema files in the given (schema) directory
|
||||
*
|
||||
* @param schemaDirectory The directory where the JSON schema files are
|
||||
* @param resourcesDirectory The directory where the test files are
|
||||
*/
|
||||
@@ -261,7 +256,6 @@ export async function validateFiles(
|
||||
|
||||
/**
|
||||
* Write a report for errors that occurred in validation
|
||||
*
|
||||
* @param reportPath Path to write report to
|
||||
* @param errors Errors that occurred in validation
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user