0.4.1 • Published 3 years ago

@kevinki.ng/contractualize v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Contractualize

Write your API models in Joi. Automatically generate OAS 3.0, TypeScript, Java, and Postman.

oclif Version Downloads/week License

Usage

$ npm install --save-dev @kevinki.ng/contractualize
$ con --version
@kevinki.ng/contractualize/0.0.0 darwin-x64 node-v14.17.0
$ con --help
Write your API models in Joi. Automatically generate OAS 3.0, TypeScript, Java, and Postman.

USAGE
  $ con

OPTIONS
  -h, --help           Show CLI help
  -i, --input=input    Path to directory with Joi schemas
  -o, --output=output  Directory to store output
  -p, --postman        Compiles Postman scripts from OAS spec to directory specified by output
  -t, --ts             Compiles Typescript Interfaces from OAS spec to directory specified by output
  -v, --version        Show CLI version
  -w, --warn           Enable warnings

Example

Contractualize is currently highly opinionated about the directory structure. This is more of a time & effort limitation than a technical one. If the library gains any traction, this could be reworked. Presently, your structure must look like this:

$ tree ./example
./example
├── schema                              // can be hierarchical
│   ├── common
│   │   ├── Engine.js
│   │   └── Wheel.js
│   ├── service1
│   │   ├── RequestCar.js
│   │   ├── RequestTruck.js
│   │   ├── ResponseCar.js
│   │   └── ResponseTruck.js
│   └── service2
│       ├── RequestAircraft.js
│       ├── RequestHelicopter.js
│       ├── ResponseAircraft.js
│       └── ResponseHelicopter.js
├── postman                             // must be flat -- allows things like Pre-request Scripts in Postman
│   └── service1.js                     // must have same name as root-level service1.js
├── swagger                             // other arbitrary directories are allowed, but are incompatible with --joi flag
│   └── CommonHeaderParams.js           // raw OAS 3.0 for use in root-level service1.js, for example
├── service1.js                         // OAS 3.0 specs are flat and at the root
└── service2.js

6 directories, 14 files
$ con --input ./example --output ./autogen --ts --postman --java
---------------
 Compiling Joi 
---------------
---------------
 Compiling OAS 
---------------
--------------
 Compiling TS 
--------------
✨   try to get swagger by path "/Users/kking/code/contractualize/examples/autogen/service1.oas.json"
✨   try to get swagger by path "/Users/kking/code/contractualize/examples/autogen/service2.oas.json"
-------------------
 Compiling Postman 
-------------------
----------------
 Extend Postman 
----------------
✨   try to read templates from directory "/Users/kking/code/contractualize/node_modules/swagger-typescript-api/templates/default"
☄️    start generating your typescript api
✨   try to read templates from directory "/Users/kking/code/contractualize/node_modules/swagger-typescript-api/templates/default"
☄️    start generating your typescript api
$ tree ./autogen
./autogen
├── java
│   ├── service1.src.main.java.io.swagger.client.model
│   │   ├── Engine.java
│   │   ├── RequestCar.java
│   │   ├── RequestCarParts.java
│   │   ├── RequestTruck.java
│   │   ├── RequestTruckParts.java
│   │   ├── ResponseCar.java
│   │   ├── ResponseTruck.java
│   │   └── Wheel.java
│   └── service2.src.main.java.io.swagger.client.model
│       ├── Engine.java
│       ├── RequestAircraft.java
│       ├── RequestAircraftParts.java
│       ├── RequestHelicopter.java
│       ├── RequestHelicopterParts.java
│       ├── ResponseAircraft.java
│       ├── ResponseHelicopter.java
│       └── Wheel.java
│── typescript
│   ├── service1.ts
│   └── service2.ts
├── schema
│   ├── common
│   │   ├── Engine.js
│   │   ├── Engine.oas.json
│   │   ├── Wheel.js
│   │   └── Wheel.oas.json
│   ├── service1
│   │   ├── RequestCar.js
│   │   ├── RequestCar.oas.json
│   │   ├── RequestTruck.js
│   │   ├── RequestTruck.oas.json
│   │   ├── ResponseCar.js
│   │   ├── ResponseCar.oas.json
│   │   ├── ResponseTruck.js
│   │   └── ResponseTruck.oas.json
│   └── service2
│       ├── RequestAircraft.js
│       ├── RequestAircraft.oas.json
│       ├── RequestHelicopter.js
│       ├── RequestHelicopter.oas.json
│       ├── ResponseAircraft.js
│       ├── ResponseAircraft.oas.json
│       ├── ResponseHelicopter.js
│       └── ResponseHelicopter.oas.json
├── service1.oas.json
├── service1.postman.json
├── service2.oas.json
└── service2.postman.json

22 directories, 42 files
0.3.0

3 years ago

0.4.1

3 years ago

0.3.2

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago