Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(openapi)!: convert bundling library to openapi-cli #50

Merged
merged 7 commits into from
Feb 10, 2021
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ Install the snippet library

Install the reference resolving library
```bash
npm install swagger-cli --save-dev
npm install @redocly/openapi-cli --save-dev
```

Modify swagger file to reference `api-snippets`.

ex.
```yaml
Money:
$ref: /path/to/node_modules/@mojaloop/api-snippets/v1.0/openapi3/schemas/Money.yaml
$ref: /path/to/node_modules/@mojaloop/api-snippets/fspiop/v1_1/openapi3/components/schemas/Money.yaml
Copy link
Contributor

@eoln eoln Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kleyow we need to think about short paths -> maybe we can create symlinks in postinstall npm script? If we are introducing braking change this little improvement could be very handy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will make a ticket to investigate this.

```

Render and resolve the references.
```bash
swagger-cli bundle -t yaml -o api_render.yaml api.yaml
openapi bundle --output openapi.yaml --ext yaml openapi_template.yaml
```

Validate the result file.
Expand All @@ -45,26 +45,23 @@ to build the page found at https://docs.mojaloop.io/api-snippets/

## Dev Tools

To create snippets the tool found at https://www.npmjs.com/package/evrythng-openapi-tools
To create snippets the tool found at https://redoc.ly/docs/cli/#installation-and-usage
was used to break up large specification files. Some manual edits to the paths
are needed to format the files.

TODO: Add more detailed instructions for this workflow.
- `npm i -g evrythng-openapi-tools`
- `evrythng-openapi-tools split /path/to/my-large-specifcation-file.yaml /path/to/output-directory/`
- `npm install -g @redocly/openapi-cli`
- `openapi split fspiop-rest-v1.1-openapi3-snippets.yaml --outDir ./fspiop/v1_1`

## Questions

1) Are paths in the Mojaloop Specification considered "snippets"? Are they re-used widely across services?
2) Do we need to support both Swagger 2.0 and Open Api 3?
3) Does it make sense to have a common folder between versions for specification snippets that never change
to cut down on files?
1) Do we need to support both Swagger 2.0 and Open Api 3?

## DTO TypeScript definitions for snippets
> [Data Transfer Object](https://en.wikipedia.org/wiki/Data_transfer_object) description


The reason to have DTO is to allow separation between data transfer and data access phases.
The reason to have DTO is to allow separation between data transfer and data access phases.

From OpenAPI definition perspective `api-snippets` module allows building api.yaml definitions using a structured set of building blocks - `the snippets`.

Expand Down Expand Up @@ -98,7 +95,7 @@ interface ExampleTransferRequest {

The same structure is kept in TypesScript module, but with some handy shortcuts: there are no `openapi3/schemas` sub-folders/sub-modules

To use the types defined for `CorrelationId` and `Money` snippets
To use the types defined for `CorrelationId` and `Money` snippets
- `v1.0/openapi3/schemas/CorrelationId.yaml`
- `v1.0/openapi3/schemas/Money.yaml`

Expand Down Expand Up @@ -132,7 +129,7 @@ npm run build
It will generate OpenAPI specifications from snippets, then generate DTO from these snippets and finally generate javascript code

### Auto generation for micro services
When developing a micro service, to generate interfaces from your own OpenAPI specification custom types, please use
When developing a micro service, to generate interfaces from your own OpenAPI specification custom types, please use
```bash
npx openapi-typescript src/interface/api.yaml --output src/interface/openapi.ts
```
Expand Down Expand Up @@ -164,7 +161,7 @@ So later in you implementation code you can refer to interfaces via these aliase
```typescript
import { Schemas } from 'src/interface/api.ts'

let request: Schemas.MyCustomRequest = { ... }
let request: Schemas.MyCustomRequest = { ... }
```

### DTO usage examples
Expand All @@ -180,4 +177,4 @@ the `npm run build:dto` script is already executing linting with auto-fixing

there is pre-commit hook setup witch do a linting for staged files.
### DTO testing
- testing of DTO declarations
- testing of DTO declarations
Loading