Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/sast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
# List of paths (space separated) to ignore
# Supports PATTERNS
# EXCLUDE_PATHS: 'foo bar/baz file.txt dir/*.yml'
EXCLUDE_PATHS: 'examples'
EXCLUDE_PATHS: 'examples generator-templates'
# List of rules (space separated) to ignore
# EXCLUDE_RULES: 'generic.secrets.security.detected-aws-account-id.detected-aws-account-id'
# See https://github.com/semgrep/semgrep-rules for rules registry
Expand Down
25 changes: 20 additions & 5 deletions dev.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# Development

Js client is written using typescript, mainly generated from [openapi spec](https://github.com/regulaforensics/DocumentReader-api-openapi).
Openapi-generator output used as implementation base(see packages `/src/api`, `/scr/models`).
All custom logic, on top of generated files, should be places in `/src/ext` folder.
Models generation based on [openapi spec](https://github.com/regulaforensics/DocumentReader-api-openapi).

## Generation

To regenerate models from openapi definition,
clone [latest open api definitions](https://github.com/regulaforensics/DocumentReader-api-openapi)
and use next command from the project root:
clone [latest open api definitions](https://github.com/regulaforensics/DocumentReader-api-openapi)
and use next command from the project root.
```bash
./update-models.sh
```

## Generator configuration Features

1. The generator treats the discriminator value as a string,
but in our case it's numbers. To solve this problem, changes
have been made to the modelOneOf.mustache template.

## Problem solving

To solve new problems, use the generator
settings ([typescript](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/typescript-axios.md),
[common](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md))
and [templates](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript-axios).

**Do not edit the generated files! They will be overwritten after generation!**
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettierRecommended from 'eslint-plugin-prettier/recommended';

export default [
{
files: ['**/*.{js,mjs,cjs,ts}'],
},
{
languageOptions: {
globals: { ...globals.browser, ...globals.node },
},
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
prettierRecommended,
{
ignores: ['dist/*', 'lib/*', '!.*'],
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
];
35 changes: 18 additions & 17 deletions examples/auth/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/auth/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"dependencies": {
"@regulaforensics/document-reader-webclient": "file:../../..",
"axios": "^1.8.3",
"axios": "^1.8.4",
"qs": "^6.14.0"
},
"version": "0.0.0"
Expand Down
8 changes: 4 additions & 4 deletions examples/auth/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/auth/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "node index.js"
},
"dependencies": {
"axios": "^1.8.3",
"axios": "^1.8.4",
"body-parser": "^1.20.3",
"cors": "^2.8.5",
"express": "^5.0.1",
Expand Down
36 changes: 25 additions & 11 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,34 @@ If the instance has been launched successfully, use the following line command t
API_BASE_PATH="http://127.0.0.1:8080" node .
```

### Output


### Output
This sample generates the following text output:

```text
---------------------------------------------------------------------------
Document Overall Status: 0
Document Number Visual: OO0000000
Document Number MRZ: OO0000000
Validity Of Document Number Visual: 0
Validity Of Document Number MRZ: 0
MRZ-Visual values comparison: 1
---------------------------------------------------------------------------
---------------------------------------------------------------
Document name: Germany - ePassport (2017) Service
---------------------------------------------------------------

[Surname]
- Source: VISUAL
Value : MUSTERMANN
---------------------------------------------------------------

[Surname And Given Names]
- Source: VISUAL
Value : MUSTERMANN ERIKA
---------------------------------------------------------------

[Document Status]
- Source: MRZ
Value : SPECIMEN
- Source: VISUAL
Value : SPECIMEN

...
```

Also, it stores [portrait](portrait.jpg) and [document image](document-image.jpg) images in the current folder.
You can modify [this example](/index.js)
You can modify [this example](./index.js)
and re-run it to get your own results.
89 changes: 0 additions & 89 deletions examples/basic/encrypted-rcl-example.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/basic/encrypted-rcl.txt

This file was deleted.

27 changes: 14 additions & 13 deletions examples/basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions generator-templates/modelIndex.mustache

This file was deleted.

15 changes: 15 additions & 0 deletions generator-templates/modelOneOf.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @type {{classname}}{{#description}}
* {{{.}}}{{/description}}
* @export
*/
export type {{classname}} = {{#discriminator}}{{!

discriminator with mapped models - TypeScript discriminating union
}}{{#mappedModels}}{ {{discriminator.propertyName}}: {{mappingName}} } & {{modelName}}{{^-last}} | {{/-last}}{{/mappedModels}}{{!

discriminator only - fallback to not use the discriminator. Default model names are available but possibility of having null/nullable values could introduce more edge cases
}}{{^mappedModels}}{{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}}{{/mappedModels}}{{/discriminator}}{{!

plain oneOf
}}{{^discriminator}}{{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}}{{/discriminator}};
Loading