@digi-frontend/dgate-api-documentation 1.0.4 → 1.0.5

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.
Files changed (45) hide show
  1. package/dist/_virtual/index3.js +1 -1
  2. package/dist/_virtual/index4.js +1 -1
  3. package/dist/_virtual/index5.js +1 -1
  4. package/dist/_virtual/index6.js +1 -1
  5. package/dist/node_modules/digitinary-ui/dist/index.js +1 -1
  6. package/dist/node_modules/digitinary-ui/dist/index.js.map +1 -1
  7. package/dist/node_modules/js-yaml/dist/js-yaml.mjs.js +3 -0
  8. package/dist/node_modules/js-yaml/dist/js-yaml.mjs.js.map +1 -0
  9. package/dist/node_modules/toposort/index.js +1 -1
  10. package/dist/node_modules/yup/index.esm.js +1 -1
  11. package/dist/src/components/InfoForm/InfoForm.js +1 -1
  12. package/dist/src/components/InfoForm/InfoForm.js.map +1 -1
  13. package/dist/src/components/JsonInput/JsonInput.js +2 -0
  14. package/dist/src/components/JsonInput/JsonInput.js.map +1 -0
  15. package/dist/src/components/JsonInput/style.module.scss.js +2 -0
  16. package/dist/src/components/JsonInput/style.module.scss.js.map +1 -0
  17. package/dist/src/components/MethodAccordion/MethodAccordion.js +1 -1
  18. package/dist/src/components/MethodAccordion/MethodAccordion.js.map +1 -1
  19. package/dist/src/constants/index.js +1 -1
  20. package/dist/src/constants/index.js.map +1 -1
  21. package/dist/src/helpers/layout.helper.js +1 -1
  22. package/dist/src/helpers/layout.helper.js.map +1 -1
  23. package/dist/src/layout/layout.js +1 -1
  24. package/dist/src/layout/layout.js.map +1 -1
  25. package/dist/src/layout/layout.module.css.js +1 -1
  26. package/dist/styles.css +315 -212
  27. package/dist/types/components/JsonInput/JsonInput.d.ts +13 -0
  28. package/dist/types/components/MethodAccordion/MethodAccordion.d.ts +1 -2
  29. package/dist/types/constants/index.d.ts +12 -4
  30. package/dist/types/types/layout.type.d.ts +9 -1
  31. package/dist/types/types/openApi.d.ts +1 -1
  32. package/package.json +2 -1
  33. package/src/components/InfoForm/InfoForm.module.scss +0 -5
  34. package/src/components/InfoForm/InfoForm.tsx +3 -17
  35. package/src/components/JsonInput/JsonInput.tsx +124 -0
  36. package/src/components/JsonInput/style.module.scss +123 -0
  37. package/src/components/MethodAccordion/MethodAccordion.module.scss +10 -5
  38. package/src/components/MethodAccordion/MethodAccordion.tsx +17 -47
  39. package/src/constants/index.ts +16 -8
  40. package/src/helpers/layout.helper.ts +53 -24
  41. package/src/layout/layout.module.css +18 -0
  42. package/src/layout/layout.tsx +40 -16
  43. package/src/types/layout.type.ts +9 -1
  44. package/src/types/openApi.ts +1 -1
  45. package/dist/types/types/index.d.ts +0 -18
@@ -1,15 +1,19 @@
1
1
  import { TransformedPathsArray } from '@entities/layout.type'
2
- import { OpenAPIFile } from '@entities/openApi'
2
+ import { OpenAPIFile, SecurityScheme } from '@entities/openApi'
3
3
  import { TransformedOpenApi } from '@entities/transformedOpenApi'
4
4
 
5
5
  export const transformOpenApiObject = (openApiJson: OpenAPIFile): TransformedOpenApi => {
6
6
  if (openApiJson.components && openApiJson.components.securitySchemes) {
7
- const authKey = Object.keys(openApiJson.components.securitySchemes)
8
- if (authKey && authKey.length) {
9
- openApiJson.components.securitySchemes[authKey[0]].type =
10
- openApiJson?.components?.securitySchemes?.[authKey[0]]?.type?.toUpperCase()
7
+ const authKey = Object.keys(openApiJson.components.securitySchemes)?.at(0)
8
+
9
+ if (authKey) {
10
+ openApiJson.components.securitySchemes[authKey].type =
11
+ openApiJson?.components?.securitySchemes?.[
12
+ authKey
13
+ ]?.type?.toUpperCase() as SecurityScheme['type']
11
14
  }
12
15
  }
16
+
13
17
  return {
14
18
  ...openApiJson,
15
19
  paths: transformPathsToArray(openApiJson.paths),
@@ -22,16 +26,16 @@ export const transformOpenApiObjectToOrigin = (values: TransformedOpenApi): Open
22
26
  paths: transformPathsArrayToOrigin(values.paths),
23
27
  }
24
28
  if (object.components && object.components.securitySchemes) {
25
- const authKey = Object.keys(object.components.securitySchemes)
26
- if (authKey && authKey.length) {
27
- if (
28
- object.components.securitySchemes[authKey[0]].type.toLowerCase() == 'APIKEY'.toLowerCase()
29
- ) {
30
- object.components.securitySchemes[authKey[0]].in =
31
- object.components.securitySchemes[authKey[0]].in.toUpperCase()
29
+ const authKey = Object.keys(object.components.securitySchemes)?.at(0)
30
+ if (authKey) {
31
+ if (object.components.securitySchemes[authKey].type.toLowerCase() == 'APIKEY'.toLowerCase()) {
32
+ object.components.securitySchemes[authKey].in = object.components.securitySchemes[
33
+ authKey
34
+ ].in.toUpperCase() as SecurityScheme['in']
32
35
  }
33
- object.components.securitySchemes[authKey[0]].type =
34
- object?.components?.securitySchemes?.[authKey[0]]?.type?.toUpperCase()
36
+ object.components.securitySchemes[authKey].type = object?.components?.securitySchemes?.[
37
+ authKey
38
+ ]?.type?.toUpperCase() as SecurityScheme['type']
35
39
  }
36
40
  }
37
41
  return object
@@ -51,23 +55,42 @@ export const transformPathsToArray = (paths: OpenAPIFile['paths']): TransformedP
51
55
  code,
52
56
  content: {
53
57
  contentType,
54
- schema: codeProps.content?.[contentType]?.schema,
58
+ schema: {
59
+ ...codeProps.content?.[contentType]?.schema,
60
+ properties: JSON.stringify(codeProps.content?.[contentType]?.schema?.properties),
61
+ },
55
62
  },
56
63
  }
57
64
  }),
58
65
  }
66
+
59
67
  if (method.toLowerCase() != 'get') {
60
68
  obj['requestBody'] = methodProps.requestBody
61
- ? Object.entries(methodProps.responses).map(([_, codeProps]) => {
69
+ ? Object.entries(methodProps.requestBody).map(([_, codeProps]) => {
62
70
  const contentType = Object.keys(codeProps.content || {})[0]
63
71
  return {
64
72
  content: {
65
73
  contentType,
66
- schema: codeProps.content?.[contentType]?.schema,
74
+ schema: {
75
+ ...codeProps.content?.[contentType]?.schema,
76
+ properties: JSON.stringify(
77
+ codeProps.content?.[contentType]?.schema?.properties
78
+ ),
79
+ },
67
80
  },
68
81
  }
69
82
  })
70
- : {}
83
+ : [
84
+ {
85
+ content: {
86
+ contentType: 'application/json',
87
+ schema: {
88
+ properties: '{}',
89
+ type: 'object',
90
+ },
91
+ },
92
+ },
93
+ ]
71
94
  }
72
95
  return obj
73
96
  }),
@@ -86,24 +109,30 @@ export const transformPathsArrayToOrigin = (paths: TransformedPathsArray): OpenA
86
109
  respAcc[code] = {
87
110
  description: 'Success', // Assuming this is static from the original data
88
111
  content: content.contentType
89
- ? { [content.contentType]: { schema: content.schema } }
112
+ ? {
113
+ [content.contentType]: {
114
+ schema: {
115
+ ...(content.schema as object),
116
+ properties: JSON.parse((content?.schema as any)?.properties as string),
117
+ },
118
+ },
119
+ }
90
120
  : {},
91
121
  }
92
122
  return respAcc
93
123
  }, {} as Record<string, any>),
94
124
  }
95
125
 
126
+ const parsedRequestBodyProps =
127
+ type !== 'get' ? JSON.parse(requestBody[0].content.schema.properties) : {}
96
128
  // Add requestBody for non-GET methods
97
- if (type !== 'get' && requestBody?.length > 0) {
129
+ if (type !== 'get') {
98
130
  methodAcc[type].requestBody = {
99
131
  content: {
100
132
  [requestBody[0].content.contentType]: {
101
133
  schema: {
102
134
  ...requestBody[0].content.schema,
103
- properties:
104
- typeof requestBody[0].content.schema.properties === 'string'
105
- ? JSON.parse(requestBody[0].content.schema.properties)
106
- : requestBody[0].content.schema.properties,
135
+ properties: parsedRequestBodyProps,
107
136
  },
108
137
  },
109
138
  },
@@ -21,6 +21,24 @@
21
21
  .editorSide {
22
22
  background-color: #fff;
23
23
  padding-bottom: 1.25rem;
24
+
25
+ .editorSectionHead {
26
+
27
+ span {
28
+ width: 100%;
29
+ }
30
+
31
+ .editorSectionHead_content {
32
+ display: flex;
33
+ justify-content: space-between;
34
+ align-items: center;
35
+
36
+ button {
37
+ width: 6.25rem;
38
+ }
39
+ }
40
+
41
+ }
24
42
  }
25
43
 
26
44
  .livePreviewSide {
@@ -1,5 +1,5 @@
1
1
  import { JSX } from 'react'
2
- import { Alert } from 'digitinary-ui'
2
+ import { Alert, Button } from 'digitinary-ui'
3
3
  import MethodsAccordion from '../components/MethodAccordion/MethodAccordion'
4
4
  import styles from './layout.module.css'
5
5
  import InfoForm from '../components/InfoForm/InfoForm'
@@ -8,23 +8,25 @@ import { transformOpenApiObject, transformOpenApiObjectToOrigin } from '../helpe
8
8
  import { OpenAPIFile } from '../types/openApi'
9
9
  import LivePreview from '../components/LivePreview/LivePreview'
10
10
  import { FormikProvider, useFormik } from 'formik'
11
- import * as Yup from 'yup'
12
11
  import { schemaValidation } from '../validator/form.scheme'
13
12
  import { TransformedOpenApi } from '@entities/transformedOpenApi'
13
+ import { methodColorMapping } from '../constants/index'
14
14
 
15
15
  interface ILayoutProps {
16
16
  openApiJson?: OpenAPIFile
17
17
  }
18
18
 
19
19
  const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
20
- const transformedOpenApi = transformOpenApiObject(openApiJson)
20
+ const clonedOpenApiJson = structuredClone(openApiJson)
21
+ const transformedOpenApi = transformOpenApiObject(clonedOpenApiJson)
21
22
  const formik = useFormik<TransformedOpenApi>({
22
23
  initialValues: structuredClone(transformedOpenApi),
23
24
  validationSchema: schemaValidation,
24
25
  validateOnMount: true,
25
26
  onSubmit: (values, { validateForm }) => {
26
27
  // Handle save logic
27
- handleSave(transformOpenApiObjectToOrigin(values))
28
+ const originalOpenApiForm = transformOpenApiObjectToOrigin(values)
29
+ handleSave(originalOpenApiForm)
28
30
  validateForm(values)
29
31
  },
30
32
  })
@@ -37,7 +39,25 @@ const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
37
39
  </Alert>
38
40
  <div className={styles.layoutContainer}>
39
41
  <div className={`${styles.editorSide} ${styles.docSide}`}>
40
- <SectionHead className={styles.editorSectionHead} text="API Information" />
42
+ <SectionHead
43
+ className={styles.editorSectionHead}
44
+ text={
45
+ <div className={styles.editorSectionHead_content}>
46
+ API Information
47
+ <Button
48
+ className={styles.methodForm_submitBtn}
49
+ size="medium"
50
+ fullWidth={false}
51
+ type="submit"
52
+ variant="contained"
53
+ color="primary"
54
+ onClick={formik.submitForm}
55
+ >
56
+ Save
57
+ </Button>
58
+ </div>
59
+ }
60
+ />
41
61
  <FormikProvider value={formik}>
42
62
  <InfoForm />
43
63
  </FormikProvider>
@@ -45,17 +65,21 @@ const Layout = ({ openApiJson, handleSave }: ILayoutProps): JSX.Element => {
45
65
  <FormikProvider value={formik}>
46
66
  {formik.values.paths.map((path, pathIndex) => (
47
67
  <>
48
- {path.methods.map((method, methodIndex) => (
49
- <MethodsAccordion
50
- method={method}
51
- path={path.path}
52
- setFieldValue={(key, value) => {
53
- const h = `paths[${pathIndex}].methods[${methodIndex}].${key}`
54
- formik.setFieldValue(h, value)
55
- }}
56
- handleSave={formik.submitForm}
57
- />
58
- ))}
68
+ {path.methods
69
+ .sort(
70
+ (method) =>
71
+ methodColorMapping[method.type].order + methodColorMapping[method.type].order
72
+ )
73
+ .map((method, methodIndex) => (
74
+ <MethodsAccordion
75
+ method={method}
76
+ path={path.path}
77
+ setFieldValue={(key, value) => {
78
+ const h = `paths[${pathIndex}].methods[${methodIndex}].${key}`
79
+ formik.setFieldValue(h, value)
80
+ }}
81
+ />
82
+ ))}
59
83
  </>
60
84
  ))}
61
85
  </FormikProvider>
@@ -4,7 +4,15 @@ export type TransformedMethod = {
4
4
  type: HTTPMethod
5
5
  tags: string[]
6
6
  parameters: any
7
- requestBody: any
7
+ requestBody: {
8
+ content: {
9
+ contentType: string
10
+ schema: {
11
+ properties: string
12
+ type: string
13
+ }
14
+ }
15
+ }[]
8
16
  responses: {
9
17
  code: string
10
18
  content: {
@@ -81,7 +81,7 @@ interface Schema {
81
81
  required?: string[]
82
82
  }
83
83
 
84
- interface SecurityScheme {
84
+ export interface SecurityScheme {
85
85
  type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect'
86
86
  description?: string
87
87
  name?: string
@@ -1,18 +0,0 @@
1
- export type MethodTypes = 'GET' | 'POST' | 'PUT' | 'DELETE';
2
- export interface ParameterType {
3
- name: string;
4
- in: string;
5
- schemaType: string;
6
- required: boolean;
7
- }
8
- export interface MethodAccordionProps {
9
- method: MethodTypes;
10
- path: string;
11
- desc: string;
12
- parameters: ParameterType[];
13
- request: string;
14
- response: {
15
- content: string;
16
- statusCode: number;
17
- };
18
- }