openapi-sync 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helpers.ts DELETED
@@ -1,128 +0,0 @@
1
- import { variableNameChar } from "./regex";
2
- import * as yaml from "js-yaml";
3
-
4
- export const isJson = (value: any) => {
5
- return ["object"].includes(typeof value) && !(value instanceof Blob);
6
- };
7
-
8
- export const isYamlString = (fileContent: string) => {
9
- try {
10
- yaml.load(fileContent);
11
- return true;
12
- } catch (en) {
13
- const e = en as any;
14
- if (e instanceof yaml.YAMLException) {
15
- return false;
16
- } else {
17
- throw e;
18
- }
19
- }
20
- };
21
-
22
- export const yamlStringToJson = (fileContent: string) => {
23
- if (isYamlString(fileContent)) {
24
- const content = yaml.load(fileContent);
25
-
26
- const jsonString = JSON.stringify(content, null, 2);
27
- const json = JSON.parse(jsonString);
28
- return json;
29
- }
30
- };
31
-
32
- export const capitalize = (text: string) => {
33
- const capitalizedWord =
34
- text.substring(0, 1).toUpperCase() + text.substring(1);
35
- return capitalizedWord;
36
- };
37
-
38
- export const getEndpointDetails = (path: string, method: string) => {
39
- const pathParts = path.split("/");
40
- let name = `${capitalize(method)}`;
41
- const variables: string[] = [];
42
- pathParts.forEach((part) => {
43
- // check if part is a variable
44
- //api/{userId}
45
- if (part[0] === "{" && part[part.length - 1] === "}") {
46
- const s = part.replace(/{/, "").replace(/}/, "");
47
- variables.push(s);
48
- part = `$${s}`;
49
- }
50
-
51
- //api/<userId>
52
- else if (part[0] === "<" && part[part.length - 1] === ">") {
53
- const s = part.replace(/</, "").replace(/>/, "");
54
- variables.push(s);
55
- part = `$${s}`;
56
- }
57
-
58
- //api/:userId
59
- else if (part[0] === ":") {
60
- const s = part.replace(/:/, "");
61
- variables.push(s);
62
- part = `$${s}`;
63
- }
64
-
65
- // parse to variable name
66
- let partVal = "";
67
- part.split("").forEach((char) => {
68
- let c = char;
69
- if (!variableNameChar.test(char)) c = "/";
70
- partVal += c;
71
- });
72
-
73
- partVal.split("/").forEach((val) => {
74
- name += capitalize(val);
75
- });
76
- });
77
-
78
- return { name, variables, pathParts };
79
- };
80
-
81
- export const JSONStringify = (obj: Record<string, any>, indent = 1) => {
82
- let result = "{";
83
- const keys = Object.keys(obj);
84
-
85
- for (let i = 0; i < keys.length; i++) {
86
- const key = keys[i];
87
- const value = obj[key];
88
-
89
- result += "\n" + " ".repeat(indent) + key + ": ";
90
-
91
- if (typeof value === "object" && value !== null) {
92
- result += "" + JSONStringify(value, indent + 1);
93
- } else {
94
- result += value
95
- .split("\n")
96
- .filter((line: string) => line.trim() !== "")
97
- .join(`\n${" ".repeat(indent)}`);
98
- }
99
-
100
- if (i < keys.length - 1) {
101
- result += ", ";
102
- }
103
- }
104
-
105
- result += `\n${" ".repeat(indent - 1)}}`;
106
- return result;
107
- };
108
-
109
- export const renderTypeRefMD = (typeRef: string, indent = 1) => {
110
- return `\n\`\`\`typescript\n${" ".repeat(indent)} ${typeRef
111
- .split("\n")
112
- .filter((line) => line.trim() !== "")
113
- .join(`\n${" ".repeat(indent)} `)}\n\`\`\``;
114
- };
115
-
116
- export function getNestedValue<T>(obj: object, path: string): T | undefined {
117
- // Split the path string into an array of keys
118
- const keys = path.split(".");
119
-
120
- // Use the reduce method to navigate the object
121
- return keys.reduce((currentObj: any, key: string) => {
122
- // If the current object is not null or undefined,
123
- // return the value of the next key. Otherwise, return undefined.
124
- return currentObj && currentObj[key] !== undefined
125
- ? currentObj[key]
126
- : undefined;
127
- }, obj) as T | undefined;
128
- }
package/regex.ts DELETED
@@ -1,2 +0,0 @@
1
- export const variableName = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
2
- export const variableNameChar = /[A-Za-z0-9_$]/;
package/types.ts DELETED
@@ -1,139 +0,0 @@
1
- import { Method } from "axios";
2
-
3
- export type IOpenApiSpec = Record<"openapi", string> & Record<string, any>;
4
-
5
- export type IOpenApSchemaSpec = {
6
- nullable?: boolean;
7
- type:
8
- | "string"
9
- | "integer"
10
- | "number"
11
- | "array"
12
- | "object"
13
- | "boolean"
14
- | "null"
15
- | any[];
16
- example?: any;
17
- enum?: string[];
18
- format?: string;
19
- items?: IOpenApSchemaSpec;
20
- required?: string[];
21
- description?: string;
22
- $ref?: string;
23
- properties?: Record<string, IOpenApSchemaSpec>;
24
- additionalProperties?: IOpenApSchemaSpec;
25
- anyOf?: IOpenApSchemaSpec[];
26
- oneOf?: IOpenApSchemaSpec[];
27
- allOf?: IOpenApSchemaSpec[];
28
- };
29
-
30
- export type IOpenApiParameterSpec = {
31
- $ref?: string;
32
- name: string;
33
- in: string;
34
- enum?: string[];
35
- description?: string;
36
- required?: boolean;
37
- deprecated?: boolean;
38
- allowEmptyValue?: boolean;
39
- style?: string;
40
- explode?: boolean;
41
- allowReserved?: boolean;
42
- schema?: IOpenApSchemaSpec;
43
- example?: any;
44
- examples?: any[];
45
- };
46
-
47
- export type IOpenApiMediaTypeSpec = {
48
- schema?: IOpenApSchemaSpec;
49
- example?: any;
50
- examples?: any[];
51
- encoding?: any;
52
- };
53
-
54
- export type IOpenApiRequestBodySpec = {
55
- description?: string;
56
- required?: boolean;
57
- content: Record<string, IOpenApiMediaTypeSpec>;
58
- };
59
-
60
- export type IOpenApiResponseSpec = Record<string, IOpenApiRequestBodySpec>;
61
-
62
- export type IConfigReplaceWord = {
63
- /** string and regular expression as a string*/
64
- replace: string;
65
- with: string;
66
- type?: "endpoint" | "type";
67
- };
68
-
69
- export type IConfigDoc = {
70
- disable?: boolean;
71
- showCurl?: boolean;
72
- };
73
-
74
- export type IConfig = {
75
- refetchInterval?: number;
76
- folder?: string;
77
- api: Record<string, string>;
78
- server?: number | string;
79
- types?: {
80
- name?: {
81
- prefix?: string;
82
- format?: (
83
- source: "shared" | "endpoint",
84
- data: {
85
- name?: string;
86
- ////. endpoint source //////
87
- type?: "response" | "dto" | "query";
88
- code?: string;
89
- method?: Method;
90
- path?: string;
91
- summary?: string;
92
- },
93
- defaultName: string
94
- ) => string | null | undefined;
95
- };
96
- doc?: IConfigDoc;
97
- };
98
- endpoints?: {
99
- value?: {
100
- replaceWords?: IConfigReplaceWord[];
101
- includeServer?: boolean;
102
- type?: "string" | "object";
103
- };
104
- name?: {
105
- format?: (
106
- data: {
107
- method: Method;
108
- path: string;
109
- summary: string;
110
- operationId: string;
111
- },
112
- defaultName: string
113
- ) => string | null;
114
- prefix?: string;
115
- useOperationId?: boolean;
116
- };
117
- doc?: IConfigDoc;
118
- };
119
- };
120
-
121
- export type IOpenApiSecuritySchemes = {
122
- [key: string]: {
123
- type: "http" | "apiKey" | "oauth2" | "openIdConnect" | "mutualTLS";
124
- scheme?: "bearer" | "basic";
125
- in?: "query" | "header" | "cookie";
126
- flows?: {
127
- authorizationCode: {
128
- authorizationUrl: "https://example.com/auth";
129
- tokenUrl: "https://example.com/token";
130
- scopes: {
131
- "read:data": "Grants read access";
132
- };
133
- };
134
- };
135
- bearerFormat?: "JWT";
136
- openIdConnectUrl?: string;
137
- name?: string;
138
- };
139
- };