mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-04-23 06:39:13 +00:00
feat: enable stricter typescript compiler options
This commit is contained in:
@@ -60,11 +60,11 @@ commander
|
||||
|
||||
// get information about routes
|
||||
const routes = await gatherRouteInformation(sourcePath);
|
||||
routes.sort((a, b) => a.route.urlPath.localeCompare(b.route.urlPath));
|
||||
routes.sort((a, b) => a.route['urlPath'].localeCompare(b.route['urlPath']));
|
||||
|
||||
// change url path parameters to openapi notation
|
||||
for (const routeWithMetaInformation of routes) {
|
||||
routeWithMetaInformation.route.urlPath = routeWithMetaInformation.route.urlPath.replaceAll(
|
||||
routeWithMetaInformation.route['urlPath'] = routeWithMetaInformation.route['urlPath'].replaceAll(
|
||||
/:\w+/g,
|
||||
(match: string) => `{${match.replace(':', '')}}`,
|
||||
);
|
||||
@@ -72,7 +72,7 @@ commander
|
||||
|
||||
// keep openapi tags for routes that actually share url fragments
|
||||
let tagsToKeep = routes.map(routeWithMetaInformation =>
|
||||
capitalize(routeWithMetaInformation.route.urlPath.split('/')[1]),
|
||||
capitalize(routeWithMetaInformation.route['urlPath'].split('/')[1]),
|
||||
);
|
||||
tagsToKeep = tagsToKeep.filter(
|
||||
(element, i, array) => array.indexOf(element) === i && array.lastIndexOf(element) !== i,
|
||||
@@ -83,9 +83,9 @@ commander
|
||||
|
||||
// generate documentation for all routes
|
||||
for (const routeWithMetaInformation of routes) {
|
||||
routeWithMetaInformation.tags = [capitalize(routeWithMetaInformation.route.urlPath.split('/')[1])];
|
||||
routeWithMetaInformation.tags = [capitalize(routeWithMetaInformation.route['urlPath'].split('/')[1])];
|
||||
|
||||
output.paths[routeWithMetaInformation.route.urlPath] = generateOpenAPIForRoute(
|
||||
output.paths[routeWithMetaInformation.route['urlPath']] = generateOpenAPIForRoute(
|
||||
routeWithMetaInformation,
|
||||
path.relative(relativeOutDirectoryPath, outDirectorySchemasPath),
|
||||
tagsToKeep,
|
||||
@@ -165,7 +165,7 @@ commander
|
||||
continue;
|
||||
}
|
||||
|
||||
unexpected = unexpected || errorsPerFile[file].some(error => !error.expected);
|
||||
unexpected = unexpected || errorsPerFile[file]?.some(error => !error.expected) || false;
|
||||
}
|
||||
|
||||
if (relativeReportPath !== undefined) {
|
||||
|
||||
@@ -48,7 +48,7 @@ export async function gatherRouteInformation(path: string): Promise<RouteWithMet
|
||||
// instantiate all errors
|
||||
instantiatedRoute.errors = await Promise.all(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
instantiatedRoute.errorNames.map(async (error: any) =>
|
||||
instantiatedRoute['errorNames'].map(async (error: any) =>
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
Object.assign((await project.instantiateDefinitionByName(error.name)) as object, {
|
||||
name: error.name,
|
||||
@@ -57,10 +57,10 @@ export async function gatherRouteInformation(path: string): Promise<RouteWithMet
|
||||
);
|
||||
instantiatedRoute.responseBodyDescription =
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
||||
project.definitions[instantiatedRoute.responseBodyName]?.comment?.shortSummary!;
|
||||
project.definitions[instantiatedRoute['responseBodyName']]?.comment?.shortSummary!;
|
||||
instantiatedRoute.requestBodyDescription =
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
||||
project.definitions[instantiatedRoute.requestBodyName]?.comment?.shortSummary!;
|
||||
project.definitions[instantiatedRoute['requestBodyName']]?.comment?.shortSummary!;
|
||||
|
||||
return {
|
||||
description: {
|
||||
@@ -89,7 +89,7 @@ export function generateOpenAPIForRoute(
|
||||
const route = routeWithInfo.route;
|
||||
const openapiPath: OpenAPIV3.PathItemObject = {};
|
||||
|
||||
openapiPath[route.method.toLowerCase() as OpenAPIV3.HttpMethods] = {
|
||||
openapiPath[route['method'].toLowerCase() as OpenAPIV3.HttpMethods] = {
|
||||
summary: capitalize(routeWithInfo.description.shortText?.replace(/(Route to |Route for )/gim, '')),
|
||||
description: routeWithInfo.description.text,
|
||||
requestBody: {
|
||||
@@ -97,7 +97,7 @@ export function generateOpenAPIForRoute(
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
$ref: path.join(outDirectorySchemasPath, `${route.requestBodyName}.json`),
|
||||
$ref: path.join(outDirectorySchemasPath, `${route['requestBodyName']}.json`),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -117,19 +117,21 @@ export function generateOpenAPIForRoute(
|
||||
tags: routeWithInfo.tags?.filter(value => tagsToKeep.includes(value)),
|
||||
};
|
||||
|
||||
openapiPath[route.method.toLowerCase() as OpenAPIV3.HttpMethods]!.responses![route.statusCodeSuccess] = {
|
||||
openapiPath[route['method'].toLowerCase() as OpenAPIV3.HttpMethods]!.responses![
|
||||
route['statusCodeSuccess']
|
||||
] = {
|
||||
description: route.responseBodyDescription,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
$ref: path.join(outDirectorySchemasPath, `${route.responseBodyName}.json`),
|
||||
$ref: path.join(outDirectorySchemasPath, `${route['responseBodyName']}.json`),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
for (const error of route.errors) {
|
||||
openapiPath[route.method.toLowerCase() as OpenAPIV3.HttpMethods]!.responses![error.statusCode] = {
|
||||
openapiPath[route['method'].toLowerCase() as OpenAPIV3.HttpMethods]!.responses![error.statusCode] = {
|
||||
description:
|
||||
error.message ?? capitalize(error.name.replaceAll(/([A-Z][a-z])/g, ' $1').replace('SC ', '')),
|
||||
content: {
|
||||
@@ -142,8 +144,8 @@ export function generateOpenAPIForRoute(
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof route.obligatoryParameters === 'object') {
|
||||
for (const [parameter, schemaDefinition] of Object.entries(route.obligatoryParameters)) {
|
||||
if (typeof route['obligatoryParameters'] === 'object') {
|
||||
for (const [parameter, schemaDefinition] of Object.entries(route['obligatoryParameters'])) {
|
||||
const openapiParameter: OpenAPIV3.ParameterObject = {
|
||||
in: 'path',
|
||||
name: parameter,
|
||||
@@ -153,7 +155,7 @@ export function generateOpenAPIForRoute(
|
||||
$ref: `schema/SCSearchResponse.json#/definitions/${schemaDefinition}`,
|
||||
},
|
||||
};
|
||||
openapiPath[route.method.toLowerCase() as OpenAPIV3.HttpMethods]?.parameters?.push(openapiParameter);
|
||||
openapiPath[route['method'].toLowerCase() as OpenAPIV3.HttpMethods]?.parameters?.push(openapiParameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ function createPlantUMLCodeForClass(config: UMLConfig, readerClass: LightweightC
|
||||
if (config.showProperties && readerClass.properties) {
|
||||
for (const key in readerClass.properties) {
|
||||
const property = readerClass.properties[key];
|
||||
if (property.optional && !config.showOptionalProperties) {
|
||||
if (property?.optional && !config.showOptionalProperties) {
|
||||
// don't show optional attributes
|
||||
continue;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ function createPlantUMLCodeForClass(config: UMLConfig, readerClass: LightweightC
|
||||
// don't show inherited properties
|
||||
continue;
|
||||
}*/
|
||||
model += `\n\t${createPropertyLine(property)}`;
|
||||
model += `\n\t${createPropertyLine(property!)}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,13 +213,13 @@ function createPlantUMLCodeForClass(config: UMLConfig, readerClass: LightweightC
|
||||
if (readerClass.properties) {
|
||||
for (const key in readerClass.properties) {
|
||||
const property = readerClass.properties[key];
|
||||
const types: string[] = getReferenceTypes(property.type);
|
||||
const types: string[] = getReferenceTypes(property!.type);
|
||||
for (const type of types) {
|
||||
if (config.showAssociations) {
|
||||
/*if (property.inherited && !config.showInheritedProperties) {
|
||||
continue;
|
||||
}*/
|
||||
model += `${readerClass.name} -up-> ${type} : ${property.name} >\n`;
|
||||
model += `${readerClass.name} -up-> ${type} : ${property!.name} >\n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ export class Validator {
|
||||
}
|
||||
|
||||
// schema will be cached
|
||||
return this.ajvValidateWrapper(this.schemas[schema], instance);
|
||||
return this.ajvValidateWrapper(this.schemas[schema]!, instance);
|
||||
}
|
||||
|
||||
return this.ajvValidateWrapper(schema, instance);
|
||||
@@ -147,7 +147,7 @@ function fromAjvResult(
|
||||
const error: ValidationError = {
|
||||
dataPath: ajvError.instancePath,
|
||||
instance: instance,
|
||||
message: betterErrorObject?.[index]?.error ?? ajvError.message,
|
||||
message: betterErrorObject?.[index]?.error ?? ajvError.message!,
|
||||
name: ajvError.keyword,
|
||||
schemaPath: ajvError.schemaPath,
|
||||
suggestion: betterErrorObject?.[index]?.suggestion,
|
||||
@@ -223,7 +223,7 @@ export async function validateFiles(
|
||||
}
|
||||
|
||||
// add error to list of errors
|
||||
errors[testFileName].push({
|
||||
errors[testFileName]?.push({
|
||||
...error,
|
||||
expected,
|
||||
});
|
||||
@@ -234,7 +234,7 @@ export async function validateFiles(
|
||||
for (const error of expectedErrors) {
|
||||
await Logger.error(`Extraneous expected error '${error}' in ${testFile}.`);
|
||||
|
||||
errors[testFileName].push({
|
||||
errors[testFileName]?.push({
|
||||
dataPath: 'undefined',
|
||||
expected: false,
|
||||
instance: undefined,
|
||||
@@ -279,7 +279,7 @@ export async function writeReport(reportPath: PathLike, errors: ExpectedValidati
|
||||
|
||||
let fileOutput = '';
|
||||
|
||||
for (const [index, error] of errors[fileName].entries()) {
|
||||
for (const [index, error] of errors[fileName]!.entries()) {
|
||||
fileOutput += mustache.render(errorTemplate, {
|
||||
idx: index + 1,
|
||||
instance: JSON.stringify(error.instance, undefined, 2),
|
||||
|
||||
Reference in New Issue
Block a user