Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
p-zielinski committed Dec 1, 2023
1 parent 127223d commit 9d8c824
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
6 changes: 1 addition & 5 deletions reference/OpenAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@
"type": "string",
"example": "camp_rRsfatlwN7unSeUIJDCYedal"
},
"ParameterCampaignId": {
"type": "string",
"example": "camp_rRsfatlwN7unSeUIJDCYedal"
},
"ParameterEarningRuleId": {
"type": "string",
"example": "ern_CFuv1O0IDl8Jgph0ojhMu8bH"
Expand Down Expand Up @@ -70031,7 +70027,7 @@
"/v1/customers/{customerId}": {
"parameters": [
{
"schema": {,
"schema": {
"$ref": "#/components/schemas/ParameterCustomerId"
},
"name": "customerId",
Expand Down
96 changes: 54 additions & 42 deletions scripts/count-important-statistics-about-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,76 @@ import path from "path";
import fsPromises from "fs/promises";

const main = async () => {
const openApiPath = path.join(__dirname, "../reference/OpenAPI.json");
const openAPIContent = JSON.parse(
(await fsPromises.readFile(openApiPath)).toString()
);
const openApiPath = path.join(__dirname, "../reference/OpenAPI.json");
const openAPIContent = JSON.parse(
(await fsPromises.readFile(openApiPath)).toString()
);

countResponsesSchemasWithOneOf(openAPIContent);
countParametersWithoutRefs(openAPIContent);
countEndpointsWithParametersThatNotUsingRefs(openAPIContent);
}
countResponsesSchemasWithOneOf(openAPIContent);
countParametersWithoutRefs(openAPIContent);
countEndpointsWithParametersThatNotUsingRefs(openAPIContent);
};

const countResponsesSchemasWithOneOf = (openAPIContent) => {
const schemas = openAPIContent.components.schemas;
const schemas = openAPIContent.components.schemas;

const schemasWithOneOf = Object.keys(schemas)
.filter(schemaName => schemaName.includes("ResponseBody"))
.filter(schemaName => schemas[schemaName].oneOf)
const schemasWithOneOf = Object.keys(schemas)
.filter((schemaName) => schemaName.includes("ResponseBody"))
.filter((schemaName) => schemas[schemaName].oneOf);

console.log("Responses schemas with oneOf = ", schemasWithOneOf);
}
console.log("Responses schemas with oneOf = ", schemasWithOneOf);
};

const countParametersWithoutRefs = (openAPIContent) => {
const parameters = openAPIContent.components.parameters;
const parameters = openAPIContent.components.parameters;

const parametersWithoutRefs = Object.keys(parameters)
.filter(parameterName => !parameters[parameterName].schema.$ref)
const parametersWithoutRefs = Object.keys(parameters).filter(
(parameterName) => !parameters[parameterName].schema.$ref
);

console.log("Parameters without refs = ", parametersWithoutRefs.length);
}
console.log(
"Parameters without refs = ",
parametersWithoutRefs.length,
parametersWithoutRefs
);
};

const countEndpointsWithParametersThatNotUsingRefs = (openAPIContent) => {
type PathsWithMethods = Record<string, MethodWithParametersCount>;
type MethodWithParametersCount = Record<string, number>;
type PathsWithMethods = Record<string, MethodWithParametersCount>;
type MethodWithParametersCount = Record<string, number>;

const paths = openAPIContent.paths;
const paths = openAPIContent.paths;

const result: PathsWithMethods = {}
const result: PathsWithMethods = {};

Object.keys(paths).forEach(path => {
result[path] = {};
Object.keys(paths).forEach((path) => {
result[path] = {};

const methods = Object.keys(paths[path]);
methods.forEach(method => {
const parameters = paths[path][method].parameters;
if(parameters){
const parametersWithoutRefs = parameters.filter(parameter => !parameter.$ref);
const methods = Object.keys(paths[path]);
methods.forEach((method) => {
const parameters = paths[path][method].parameters;
if (parameters) {
const parametersWithoutRefs = parameters.filter(
(parameter) => !parameter.$ref
);

if(parametersWithoutRefs.length){
result[path][method] = parametersWithoutRefs.map(parameter => parameter.name).join(", ");
}
}
})

if(!Object.keys(result[path]).length){
delete result[path];
if (parametersWithoutRefs.length) {
result[path][method] = parametersWithoutRefs
.map((parameter) => parameter.name)
.join(", ");
}
})
}
});

if (!Object.keys(result[path]).length) {
delete result[path];
}
});

console.log("Schema and methods that contains parameters without refs = ", result);
}
console.log(
"Schema and methods that contains parameters without refs = ",
result
);
};

main()
main();

0 comments on commit 9d8c824

Please sign in to comment.