@digi-frontend/dgate-api-documentation 1.0.84 → 1.0.86

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.
@@ -2,6 +2,11 @@ import { TransformedPathsArray } from '@entities/layout.type'
2
2
  import { OpenAPIFile, SecurityScheme } from '@entities/openApi'
3
3
  import { TransformedOpenApi } from '@entities/transformedOpenApi'
4
4
 
5
+ const resolveRef = (ref: string, openApiJson: OpenAPIFile): Object => {
6
+ const parts = ref.replace(/^#\//, '').split('/')
7
+ return parts.reduce((obj, key) => obj?.[key], openApiJson)
8
+ }
9
+
5
10
  export const transformOpenApiObject = (openApiJson: OpenAPIFile): TransformedOpenApi => {
6
11
  if (openApiJson.components && openApiJson.components.securitySchemes) {
7
12
  const authKey = Object.keys(openApiJson.components.securitySchemes)?.at(0)
@@ -17,6 +22,7 @@ export const transformOpenApiObject = (openApiJson: OpenAPIFile): TransformedOpe
17
22
  scheme: 'public',
18
23
  },
19
24
  },
25
+ ...(openApiJson.components || {}),
20
26
  }
21
27
  }
22
28
 
@@ -26,7 +32,7 @@ export const transformOpenApiObject = (openApiJson: OpenAPIFile): TransformedOpe
26
32
 
27
33
  return {
28
34
  ...openApiJson,
29
- paths: transformPathsToArray(openApiJson.paths),
35
+ paths: transformPathsToArray(openApiJson),
30
36
  } as TransformedOpenApi
31
37
  }
32
38
 
@@ -50,7 +56,8 @@ export const transformOpenApiObjectToOrigin = (values: TransformedOpenApi): Open
50
56
  return object
51
57
  }
52
58
 
53
- export const transformPathsToArray = (paths: OpenAPIFile['paths']): TransformedPathsArray | any => {
59
+ export const transformPathsToArray = (openApiJson: OpenAPIFile): TransformedPathsArray | any => {
60
+ const paths: OpenAPIFile['paths'] = openApiJson.paths
54
61
  const transformedPaths = Object.entries(paths).map(([path, methods]) => ({
55
62
  path,
56
63
  methods: Object.entries(methods).map(([method, methodProps]) => {
@@ -61,20 +68,55 @@ export const transformPathsToArray = (paths: OpenAPIFile['paths']): TransformedP
61
68
  summary: methodProps.summary || '',
62
69
  responses: Object.entries(methodProps.responses).map(([code, codeProps]) => {
63
70
  const contentType = Object.keys(codeProps.content || {})[0]
64
- const headers = !codeProps?.headers ? {} : codeProps.headers
71
+ let headers = codeProps?.headers ?? {}
72
+
73
+ // ? Fix headers with items property
74
+ Object.keys(headers).map((header: string) => {
75
+ let headerObj = headers[header]
76
+ if (
77
+ headerObj?.schema &&
78
+ headerObj?.schema?.type &&
79
+ headerObj?.schema?.type != 'array'
80
+ ) {
81
+ delete headers[header]?.schema?.items
82
+ }
83
+ })
84
+
85
+ let schema = codeProps.content?.[contentType]?.schema
86
+ if (schema?.$ref) {
87
+ schema = resolveRef(schema?.$ref, openApiJson)
88
+ } else if (schema?.type == 'array' && schema?.items?.$ref) {
89
+ const resolvedItemSchema = resolveRef(schema.items.$ref, openApiJson)
90
+ schema = {
91
+ ...schema,
92
+ items: resolvedItemSchema,
93
+ }
94
+ }
95
+
65
96
  return {
66
97
  code,
67
98
  headers,
68
99
  content: {
69
100
  contentType,
70
101
  schema: {
71
- ...codeProps.content?.[contentType]?.schema,
72
- properties: JSON.stringify(codeProps.content?.[contentType]?.schema?.properties),
102
+ ...schema,
103
+ properties: JSON.stringify(schema?.properties || schema?.items?.properties),
73
104
  },
74
105
  },
75
106
  }
76
107
  }),
77
108
  }
109
+
110
+ if (!obj.responses.find((item) => item.code == '200')) {
111
+ obj.responses.push({
112
+ code: '200',
113
+ content: {
114
+ contentType: 'application/json',
115
+ schema: {},
116
+ },
117
+ headers: {},
118
+ })
119
+ }
78
120
  // Add parameters if it does not exist in the original JSON
79
121
  if (!methodProps?.parameters) {
80
122
  obj.parameters = []
@@ -84,14 +126,24 @@ export const transformPathsToArray = (paths: OpenAPIFile['paths']): TransformedP
84
126
 
85
127
  if (method.toLowerCase() != 'get') {
86
128
  const contentType = Object.keys(methodProps?.requestBody?.content || {})[0]
87
- const reqSchema = methodProps?.requestBody?.content?.schema
88
- const requestBodyData = methodProps?.requestBody?.content?.schema?.properties
129
+ let reqSchema = methodProps?.requestBody?.content?.[contentType]?.schema
130
+
131
+ if (reqSchema?.$ref) {
132
+ reqSchema = resolveRef(reqSchema.$ref, openApiJson)
133
+ } else if (reqSchema?.type === 'array' && reqSchema.items?.$ref) {
134
+ reqSchema = {
135
+ ...reqSchema,
136
+ items: resolveRef(reqSchema.items.$ref, openApiJson),
137
+ }
138
+ }
139
+
140
+ const requestBodyData = reqSchema
89
141
  ? {
90
142
  content: {
91
143
  contentType,
92
144
  schema: {
93
145
  ...reqSchema,
94
- properties: reqSchema?.properties ? JSON.stringify(reqSchema?.properties) : '{}',
146
+ properties: JSON.stringify(reqSchema?.properties || reqSchema?.items?.properties),
95
147
  },
96
148
  },
97
149
  }
@@ -128,8 +180,18 @@ export const transformPathsArrayToOrigin = (paths: TransformedPathsArray): OpenA
128
180
  acc[path] = methods.reduce(
129
181
  (methodAcc, { type, tags, responses, summary, requestBody, ...rest }) => {
130
182
  // Initialize the method object
183
+ // ? Validate (rest) [parameters]
184
+ let copiedRest = structuredClone(rest || {})
185
+ if (copiedRest && copiedRest.parameters) {
186
+ copiedRest.parameters.map((param) => {
187
+ if (param && param?.schema?.items && param?.schema?.items?.type == 'array') {
188
+ param.schema.items.items = {}
189
+ }
190
+ return param
191
+ })
192
+ }
131
193
  methodAcc[type] = {
132
- ...rest,
194
+ ...copiedRest,
133
195
  tags,
134
196
  summary,
135
197
  responses: responses.reduce((respAcc, { code, content, headers }) => {
@@ -27,12 +27,18 @@
27
27
  font-size: 1rem;
28
28
  line-height: 1.25rem;
29
29
 
30
+ .btnContentWrapper {
31
+ .btnContent{
32
+ font-size: 0.918rem !important;
33
+ }
34
+ }
35
+
30
36
  &:hover:not(:disabled) {
31
37
  color: #000000 !important;
32
38
  }
33
39
 
34
40
  &:hover {
35
- color: #000;
41
+ color: #000 !important;
36
42
  }
37
43
 
38
44
  svg {
@@ -74,6 +80,12 @@
74
80
  line-height: 1.234rem;
75
81
  height: 2.25rem;
76
82
 
83
+ .btnContentWrapper {
84
+ .btnContent{
85
+ font-size: 0.918rem !important;
86
+ }
87
+ }
88
+
77
89
  &:hover:not(:disabled) {
78
90
  color: #000000 !important;
79
91
  }
@@ -49,6 +49,7 @@ const Layout = ({
49
49
  })
50
50
  const { dirty, isValid, isSubmitting, values, setFieldValue, handleSubmit, errors } = formik
51
51
  const [isPublishDialogOpen, setIsPublishDialogOpen] = useState(false)
52
+
52
53
  const [openMethodIndex, setOpenMethodIndex] = useState<number | null>(null)
53
54
 
54
55
  useEffect(() => {
@@ -57,11 +58,6 @@ const Layout = ({
57
58
  }
58
59
  }, [dirty])
59
60
 
60
- // TODO: keep it here until production
61
- useEffect(() => {
62
- console.log({ values, errors })
63
- }, [values])
64
-
65
61
  return (
66
62
  <div className={styles.docsLayout}>
67
63
  {dirty && (
@@ -111,8 +107,8 @@ const Layout = ({
111
107
  const h = `paths[${pathIndex}].methods[${methodIndex}].${key}`
112
108
  setFieldValue(h, value)
113
109
  }}
114
- isOpen={openMethodIndex === methodIndex}
115
- setIsOpen={(open) => setOpenMethodIndex(open ? methodIndex : null)}
110
+ isOpen={openMethodIndex === parseInt(`${pathIndex}${methodIndex}`)}
111
+ setIsOpen={(open) => setOpenMethodIndex(open ? parseInt(`${pathIndex}${methodIndex}`) : null)}
116
112
  errors={(formik.errors.paths?.[pathIndex] as any)?.methods?.[methodIndex]}
117
113
  />
118
114
  ))}
package/variables.txt CHANGED
@@ -1 +1 @@
1
- export APP_VERSION=1.0.83
1
+ export APP_VERSION=1.0.85