├── .eslintignore ├── dist ├── types.js.map ├── types.js ├── requests │ ├── requests.models.js │ ├── requests.models.js.map │ ├── process-responses.js.map │ ├── process-params.js.map │ ├── process-paths.js.map │ └── process-params.js ├── index.js.map ├── common │ ├── generate.js.map │ ├── templates │ │ ├── formArrayExtended.ts │ │ ├── formMap.ts │ │ └── utils.ts │ └── generate.js ├── forms │ ├── shared-module.js.map │ ├── shared-module.js │ ├── process-module.js.map │ ├── generate-form-modules.js.map │ ├── states │ │ ├── generate-http-reducers.js.map │ │ └── generate-http-effects.js.map │ └── process-module.js ├── index.js ├── conf.js.map ├── conf.js └── generate.js.map ├── src ├── typings.d.ts ├── common │ ├── generate.ts │ └── templates │ │ ├── formArrayExtended.ts │ │ ├── formMap.ts │ │ └── utils.ts ├── forms │ ├── shared-module.ts │ └── process-module.ts ├── index.ts ├── requests │ ├── requests.models.ts │ ├── process-params.ts │ └── process-responses.ts ├── conf.ts ├── types.ts └── utils.spec.ts ├── demo ├── test-generate.ts └── generated │ ├── defs │ ├── RefStatus.ts │ ├── MapObject.ts │ ├── ArrayOfStrings.ts │ ├── ArrayGeneratedInlineModel.ts │ ├── OrderDto.ts │ ├── LoginDto.ts │ ├── ArrayOfObjects.ts │ ├── MapStructure.ts │ ├── Products.ts │ ├── SelfRefObject.ts │ ├── ProductDetail.ts │ ├── TicketDetailOutput.ts │ ├── GetGoodsListGeneratedInlineModel.ts │ ├── UserDetails.ts │ ├── MapContent.ts │ ├── ArrayStructure.ts │ └── Goods.ts │ ├── store │ ├── forms-shared.module.ts │ ├── order │ │ ├── deleteORDER │ │ │ ├── deleteORDER.service.ts │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── deleteORDER.module.ts │ │ ├── patchOrder │ │ │ ├── patchOrder.service.ts │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── patchOrder.module.ts │ │ ├── order │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ ├── order.module.ts │ │ │ └── order.service.ts │ │ └── putOrder │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ ├── putOrder.module.ts │ │ │ └── putOrder.service.ts │ ├── logout │ │ └── logout │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── logout.module.ts │ ├── product-detail │ │ └── productDetail │ │ │ ├── productDetail.service.ts │ │ │ ├── productDetail.module.ts │ │ │ └── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ ├── career │ │ └── positions │ │ │ ├── positions.service.ts │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── positions.module.ts │ ├── goods │ │ └── getGoodsList │ │ │ ├── getGoodsList.service.ts │ │ │ ├── getGoodsList.module.ts │ │ │ └── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ ├── login │ │ └── login │ │ │ ├── login.service.ts │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── login.module.ts │ ├── rest-auth │ │ ├── restAuthLogoutList │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── restAuthLogoutList.module.ts │ │ ├── restAuthLogoutCreate │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── restAuthLogoutCreate.module.ts │ │ ├── restAuthUserRead │ │ │ ├── restAuthUserRead.module.ts │ │ │ └── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ ├── restAuthUserUpdate │ │ │ ├── restAuthUserUpdate.module.ts │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── restAuthUserUpdate.service.ts │ │ └── restAuthUserPartialUpdate │ │ │ ├── restAuthUserPartialUpdate.module.ts │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── restAuthUserPartialUpdate.service.ts │ ├── structures │ │ ├── map │ │ │ ├── map.module.ts │ │ │ ├── states │ │ │ │ ├── actions.ts │ │ │ │ ├── effects.ts │ │ │ │ └── reducers.ts │ │ │ └── map.service.ts │ │ └── array │ │ │ ├── array.module.ts │ │ │ └── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ ├── params │ │ └── dashed │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── dashed.module.ts │ ├── ticketing │ │ └── showTicketDetail │ │ │ ├── showTicketDetail.service.ts │ │ │ ├── showTicketDetail.module.ts │ │ │ └── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ ├── products │ │ └── products │ │ │ ├── products.module.ts │ │ │ ├── states │ │ │ ├── actions.ts │ │ │ ├── effects.ts │ │ │ └── reducers.ts │ │ │ └── products.service.ts │ └── registration │ │ └── registration │ │ ├── states │ │ ├── actions.ts │ │ ├── effects.ts │ │ └── reducers.ts │ │ ├── registration.module.ts │ │ └── registration.service.ts │ ├── controllers │ ├── Logout.ts │ ├── Career.ts │ ├── Login.ts │ ├── ProductDetail.ts │ ├── Registration.ts │ ├── Goods.ts │ ├── Ticketing.ts │ ├── Structures.ts │ └── Products.ts │ ├── common │ ├── formArrayExtended.ts │ ├── formMap.ts │ └── utils.ts │ └── model.ts ├── .editorconfig ├── tests ├── polyfills.ts ├── tsconfig.spec.json ├── get │ ├── goods.service.spec.ts │ ├── career.service.spec.ts │ ├── product-detail.service.spec.ts │ └── products.service.spec.ts ├── post │ ├── logout.service.spec.ts │ ├── login.service.spec.ts │ ├── regitration.service.spec.ts │ └── order.service.spec.ts ├── patch │ └── patch-order.service.spec.ts ├── common.ts ├── put │ └── put-order.service.spec.ts └── delete │ └── delete-order.service.spec.ts ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── tsconfig.json ├── .eslintrc.js ├── angular.json └── LICENSE /.eslintignore: -------------------------------------------------------------------------------- 1 | /dist 2 | /generated 3 | -------------------------------------------------------------------------------- /dist/types.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /dist/types.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=types.js.map -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // enable json imports 2 | declare module '*.json' { 3 | const value: any; 4 | export default value; 5 | } 6 | -------------------------------------------------------------------------------- /demo/test-generate.ts: -------------------------------------------------------------------------------- 1 | import {generate} from '../src/generate'; 2 | 3 | generate('swagger-files/unit-test-swagger.json', 'generated', true, true, '/swagger'); 4 | -------------------------------------------------------------------------------- /dist/requests/requests.models.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=requests.models.js.map -------------------------------------------------------------------------------- /dist/requests/requests.models.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"requests.models.js","sourceRoot":"","sources":["../../src/requests/requests.models.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /demo/generated/defs/RefStatus.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export type RefStatus = number; 9 | -------------------------------------------------------------------------------- /demo/generated/defs/MapObject.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface MapObject { 9 | [key: string]: number; 10 | } 11 | -------------------------------------------------------------------------------- /demo/generated/defs/ArrayOfStrings.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | /** Array of strings */ 9 | export type ArrayOfStrings = string[]; 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*.ts] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /demo/generated/defs/ArrayGeneratedInlineModel.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface ArrayGeneratedInlineModel { 9 | status: number; 10 | } 11 | -------------------------------------------------------------------------------- /demo/generated/defs/OrderDto.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface OrderDto { 9 | /** format: int32 */ 10 | id: number; 11 | name?: string; 12 | } 13 | -------------------------------------------------------------------------------- /demo/generated/defs/LoginDto.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface LoginDto { 9 | /** format: email */ 10 | email: string; 11 | password: string; 12 | } 13 | -------------------------------------------------------------------------------- /tests/polyfills.ts: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | * Zone JS is required by Angular itself. 3 | */ 4 | import 'zone.js/dist/zone'; // Included with Angular CLI. 5 | 6 | (window as any).global = window; 7 | -------------------------------------------------------------------------------- /demo/generated/defs/ArrayOfObjects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | /** Array of objects */ 11 | export type ArrayOfObjects = __model.OrderDto[]; 12 | -------------------------------------------------------------------------------- /demo/generated/defs/MapStructure.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | export interface MapStructure { 11 | [key: string]: __model.MapContent; 12 | } 13 | -------------------------------------------------------------------------------- /demo/generated/defs/Products.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface Products { 9 | /** format: int32 */ 10 | partnerId?: number; 11 | /** format: string */ 12 | name?: number; 13 | /** format: int32 */ 14 | offset?: number; 15 | } 16 | -------------------------------------------------------------------------------- /demo/generated/defs/SelfRefObject.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | export interface SelfRefObject { 11 | prop1?: string; 12 | parent?: __model.SelfRefObject; 13 | children?: __model.SelfRefObject[]; 14 | } 15 | -------------------------------------------------------------------------------- /demo/generated/defs/ProductDetail.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface ProductDetail { 9 | /** format: int32 */ 10 | partnerId?: number; 11 | /** format: string */ 12 | name?: number; 13 | /** format: int32 */ 14 | offset?: number; 15 | } 16 | -------------------------------------------------------------------------------- /demo/generated/defs/TicketDetailOutput.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface TicketDetailOutput { 9 | status: string; 10 | /** format: date-time */ 11 | created_date: string; 12 | created_by_user: boolean; 13 | issue__origin: string; 14 | } 15 | -------------------------------------------------------------------------------- /tests/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "polyfills.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /demo/generated/defs/GetGoodsListGeneratedInlineModel.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | export interface GetGoodsListGeneratedInlineModel { 11 | count: number; 12 | /** format: uri */ 13 | next?: string; 14 | /** format: uri */ 15 | previous?: string; 16 | results: __model.Goods[]; 17 | } 18 | -------------------------------------------------------------------------------- /demo/generated/defs/UserDetails.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface UserDetails { 9 | readonly pk?: number; 10 | /** Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only. */ 11 | username: string; 12 | /** format: email */ 13 | readonly email?: string; 14 | first_name?: string; 15 | last_name?: string; 16 | } 17 | -------------------------------------------------------------------------------- /demo/generated/defs/MapContent.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | export interface MapContent { 11 | control?: number; 12 | group?: __model.OrderDto; 13 | arrayOfObjects?: __model.ArrayOfObjects; 14 | mapRef?: __model.MapObject; 15 | mapInlinePrimitive?: {[key: string]: number}; 16 | mapInlineRef?: {[key: string]: __model.OrderDto}; 17 | arrayOfMaps?: __model.MapObject[]; 18 | } 19 | -------------------------------------------------------------------------------- /demo/generated/store/forms-shared.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {CommonModule} from '@angular/common'; 9 | import {NgModule} from '@angular/core'; 10 | import {ReactiveFormsModule} from '@angular/forms'; 11 | 12 | @NgModule({ 13 | imports: [ 14 | CommonModule, 15 | ReactiveFormsModule, 16 | ], 17 | exports: [ 18 | CommonModule, 19 | ReactiveFormsModule, 20 | ], 21 | }) 22 | export class FormsSharedModule {} 23 | -------------------------------------------------------------------------------- /demo/generated/defs/ArrayStructure.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import * as __model from '../model'; 9 | 10 | /** Array testing structure */ 11 | export interface ArrayStructure { 12 | arrayObjectRef: __model.OrderDto[]; 13 | arrayStringInline: string[]; 14 | arrayArrayStringsRef: __model.ArrayOfStrings[]; 15 | arrayArrayObjectRef: __model.ArrayOfObjects[]; 16 | nestedArray: string[][]; 17 | nestedRefsArray: __model.ArrayOfObjects[][]; 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Run tests 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: [ master ] 7 | pull_request: 8 | branches: [ master ] 9 | 10 | jobs: 11 | test: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Use Node.js 18.0.0 17 | uses: actions/setup-node@v3 18 | with: 19 | node-version: 18 20 | - name: Install dependencies 21 | run: | 22 | npm ci 23 | - name: Run tests 24 | run: npm run test:ci 25 | -------------------------------------------------------------------------------- /demo/generated/controllers/Logout.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | @Injectable() 13 | export class LogoutService { 14 | constructor(private http: HttpClient) {} 15 | 16 | /** 17 | * Logout - empty post body 18 | * http://example.com/swagger/swagger-ui.html#!/Logout/Logout 19 | */ 20 | logout(): Observable { 21 | return this.http.post(`/api-base-path/logout`, {}); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demo/generated/defs/Goods.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export interface Goods { 9 | readonly id?: number; 10 | name?: string; 11 | /** format: uri */ 12 | photo_url?: string; 13 | description?: string; 14 | /** format: decimal */ 15 | price: string; 16 | currency: CurrencyGoodsEnum; 17 | status?: StatusGoodsEnum; 18 | refStatus?: RefStatusGoodsEnum; 19 | } 20 | 21 | export type CurrencyGoodsEnum = 22 | 'CZK'; 23 | 24 | export type StatusGoodsEnum = 25 | 1 | 26 | 2 | 27 | 3; 28 | 29 | export type RefStatusGoodsEnum = 30 | 1 | 31 | 2 | 32 | 3; 33 | -------------------------------------------------------------------------------- /src/common/generate.ts: -------------------------------------------------------------------------------- 1 | import {readFileSync} from 'fs'; 2 | import {basename, join} from 'path'; 3 | 4 | import {writeFile} from '../utils'; 5 | 6 | export function addUtils(dest: string) { 7 | writeTemplate(join(dest, `utils.ts`)); 8 | } 9 | 10 | export function addFormExtensions(dest: string) { 11 | writeTemplate(join(dest, `formArrayExtended.ts`)); 12 | writeTemplate(join(dest, `formMap.ts`)); 13 | } 14 | 15 | export function writeTemplate(dst: string) { 16 | const srcFileName = join(__dirname, 'templates', basename(dst)); 17 | const dstFileName = join(dst); 18 | const content = readFileSync(srcFileName).toString(); 19 | writeFile(dstFileName, content, undefined, 'ts', []); 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Directory for instrumented libs generated by jscoverage/JSCover 7 | lib-cov 8 | 9 | # Coverage directory used by tools like istanbul 10 | coverage 11 | 12 | # nyc test coverage 13 | .nyc_output 14 | 15 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 16 | .grunt 17 | 18 | # Dependency directories 19 | node_modules/ 20 | 21 | # Optional eslint cache 22 | .eslintcache 23 | 24 | # macos 25 | .DS_Store 26 | 27 | # dotenv environment variables file 28 | .env 29 | 30 | # IDE project profiles 31 | .vscode/ 32 | .idea/ 33 | 34 | # testing input/output 35 | conf/ 36 | src/api/ 37 | 38 | # build dir 39 | dist/ 40 | 41 | # angular cache from demo 42 | .angular 43 | -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,yCAAkC;AAClC,+BAA+B;AAC/B,yCAAoC;AAEpC,mBAAO;KACJ,MAAM,CAAC,oBAAoB,EAAE,8BAA8B,IAAI,CAAC,OAAO,EAAE,CAAC;KAC1E,MAAM,CAAC,0BAA0B,EAAE,mCAAmC,IAAI,CAAC,MAAM,EAAE,CAAC;KACpF,MAAM,CAAC,YAAY,EAAE,uBAAuB,CAAC;KAC7C,MAAM,CAAC,mCAAmC,EACzC,oGAAoG,CAAC;IACvG,8CAA8C;KAC7C,MAAM,CAAC,+BAA+B,EAAE,+EAA+E,IAAI,CAAC,cAAc,uDAAuD,IAAI,CAAC,cAAc,EAAE,CAAC;KACvN,MAAM,CAAC,oBAAoB,EAAE,gCAAgC,IAAI,CAAC,WAAW,EAAE,CAAC;KAChF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,mBAAO,CAAC,KAAK,EAAE,CAAC;AAChB,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,EAAE,CAAC;AAE/B,IAAA,mBAAQ,EAAC,OAAO,CAAC,GAAG,EAClB,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,wBAAwB,EAChC,OAAO,CAAC,cAAc,EACtB,OAAO,CAAC,WAAW,CAAC,CAAC"} -------------------------------------------------------------------------------- /tests/get/goods.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | import {GoodsService} from '../../demo/generated/controllers/Goods'; 3 | import {initHttpBed} from '../common'; 4 | 5 | describe(`GoodsService`, () => { 6 | let service: GoodsService; 7 | let backend: HttpTestingController; 8 | 9 | beforeEach(() => { 10 | ({service, backend} = initHttpBed(GoodsService)); 11 | }); 12 | 13 | afterEach(() => { 14 | backend.verify(); 15 | }); 16 | 17 | it(`should check request parameters are correct`, () => { 18 | service.getGoodsList({}).subscribe(); 19 | const req = backend.expectOne('/api-base-path/goods/get-goods-list/').request; 20 | expect(req.method).toBe('GET'); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /dist/common/generate.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/common/generate.ts"],"names":[],"mappings":";;;AAAA,2BAAgC;AAChC,+BAAoC;AAEpC,oCAAmC;AAEnC,SAAgB,QAAQ,CAAC,IAAY;IACnC,aAAa,CAAC,IAAA,WAAI,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;AACxC,CAAC;AAFD,4BAEC;AAED,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,aAAa,CAAC,IAAA,WAAI,EAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAClD,aAAa,CAAC,IAAA,WAAI,EAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC;AAC1C,CAAC;AAHD,8CAGC;AAED,SAAgB,aAAa,CAAC,GAAW;IACvC,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,EAAE,IAAA,eAAQ,EAAC,GAAG,CAAC,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,IAAA,iBAAY,EAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC;IACrD,IAAA,iBAAS,EAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC;AALD,sCAKC"} -------------------------------------------------------------------------------- /tests/post/logout.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | import {LogoutService} from '../../demo/generated/controllers/Logout'; 3 | import {initHttpBed} from '../common'; 4 | 5 | describe(`OrderService`, () => { 6 | let service: LogoutService; 7 | let backend: HttpTestingController; 8 | 9 | beforeEach(() => { 10 | ({service, backend} = initHttpBed(LogoutService)); 11 | }); 12 | 13 | afterEach(() => { 14 | backend.verify(); 15 | }); 16 | 17 | it(`should check request parameters are correct`, () => { 18 | service.logout().subscribe(); 19 | const req = backend.expectOne('/api-base-path/logout').request; 20 | expect(req.method).toBe('POST'); 21 | expect(req.body).toEqual({}); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /tests/get/career.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {CareerService} from '../../demo/generated/controllers/Career'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`CareerDetailService`, () => { 7 | let service: CareerService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(CareerService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | service.positions({version: '2', positionId: 220}).subscribe(); 20 | const req = backend.expectOne('/api-base-path/career/v2/positions/220').request; 21 | expect(req.method).toBe('GET'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /tests/get/product-detail.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | import {ProductDetailService} from '../../demo/generated/controllers/ProductDetail'; 3 | import {initHttpBed} from '../common'; 4 | 5 | describe(`ProductDetailService`, () => { 6 | let service: ProductDetailService; 7 | let backend: HttpTestingController; 8 | 9 | beforeEach(() => { 10 | ({service, backend} = initHttpBed(ProductDetailService)); 11 | }); 12 | 13 | afterEach(() => { 14 | backend.verify(); 15 | }); 16 | 17 | it(`should check request parameters are correct`, () => { 18 | service.productDetail({productId: 1}).subscribe(); 19 | const req = backend.expectOne('/api-base-path/product-detail/1').request; 20 | expect(req.method).toBe('GET'); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /demo/generated/store/order/deleteORDER/deleteORDER.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {OrderService} from '../../../controllers/Order'; 11 | 12 | @Injectable() 13 | export class DeleteORDERFormService { 14 | form: FormGroup; 15 | constructor( 16 | private orderService: OrderService, 17 | ) { 18 | this.form = new FormGroup({ 19 | orderId: new FormControl(undefined, [Validators.required]), 20 | }); 21 | } 22 | 23 | submit(raw = false) { 24 | const data = raw ? 25 | this.form.getRawValue() : 26 | this.form.value; 27 | return this.orderService.deleteORDER(data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/patch/patch-order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {OrderService} from '../../demo/generated/controllers/Order'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`Order patch`, () => { 7 | let service: OrderService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(OrderService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | service.patchOrder({orderId: '100', model: 'test-model'}).subscribe(); 20 | 21 | const req = backend.expectOne('/api-base-path/order/100').request; 22 | expect(req.method).toBe('PATCH'); 23 | expect(JSON.parse(JSON.stringify(req.body))) 24 | .toEqual({model: 'test-model'}); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "moduleResolution": "node", 8 | "noImplicitAny": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": true, 11 | "lib": [ 12 | "dom", 13 | "es2022" 14 | ], 15 | "module": "commonjs", 16 | "sourceMap": true, 17 | "target": "ES2022" 18 | }, 19 | "include": [ 20 | "src/**/*.ts" 21 | ], 22 | "exclude": [ 23 | "dist/**/*.ts", 24 | "generated/**/*.ts", 25 | "src/api/**/*.ts", 26 | "src/**/*.spec.ts", 27 | "src/**/templates/*.ts" 28 | ], 29 | "angularCompilerOptions": { 30 | "enableI18nLegacyMessageIdFormat": false, 31 | "strictInjectionParameters": true, 32 | "strictInputAccessModifiers": true, 33 | "strictTemplates": true 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo/generated/common/formArrayExtended.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormArray so it contains definition of items for further creation */ 5 | export class FormArrayExtended extends FormArray { 6 | constructor(public createControl: ControlFactory, controls: AbstractControl[], ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setSize(value.length); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets specified number of controls in the array 17 | * @param size of the array 18 | */ 19 | setSize(size: number) { 20 | while (size < this.controls.length) this.removeAt(0); 21 | while (size > this.controls.length) this.push(this.createControl()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demo/generated/store/logout/logout/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | 11 | export enum Actions { 12 | START = '[Logout logout] Start', 13 | SUCCESS = '[Logout logout] Success', 14 | ERROR = '[Logout logout] Error', 15 | } 16 | 17 | export class Start implements Action { 18 | readonly type = Actions.START; 19 | constructor() {} 20 | } 21 | 22 | export class Success implements Action { 23 | readonly type = Actions.SUCCESS; 24 | constructor(public payload: object) {} 25 | } 26 | 27 | export class Error implements Action { 28 | readonly type = Actions.ERROR; 29 | constructor(public payload: HttpErrorResponse) {} 30 | } 31 | 32 | export type LogoutAction = Start | Success | Error; 33 | -------------------------------------------------------------------------------- /dist/common/templates/formArrayExtended.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormArray so it contains definition of items for further creation */ 5 | export class FormArrayExtended extends FormArray { 6 | constructor(public createControl: ControlFactory, controls: AbstractControl[], ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setSize(value.length); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets specified number of controls in the array 17 | * @param size of the array 18 | */ 19 | setSize(size: number) { 20 | while (size < this.controls.length) this.removeAt(0); 21 | while (size > this.controls.length) this.push(this.createControl()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/common/templates/formArrayExtended.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormArray so it contains definition of items for further creation */ 5 | export class FormArrayExtended extends FormArray { 6 | constructor(public createControl: ControlFactory, controls: AbstractControl[], ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: any[], options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setSize(value.length); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets specified number of controls in the array 17 | * @param size of the array 18 | */ 19 | setSize(size: number) { 20 | while (size < this.controls.length) this.removeAt(0); 21 | while (size > this.controls.length) this.push(this.createControl()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demo/generated/store/logout/logout/logout.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {LogoutService} from '../../../controllers/Logout'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | 15 | import {LogoutEffects} from './states/effects'; 16 | import {LogoutReducer} from './states/reducers'; 17 | import {selectorName} from './states/reducers'; 18 | 19 | @NgModule({ 20 | imports: [ 21 | FormsSharedModule, 22 | NgrxStoreModule.forFeature(selectorName, LogoutReducer), 23 | NgrxEffectsModule.forFeature([LogoutEffects]), 24 | ], 25 | providers: [ 26 | LogoutService, 27 | ], 28 | }) 29 | export class LogoutModule {} 30 | -------------------------------------------------------------------------------- /demo/generated/store/order/patchOrder/patchOrder.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {OrderService} from '../../../controllers/Order'; 11 | 12 | @Injectable() 13 | export class PatchOrderFormService { 14 | form: FormGroup; 15 | constructor( 16 | private orderService: OrderService, 17 | ) { 18 | this.form = new FormGroup({ 19 | orderId: new FormControl(undefined, [Validators.required]), 20 | producer: new FormControl(undefined, []), 21 | model: new FormControl(undefined, []), 22 | }); 23 | } 24 | 25 | submit(raw = false) { 26 | const data = raw ? 27 | this.form.getRawValue() : 28 | this.form.value; 29 | return this.orderService.patchOrder(data); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /demo/generated/store/product-detail/productDetail/productDetail.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {ProductDetailService} from '../../../controllers/ProductDetail'; 11 | 12 | @Injectable() 13 | export class ProductDetailFormService { 14 | form: FormGroup; 15 | constructor( 16 | private productDetailService: ProductDetailService, 17 | ) { 18 | this.form = new FormGroup({ 19 | productId: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 20 | }); 21 | } 22 | 23 | submit(raw = false) { 24 | const data = raw ? 25 | this.form.getRawValue() : 26 | this.form.value; 27 | return this.productDetailService.productDetail(data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/post/login.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {LoginService} from '../../demo/generated/controllers/Login'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`LoginService`, () => { 7 | let service: LoginService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(LoginService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | service.login({loginDto: {email: 'test@test.com', password: 'password'}}).subscribe(); 20 | 21 | const req = backend.expectOne('/api-base-path/login').request; 22 | expect(req.method).toBe('POST'); 23 | expect(req.body.loginDto.email).toBe('test@test.com'); 24 | expect(req.body.loginDto.password).toBe('password'); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /demo/generated/store/career/positions/positions.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {CareerService} from '../../../controllers/Career'; 11 | 12 | @Injectable() 13 | export class PositionsFormService { 14 | form: FormGroup; 15 | constructor( 16 | private careerService: CareerService, 17 | ) { 18 | this.form = new FormGroup({ 19 | positionId: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 20 | version: new FormControl(undefined, [Validators.required]), 21 | }); 22 | } 23 | 24 | submit(raw = false) { 25 | const data = raw ? 26 | this.form.getRawValue() : 27 | this.form.value; 28 | return this.careerService.positions(data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /demo/generated/store/goods/getGoodsList/getGoodsList.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {GoodsService} from '../../../controllers/Goods'; 11 | 12 | @Injectable() 13 | export class GetGoodsListFormService { 14 | form: FormGroup; 15 | constructor( 16 | private goodsService: GoodsService, 17 | ) { 18 | this.form = new FormGroup({ 19 | limit: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 20 | offset: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 21 | }); 22 | } 23 | 24 | submit(raw = false) { 25 | const data = raw ? 26 | this.form.getRawValue() : 27 | this.form.value; 28 | return this.goodsService.getGoodsList(data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/common.ts: -------------------------------------------------------------------------------- 1 | import {HttpClientModule} from '@angular/common/http'; 2 | import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; 3 | import {TestBed} from '@angular/core/testing'; 4 | 5 | interface HttpBed { 6 | service: T; 7 | backend: HttpTestingController; 8 | } 9 | 10 | type ClassInterface = new (...a: any[]) => T; 11 | 12 | /** 13 | * Prepares test bed for http service test 14 | * @param service to be tested 15 | * @param providers additional providers to be injected 16 | */ 17 | export function initHttpBed(service: ClassInterface, providers: Array> = []): HttpBed { 18 | TestBed.configureTestingModule({ 19 | imports: [ 20 | HttpClientModule, 21 | HttpClientTestingModule, 22 | ], 23 | providers: [service, ...providers], 24 | }); 25 | 26 | return { 27 | service: TestBed.inject(service), 28 | backend: TestBed.inject(HttpTestingController), 29 | }; 30 | } 31 | -------------------------------------------------------------------------------- /demo/generated/store/login/login/login.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {LoginService} from '../../../controllers/Login'; 11 | 12 | @Injectable() 13 | export class LoginFormService { 14 | form: FormGroup; 15 | constructor( 16 | private loginService: LoginService, 17 | ) { 18 | this.form = new FormGroup({ 19 | loginDto: new FormGroup({ 20 | email: new FormControl(undefined, [Validators.email, Validators.required]), 21 | password: new FormControl(undefined, [Validators.required]), 22 | }, [Validators.required]), 23 | }); 24 | } 25 | 26 | submit(raw = false) { 27 | const data = raw ? 28 | this.form.getRawValue() : 29 | this.form.value; 30 | return this.loginService.login(data); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutList/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | 11 | export enum Actions { 12 | START = '[RestAuth restAuthLogoutList] Start', 13 | SUCCESS = '[RestAuth restAuthLogoutList] Success', 14 | ERROR = '[RestAuth restAuthLogoutList] Error', 15 | } 16 | 17 | export class Start implements Action { 18 | readonly type = Actions.START; 19 | constructor() {} 20 | } 21 | 22 | export class Success implements Action { 23 | readonly type = Actions.SUCCESS; 24 | constructor(public payload: void) {} 25 | } 26 | 27 | export class Error implements Action { 28 | readonly type = Actions.ERROR; 29 | constructor(public payload: HttpErrorResponse) {} 30 | } 31 | 32 | export type RestAuthLogoutListAction = Start | Success | Error; 33 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": [ 7 | "plugin:@typescript-eslint/recommended", 8 | ], 9 | "overrides": [ 10 | ], 11 | "parser": "@typescript-eslint/parser", 12 | "parserOptions": { 13 | "ecmaVersion": "latest", 14 | "sourceType": "module" 15 | }, 16 | "plugins": [ 17 | "@typescript-eslint", 18 | ], 19 | "rules": { 20 | "@typescript-eslint/no-explicit-any": 0, 21 | "@typescript-eslint/no-unused-vars": 0, 22 | "@typescript-eslint/no-empty-function": 0, 23 | "prefer-const": 0, 24 | "no-async-promise-executor": 0, 25 | "@typescript-eslint/no-inferrable-types": 0, 26 | "@typescript-eslint/no-extra-semi": 0, 27 | "@typescript-eslint/ban-types": 0, 28 | "@typescript-eslint/prefer-as-const": 0, 29 | "@typescript-eslint/no-empty-interface": 0, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutCreate/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | 11 | export enum Actions { 12 | START = '[RestAuth restAuthLogoutCreate] Start', 13 | SUCCESS = '[RestAuth restAuthLogoutCreate] Success', 14 | ERROR = '[RestAuth restAuthLogoutCreate] Error', 15 | } 16 | 17 | export class Start implements Action { 18 | readonly type = Actions.START; 19 | constructor() {} 20 | } 21 | 22 | export class Success implements Action { 23 | readonly type = Actions.SUCCESS; 24 | constructor(public payload: void) {} 25 | } 26 | 27 | export class Error implements Action { 28 | readonly type = Actions.ERROR; 29 | constructor(public payload: HttpErrorResponse) {} 30 | } 31 | 32 | export type RestAuthLogoutCreateAction = Start | Success | Error; 33 | -------------------------------------------------------------------------------- /demo/generated/store/login/login/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {LoginParams} from '../../../../controllers/Login'; 11 | 12 | export enum Actions { 13 | START = '[Login login] Start', 14 | SUCCESS = '[Login login] Success', 15 | ERROR = '[Login login] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: LoginParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type LoginAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/order/order/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {OrderParams} from '../../../../controllers/Order'; 11 | 12 | export enum Actions { 13 | START = '[Order order] Start', 14 | SUCCESS = '[Order order] Success', 15 | ERROR = '[Order order] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: OrderParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type OrderAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/login/login/login.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {LoginService} from '../../../controllers/Login'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {LoginFormService} from './login.service'; 15 | 16 | import {LoginEffects} from './states/effects'; 17 | import {LoginReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, LoginReducer), 24 | NgrxEffectsModule.forFeature([LoginEffects]), 25 | ], 26 | providers: [ 27 | LoginService, 28 | LoginFormService, 29 | ], 30 | }) 31 | export class LoginModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/order/order/order.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {OrderService} from '../../../controllers/Order'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {OrderFormService} from './order.service'; 15 | 16 | import {OrderEffects} from './states/effects'; 17 | import {OrderReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, OrderReducer), 24 | NgrxEffectsModule.forFeature([OrderEffects]), 25 | ], 26 | providers: [ 27 | OrderService, 28 | OrderFormService, 29 | ], 30 | }) 31 | export class OrderModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/structures/map/map.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {StructuresService} from '../../../controllers/Structures'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {MapFormService} from './map.service'; 15 | 16 | import {MapEffects} from './states/effects'; 17 | import {MapReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, MapReducer), 24 | NgrxEffectsModule.forFeature([MapEffects]), 25 | ], 26 | providers: [ 27 | StructuresService, 28 | MapFormService, 29 | ], 30 | }) 31 | export class MapModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/params/dashed/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {DashedParams} from '../../../../controllers/Params'; 11 | 12 | export enum Actions { 13 | START = '[Params dashed] Start', 14 | SUCCESS = '[Params dashed] Success', 15 | ERROR = '[Params dashed] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: DashedParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: void) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type DashedAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserRead/restAuthUserRead.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RestAuthService} from '../../../controllers/RestAuth'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | 15 | import {RestAuthUserReadEffects} from './states/effects'; 16 | import {RestAuthUserReadReducer} from './states/reducers'; 17 | import {selectorName} from './states/reducers'; 18 | 19 | @NgModule({ 20 | imports: [ 21 | FormsSharedModule, 22 | NgrxStoreModule.forFeature(selectorName, RestAuthUserReadReducer), 23 | NgrxEffectsModule.forFeature([RestAuthUserReadEffects]), 24 | ], 25 | providers: [ 26 | RestAuthService, 27 | ], 28 | }) 29 | export class RestAuthUserReadModule {} 30 | -------------------------------------------------------------------------------- /demo/generated/store/structures/map/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {MapParams} from '../../../../controllers/Structures'; 11 | 12 | export enum Actions { 13 | START = '[Structures map] Start', 14 | SUCCESS = '[Structures map] Success', 15 | ERROR = '[Structures map] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: MapParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: void) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type MapAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/order/order/order.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {OrderService} from '../../../controllers/Order'; 11 | 12 | @Injectable() 13 | export class OrderFormService { 14 | form: FormGroup; 15 | constructor( 16 | private orderService: OrderService, 17 | ) { 18 | this.form = new FormGroup({ 19 | orderDto: new FormGroup({ 20 | id: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 21 | name: new FormControl(undefined, []), 22 | }, []), 23 | producer: new FormControl(undefined, []), 24 | }); 25 | } 26 | 27 | submit(raw = false) { 28 | const data = raw ? 29 | this.form.getRawValue() : 30 | this.form.value; 31 | return this.orderService.order(data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo/generated/controllers/Career.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | export interface PositionsParams { 13 | /** 14 | * Position Id 15 | * format: int32 16 | */ 17 | positionId: number; 18 | /** API version */ 19 | version: string; 20 | } 21 | 22 | @Injectable() 23 | export class CareerService { 24 | constructor(private http: HttpClient) {} 25 | 26 | /** 27 | * get career 28 | * http://example.com/swagger/swagger-ui.html#!/Career/Career 29 | */ 30 | positions(params: PositionsParams): Observable { 31 | const pathParams = { 32 | positionId: params.positionId, 33 | version: params.version, 34 | }; 35 | return this.http.get(`/api-base-path/career/v${pathParams.version}/positions/${pathParams.positionId}`); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/params/dashed/dashed.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {ParamsService} from '../../../controllers/Params'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {DashedFormService} from './dashed.service'; 15 | 16 | import {DashedEffects} from './states/effects'; 17 | import {DashedReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, DashedReducer), 24 | NgrxEffectsModule.forFeature([DashedEffects]), 25 | ], 26 | providers: [ 27 | ParamsService, 28 | DashedFormService, 29 | ], 30 | }) 31 | export class DashedModule {} 32 | -------------------------------------------------------------------------------- /dist/forms/shared-module.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"shared-module.js","sourceRoot":"","sources":["../../src/forms/shared-module.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,gCAAgC;AAEhC,oCAA2C;AAE3C,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO,IAAI,iDAAiD,CAAC;IAC7D,OAAO,IAAI,2CAA2C,CAAC;IACvD,OAAO,IAAI,uDAAuD,CAAC;IACnE,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,eAAe,CAAC;IAE3B,OAAO,IAAI,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAClC,OAAO,IAAI,IAAA,cAAM,EAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IACxC,OAAO,IAAI,IAAA,cAAM,EAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,IAAI,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,IAAI,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAClC,OAAO,IAAI,IAAA,cAAM,EAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;IACxC,OAAO,IAAI,IAAA,cAAM,EAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;IAC/C,OAAO,IAAI,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,IAAI,MAAM,CAAC;IAClB,OAAO,IAAI,qCAAqC,CAAC;IAEjD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IACvF,IAAA,iBAAS,EAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC;AAvBD,gDAuBC"} -------------------------------------------------------------------------------- /demo/generated/store/order/putOrder/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {PutOrderParams} from '../../../../controllers/Order'; 11 | 12 | export enum Actions { 13 | START = '[Order putOrder] Start', 14 | SUCCESS = '[Order putOrder] Success', 15 | ERROR = '[Order putOrder] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: PutOrderParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type PutOrderAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutList/restAuthLogoutList.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RestAuthService} from '../../../controllers/RestAuth'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | 15 | import {RestAuthLogoutListEffects} from './states/effects'; 16 | import {RestAuthLogoutListReducer} from './states/reducers'; 17 | import {selectorName} from './states/reducers'; 18 | 19 | @NgModule({ 20 | imports: [ 21 | FormsSharedModule, 22 | NgrxStoreModule.forFeature(selectorName, RestAuthLogoutListReducer), 23 | NgrxEffectsModule.forFeature([RestAuthLogoutListEffects]), 24 | ], 25 | providers: [ 26 | RestAuthService, 27 | ], 28 | }) 29 | export class RestAuthLogoutListModule {} 30 | -------------------------------------------------------------------------------- /demo/generated/store/structures/array/array.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {StructuresService} from '../../../controllers/Structures'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {ArrayFormService} from './array.service'; 15 | 16 | import {ArrayEffects} from './states/effects'; 17 | import {ArrayReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, ArrayReducer), 24 | NgrxEffectsModule.forFeature([ArrayEffects]), 25 | ], 26 | providers: [ 27 | StructuresService, 28 | ArrayFormService, 29 | ], 30 | }) 31 | export class ArrayModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/ticketing/showTicketDetail/showTicketDetail.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {TicketingService} from '../../../controllers/Ticketing'; 11 | 12 | @Injectable() 13 | export class ShowTicketDetailFormService { 14 | form: FormGroup; 15 | constructor( 16 | private ticketingService: TicketingService, 17 | ) { 18 | this.form = new FormGroup({ 19 | date_from: new FormControl(undefined, []), 20 | date_to: new FormControl(undefined, []), 21 | id: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 22 | }); 23 | } 24 | 25 | submit(raw = false) { 26 | const data = raw ? 27 | this.form.getRawValue() : 28 | this.form.value; 29 | return this.ticketingService.showTicketDetail(data); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /demo/generated/controllers/Login.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface LoginParams { 15 | /** login */ 16 | loginDto: __model.LoginDto; 17 | } 18 | 19 | @Injectable() 20 | export class LoginService { 21 | constructor(private http: HttpClient) {} 22 | 23 | /** 24 | * create registration credentials 25 | * http://example.com/swagger/swagger-ui.html#!/Login/Registration 26 | */ 27 | login(params: LoginParams): Observable { 28 | const formDataParams = { 29 | loginDto: params.loginDto, 30 | }; 31 | return this.http.post(`/api-base-path/login`, formDataParams); 32 | } 33 | login_(loginDto: __model.LoginDto): Observable { 34 | return this.login({loginDto}); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/career/positions/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {PositionsParams} from '../../../../controllers/Career'; 11 | 12 | export enum Actions { 13 | START = '[Career positions] Start', 14 | SUCCESS = '[Career positions] Success', 15 | ERROR = '[Career positions] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: PositionsParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type PositionsAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/order/patchOrder/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {PatchOrderParams} from '../../../../controllers/Order'; 11 | 12 | export enum Actions { 13 | START = '[Order patchOrder] Start', 14 | SUCCESS = '[Order patchOrder] Success', 15 | ERROR = '[Order patchOrder] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: PatchOrderParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type PatchOrderAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/order/putOrder/putOrder.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {OrderService} from '../../../controllers/Order'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {PutOrderFormService} from './putOrder.service'; 15 | 16 | import {PutOrderEffects} from './states/effects'; 17 | import {PutOrderReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, PutOrderReducer), 24 | NgrxEffectsModule.forFeature([PutOrderEffects]), 25 | ], 26 | providers: [ 27 | OrderService, 28 | PutOrderFormService, 29 | ], 30 | }) 31 | export class PutOrderModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutCreate/restAuthLogoutCreate.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RestAuthService} from '../../../controllers/RestAuth'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | 15 | import {RestAuthLogoutCreateEffects} from './states/effects'; 16 | import {RestAuthLogoutCreateReducer} from './states/reducers'; 17 | import {selectorName} from './states/reducers'; 18 | 19 | @NgModule({ 20 | imports: [ 21 | FormsSharedModule, 22 | NgrxStoreModule.forFeature(selectorName, RestAuthLogoutCreateReducer), 23 | NgrxEffectsModule.forFeature([RestAuthLogoutCreateEffects]), 24 | ], 25 | providers: [ 26 | RestAuthService, 27 | ], 28 | }) 29 | export class RestAuthLogoutCreateModule {} 30 | -------------------------------------------------------------------------------- /demo/generated/store/order/deleteORDER/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {DeleteORDERParams} from '../../../../controllers/Order'; 11 | 12 | export enum Actions { 13 | START = '[Order deleteORDER] Start', 14 | SUCCESS = '[Order deleteORDER] Success', 15 | ERROR = '[Order deleteORDER] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: DeleteORDERParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type DeleteORDERAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/order/putOrder/putOrder.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {OrderService} from '../../../controllers/Order'; 11 | 12 | @Injectable() 13 | export class PutOrderFormService { 14 | form: FormGroup; 15 | constructor( 16 | private orderService: OrderService, 17 | ) { 18 | this.form = new FormGroup({ 19 | orderId: new FormControl(undefined, [Validators.required]), 20 | producer: new FormControl(undefined, [Validators.required]), 21 | model: new FormControl(undefined, [Validators.required]), 22 | customerName: new FormControl(undefined, [Validators.required]), 23 | }); 24 | } 25 | 26 | submit(raw = false) { 27 | const data = raw ? 28 | this.form.getRawValue() : 29 | this.form.value; 30 | return this.orderService.putOrder(data); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /demo/generated/store/products/products/products.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {ProductsService} from '../../../controllers/Products'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {ProductsFormService} from './products.service'; 15 | 16 | import {ProductsEffects} from './states/effects'; 17 | import {ProductsReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, ProductsReducer), 24 | NgrxEffectsModule.forFeature([ProductsEffects]), 25 | ], 26 | providers: [ 27 | ProductsService, 28 | ProductsFormService, 29 | ], 30 | }) 31 | export class ProductsModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserRead/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import * as __model from '../../../../model'; 11 | 12 | export enum Actions { 13 | START = '[RestAuth restAuthUserRead] Start', 14 | SUCCESS = '[RestAuth restAuthUserRead] Success', 15 | ERROR = '[RestAuth restAuthUserRead] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor() {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: __model.UserDetails) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type RestAuthUserReadAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/career/positions/positions.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {CareerService} from '../../../controllers/Career'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {PositionsFormService} from './positions.service'; 15 | 16 | import {PositionsEffects} from './states/effects'; 17 | import {PositionsReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, PositionsReducer), 24 | NgrxEffectsModule.forFeature([PositionsEffects]), 25 | ], 26 | providers: [ 27 | CareerService, 28 | PositionsFormService, 29 | ], 30 | }) 31 | export class PositionsModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/order/patchOrder/patchOrder.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {OrderService} from '../../../controllers/Order'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {PatchOrderFormService} from './patchOrder.service'; 15 | 16 | import {PatchOrderEffects} from './states/effects'; 17 | import {PatchOrderReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, PatchOrderReducer), 24 | NgrxEffectsModule.forFeature([PatchOrderEffects]), 25 | ], 26 | providers: [ 27 | OrderService, 28 | PatchOrderFormService, 29 | ], 30 | }) 31 | export class PatchOrderModule {} 32 | -------------------------------------------------------------------------------- /dist/common/generate.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.writeTemplate = exports.addFormExtensions = exports.addUtils = void 0; 4 | const fs_1 = require("fs"); 5 | const path_1 = require("path"); 6 | const utils_1 = require("../utils"); 7 | function addUtils(dest) { 8 | writeTemplate((0, path_1.join)(dest, `utils.ts`)); 9 | } 10 | exports.addUtils = addUtils; 11 | function addFormExtensions(dest) { 12 | writeTemplate((0, path_1.join)(dest, `formArrayExtended.ts`)); 13 | writeTemplate((0, path_1.join)(dest, `formMap.ts`)); 14 | } 15 | exports.addFormExtensions = addFormExtensions; 16 | function writeTemplate(dst) { 17 | const srcFileName = (0, path_1.join)(__dirname, 'templates', (0, path_1.basename)(dst)); 18 | const dstFileName = (0, path_1.join)(dst); 19 | const content = (0, fs_1.readFileSync)(srcFileName).toString(); 20 | (0, utils_1.writeFile)(dstFileName, content, undefined, 'ts', []); 21 | } 22 | exports.writeTemplate = writeTemplate; 23 | //# sourceMappingURL=generate.js.map -------------------------------------------------------------------------------- /demo/generated/store/order/deleteORDER/deleteORDER.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {OrderService} from '../../../controllers/Order'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {DeleteORDERFormService} from './deleteORDER.service'; 15 | 16 | import {DeleteORDEREffects} from './states/effects'; 17 | import {DeleteORDERReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, DeleteORDERReducer), 24 | NgrxEffectsModule.forFeature([DeleteORDEREffects]), 25 | ], 26 | providers: [ 27 | OrderService, 28 | DeleteORDERFormService, 29 | ], 30 | }) 31 | export class DeleteORDERModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/model.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | export * from './defs/Products'; // sources: products 9 | export * from './defs/ProductDetail'; // sources: productDetail 10 | export * from './defs/OrderDto'; // sources: orderDto 11 | export * from './defs/SelfRefObject'; // sources: selfRefObject 12 | export * from './defs/LoginDto'; // sources: loginDto 13 | export * from './defs/UserDetails'; 14 | export * from './defs/Goods'; 15 | export * from './defs/ArrayStructure'; // sources: arrayStructure 16 | export * from './defs/ArrayOfStrings'; 17 | export * from './defs/ArrayOfObjects'; 18 | export * from './defs/MapStructure'; // sources: mapStructure 19 | export * from './defs/MapContent'; // sources: mapContent 20 | export * from './defs/MapObject'; // sources: mapObject 21 | export * from './defs/TicketDetailOutput'; 22 | export * from './defs/RefStatus'; 23 | export * from './defs/GetGoodsListGeneratedInlineModel'; 24 | export * from './defs/ArrayGeneratedInlineModel'; 25 | -------------------------------------------------------------------------------- /demo/generated/store/goods/getGoodsList/getGoodsList.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {GoodsService} from '../../../controllers/Goods'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {GetGoodsListFormService} from './getGoodsList.service'; 15 | 16 | import {GetGoodsListEffects} from './states/effects'; 17 | import {GetGoodsListReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, GetGoodsListReducer), 24 | NgrxEffectsModule.forFeature([GetGoodsListEffects]), 25 | ], 26 | providers: [ 27 | GoodsService, 28 | GetGoodsListFormService, 29 | ], 30 | }) 31 | export class GetGoodsListModule {} 32 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "client": { 7 | "root": "", 8 | "sourceRoot": "tests", 9 | "projectType": "application", 10 | "architect": { 11 | "test": { 12 | "builder": "@angular-devkit/build-angular:karma", 13 | "options": { 14 | "polyfills": [ 15 | "zone.js", 16 | "zone.js/testing" 17 | ], 18 | "tsConfig": "tests/tsconfig.spec.json", 19 | "scripts": [], 20 | "styles": [], 21 | "assets": [ 22 | "tests/assets", 23 | "tests/favicon.ico" 24 | ] 25 | } 26 | } 27 | } 28 | } 29 | }, 30 | "schematics": { 31 | "@schematics/angular:component": { 32 | "prefix": "app" 33 | }, 34 | "@schematics/angular:directive": { 35 | "prefix": "app" 36 | } 37 | }, 38 | "cli": { 39 | "analytics": false 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demo/generated/store/registration/registration/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {RegistrationParams} from '../../../../controllers/Registration'; 11 | 12 | export enum Actions { 13 | START = '[Registration registration] Start', 14 | SUCCESS = '[Registration registration] Success', 15 | ERROR = '[Registration registration] Error', 16 | } 17 | 18 | export class Start implements Action { 19 | readonly type = Actions.START; 20 | constructor(public payload: RegistrationParams) {} 21 | } 22 | 23 | export class Success implements Action { 24 | readonly type = Actions.SUCCESS; 25 | constructor(public payload: object) {} 26 | } 27 | 28 | export class Error implements Action { 29 | readonly type = Actions.ERROR; 30 | constructor(public payload: HttpErrorResponse) {} 31 | } 32 | 33 | export type RegistrationAction = Start | Success | Error; 34 | -------------------------------------------------------------------------------- /demo/generated/store/logout/logout/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {LogoutService} from '../../../../controllers/Logout'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class LogoutEffects { 20 | Logout = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap(() => this.logoutService.logout() 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private logoutService: LogoutService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/products/products/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {ProductsParams} from '../../../../controllers/Products'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[Products products] Start', 15 | SUCCESS = '[Products products] Success', 16 | ERROR = '[Products products] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: ProductsParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.Products) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type ProductsAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/store/registration/registration/registration.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RegistrationService} from '../../../controllers/Registration'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {RegistrationFormService} from './registration.service'; 15 | 16 | import {RegistrationEffects} from './states/effects'; 17 | import {RegistrationReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, RegistrationReducer), 24 | NgrxEffectsModule.forFeature([RegistrationEffects]), 25 | ], 26 | providers: [ 27 | RegistrationService, 28 | RegistrationFormService, 29 | ], 30 | }) 31 | export class RegistrationModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/structures/array/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {ArrayParams} from '../../../../controllers/Structures'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[Structures array] Start', 15 | SUCCESS = '[Structures array] Success', 16 | ERROR = '[Structures array] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: ArrayParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.ArrayGeneratedInlineModel) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type ArrayAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/store/product-detail/productDetail/productDetail.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {ProductDetailService} from '../../../controllers/ProductDetail'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {ProductDetailFormService} from './productDetail.service'; 15 | 16 | import {ProductDetailEffects} from './states/effects'; 17 | import {ProductDetailReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, ProductDetailReducer), 24 | NgrxEffectsModule.forFeature([ProductDetailEffects]), 25 | ], 26 | providers: [ 27 | ProductDetailService, 28 | ProductDetailFormService, 29 | ], 30 | }) 31 | export class ProductDetailModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/login/login/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {LoginService} from '../../../../controllers/Login'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class LoginEffects { 20 | Login = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.loginService.login(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private loginService: LoginService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/order/order/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {OrderService} from '../../../../controllers/Order'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class OrderEffects { 20 | Order = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.orderService.order(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private orderService: OrderService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /tests/put/put-order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {OrderService, PutOrderParams} from '../../demo/generated/controllers/Order'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`Order put`, () => { 7 | let service: OrderService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(OrderService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | const params: PutOrderParams = { 20 | orderId: '100', 21 | producer: 'test-producer', 22 | model: 'test-model', 23 | customerName: 'Johnny Cash', 24 | }; 25 | service.putOrder(params).subscribe(); 26 | 27 | const req = backend.expectOne('/api-base-path/order/100').request; 28 | expect(req.method).toBe('PUT'); 29 | const bodyParams = {...params}; 30 | delete (bodyParams as Partial).orderId; 31 | expect(req.body).toEqual(bodyParams); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /demo/generated/store/ticketing/showTicketDetail/showTicketDetail.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {TicketingService} from '../../../controllers/Ticketing'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {ShowTicketDetailFormService} from './showTicketDetail.service'; 15 | 16 | import {ShowTicketDetailEffects} from './states/effects'; 17 | import {ShowTicketDetailReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, ShowTicketDetailReducer), 24 | NgrxEffectsModule.forFeature([ShowTicketDetailEffects]), 25 | ], 26 | providers: [ 27 | TicketingService, 28 | ShowTicketDetailFormService, 29 | ], 30 | }) 31 | export class ShowTicketDetailModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/goods/getGoodsList/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {GetGoodsListParams} from '../../../../controllers/Goods'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[Goods getGoodsList] Start', 15 | SUCCESS = '[Goods getGoodsList] Success', 16 | ERROR = '[Goods getGoodsList] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: GetGoodsListParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.GetGoodsListGeneratedInlineModel) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type GetGoodsListAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/store/order/putOrder/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {OrderService} from '../../../../controllers/Order'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class PutOrderEffects { 20 | PutOrder = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.orderService.putOrder(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private orderService: OrderService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/params/dashed/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {ParamsService} from '../../../../controllers/Params'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class DashedEffects { 20 | Dashed = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.paramsService.dashed(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private paramsService: ParamsService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /src/forms/shared-module.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import * as conf from '../conf'; 3 | import {Config} from '../generate'; 4 | import {indent, writeFile} from '../utils'; 5 | 6 | export function createSharedModule(config: Config) { 7 | let content = ''; 8 | content += `import {CommonModule} from '@angular/common';\n`; 9 | content += `import {NgModule} from '@angular/core';\n`; 10 | content += `import {ReactiveFormsModule} from '@angular/forms';\n`; 11 | content += '\n'; 12 | content += '@NgModule({\n'; 13 | 14 | content += indent('imports: [\n'); 15 | content += indent('CommonModule,\n', 2); 16 | content += indent('ReactiveFormsModule,\n', 2); 17 | content += indent('],\n'); 18 | 19 | content += indent('exports: [\n'); 20 | content += indent('CommonModule,\n', 2); 21 | content += indent('ReactiveFormsModule,\n', 2); 22 | content += indent('],\n'); 23 | 24 | content += '})\n'; 25 | content += `export class FormsSharedModule {}\n`; 26 | 27 | const moduleFileName = path.join(config.dest, conf.storeDir, `forms-shared.module.ts`); 28 | writeFile(moduleFileName, content, config.header); 29 | } 30 | -------------------------------------------------------------------------------- /demo/generated/store/career/positions/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {CareerService} from '../../../../controllers/Career'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class PositionsEffects { 20 | Positions = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.careerService.positions(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private careerService: CareerService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/order/patchOrder/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {OrderService} from '../../../../controllers/Order'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class PatchOrderEffects { 20 | PatchOrder = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.orderService.patchOrder(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private orderService: OrderService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserUpdate/restAuthUserUpdate.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RestAuthService} from '../../../controllers/RestAuth'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {RestAuthUserUpdateFormService} from './restAuthUserUpdate.service'; 15 | 16 | import {RestAuthUserUpdateEffects} from './states/effects'; 17 | import {RestAuthUserUpdateReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, RestAuthUserUpdateReducer), 24 | NgrxEffectsModule.forFeature([RestAuthUserUpdateEffects]), 25 | ], 26 | providers: [ 27 | RestAuthService, 28 | RestAuthUserUpdateFormService, 29 | ], 30 | }) 31 | export class RestAuthUserUpdateModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/structures/map/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {StructuresService} from '../../../../controllers/Structures'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class MapEffects { 20 | Map = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.structuresService.map(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private structuresService: StructuresService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jan Walter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /demo/generated/store/goods/getGoodsList/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {GoodsService} from '../../../../controllers/Goods'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class GetGoodsListEffects { 20 | GetGoodsList = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.goodsService.getGoodsList(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private goodsService: GoodsService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/order/deleteORDER/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {OrderService} from '../../../../controllers/Order'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class DeleteORDEREffects { 20 | DeleteORDER = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.orderService.deleteORDER(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private orderService: OrderService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserRead/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RestAuthService} from '../../../../controllers/RestAuth'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RestAuthUserReadEffects { 20 | RestAuthUserRead = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap(() => this.restauthService.restAuthUserRead() 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private restauthService: RestAuthService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/products/products/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {ProductsService} from '../../../../controllers/Products'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class ProductsEffects { 20 | Products = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.productsService.products(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private productsService: ProductsService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/structures/array/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {StructuresService} from '../../../../controllers/Structures'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class ArrayEffects { 20 | Array = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.structuresService.array(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private structuresService: StructuresService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutList/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RestAuthService} from '../../../../controllers/RestAuth'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RestAuthLogoutListEffects { 20 | RestAuthLogoutList = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap(() => this.restauthService.restAuthLogoutList() 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private restauthService: RestAuthService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/product-detail/productDetail/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {ProductDetailParams} from '../../../../controllers/ProductDetail'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[ProductDetail productDetail] Start', 15 | SUCCESS = '[ProductDetail productDetail] Success', 16 | ERROR = '[ProductDetail productDetail] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: ProductDetailParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.ProductDetail) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type ProductDetailAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutCreate/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RestAuthService} from '../../../../controllers/RestAuth'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RestAuthLogoutCreateEffects { 20 | RestAuthLogoutCreate = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap(() => this.restauthService.restAuthLogoutCreate() 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private restauthService: RestAuthService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/ticketing/showTicketDetail/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {ShowTicketDetailParams} from '../../../../controllers/Ticketing'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[Ticketing showTicketDetail] Start', 15 | SUCCESS = '[Ticketing showTicketDetail] Success', 16 | ERROR = '[Ticketing showTicketDetail] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: ShowTicketDetailParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.TicketDetailOutput[]) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type ShowTicketDetailAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/controllers/ProductDetail.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface ProductDetailParams { 15 | /** 16 | * product id 17 | * format: int32 18 | */ 19 | productId: number; 20 | } 21 | 22 | @Injectable() 23 | export class ProductDetailService { 24 | constructor(private http: HttpClient) {} 25 | 26 | /** 27 | * Get product detail 28 | * http://example.com/swagger/swagger-ui.html#!/ProductDetail/ProductDetail 29 | */ 30 | productDetail(params: ProductDetailParams): Observable<__model.ProductDetail> { 31 | const pathParams = { 32 | productId: params.productId, 33 | }; 34 | return this.http.get<__model.ProductDetail>(`/api-base-path/product-detail/${pathParams.productId}`); 35 | } 36 | productDetail_(productId: number): Observable<__model.ProductDetail> { 37 | return this.productDetail({productId}); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserUpdate/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {RestAuthUserUpdateParams} from '../../../../controllers/RestAuth'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[RestAuth restAuthUserUpdate] Start', 15 | SUCCESS = '[RestAuth restAuthUserUpdate] Success', 16 | ERROR = '[RestAuth restAuthUserUpdate] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: RestAuthUserUpdateParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.UserDetails) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type RestAuthUserUpdateAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import {program} from 'commander'; 3 | import * as conf from './conf'; 4 | import {generate} from './generate'; 5 | 6 | program 7 | .option('-s, --src ', `Source directory, default: ${conf.apiFile}`) 8 | .option('-d, --dest ', `Destination directory, default: ${conf.outDir}`) 9 | .option('--no-store', 'Do not generate store') 10 | .option('-w, --unwrap-single-param-methods', 11 | 'Controller methods with a single parameter get a method_() where the parameter object is unwrapped') 12 | /* tslint:disable-next-line:max-line-length */ 13 | .option('-u, --swagger-url-path ', `swagger URL path, where the swagger ui documentation can be found; default: ${conf.swaggerUrlPath}, i.e. the resulting address would be http://example${conf.swaggerUrlPath}`) 14 | .option('-o, --omit-version', `Write version info, default: ${conf.omitVersion}`) 15 | .parse(process.argv); 16 | 17 | program.parse(); 18 | const options = program.opts(); 19 | 20 | generate(options.src, 21 | options.dest, 22 | options.store, 23 | options.unwrapSingleParamMethods, 24 | options.swaggerUrlPath, 25 | options.omitVersion); 26 | -------------------------------------------------------------------------------- /tests/delete/delete-order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | import {OrderService} from '../../demo/generated/controllers/Order'; 3 | import {initHttpBed} from '../common'; 4 | 5 | describe(`Order delete`, () => { 6 | let service: OrderService; 7 | let backend: HttpTestingController; 8 | 9 | beforeEach(() => { 10 | ({service, backend} = initHttpBed(OrderService)); 11 | }); 12 | 13 | afterEach(() => { 14 | backend.verify(); 15 | }); 16 | 17 | it(`should check request parameters are correct`, () => { 18 | service.deleteORDER({orderId: '123e4567-e89b-12d3-a456-426655440000'}).subscribe(); 19 | 20 | const req = backend.expectOne('/api-base-path/order/123e4567-e89b-12d3-a456-426655440000').request; 21 | expect(req.method).toBe('DELETE'); 22 | }); 23 | 24 | it(`generate single parameter unwrapped method`, () => { 25 | service.deleteORDER_('123e4567-e89b-12d3-a456-426655440000').subscribe(); 26 | 27 | const req = backend.expectOne('/api-base-path/order/123e4567-e89b-12d3-a456-426655440000').request; 28 | expect(req.method).toBe('DELETE'); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /src/common/templates/formMap.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormGroup} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormGroup so it contains definition of map items for further creation */ 5 | export class FormMap extends FormGroup { 6 | constructor(public createControl: ControlFactory, controls: Record, ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: Record, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setShape(Object.keys(value)); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets child controls for a specified list of keys 17 | * @param keys list of keys new form group should contain 18 | */ 19 | setShape(keys: string[]) { 20 | const allKeys = new Set([...keys, ...Object.keys(this.controls)]); 21 | allKeys.forEach(key => { 22 | // add control for a new one 23 | if (!(key in this.controls)) this.addControl(key, this.createControl()); 24 | // remove control if missing 25 | else if (!keys.includes(key)) this.removeControl(key); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demo/generated/common/formMap.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormGroup} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormGroup so it contains definition of map items for further creation */ 5 | export class FormMap extends FormGroup { 6 | constructor(public createControl: ControlFactory, controls: Record, ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: Record, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setShape(Object.keys(value)); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets child controls for a specified list of keys 17 | * @param keys list of keys new form group should contain 18 | */ 19 | setShape(keys: string[]) { 20 | const allKeys = new Set([...keys, ...Object.keys(this.controls)]); 21 | allKeys.forEach(key => { 22 | // add control for a new one 23 | if (!(key in this.controls)) this.addControl(key, this.createControl()); 24 | // remove control if missing 25 | else if (!keys.includes(key)) this.removeControl(key); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demo/generated/store/ticketing/showTicketDetail/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {TicketingService} from '../../../../controllers/Ticketing'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class ShowTicketDetailEffects { 20 | ShowTicketDetail = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.ticketingService.showTicketDetail(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private ticketingService: TicketingService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /dist/common/templates/formMap.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormGroup} from '@angular/forms'; 2 | import {ControlFactory} from './utils'; 3 | 4 | /** Extends FormGroup so it contains definition of map items for further creation */ 5 | export class FormMap extends FormGroup { 6 | constructor(public createControl: ControlFactory, controls: Record, ...rest: any[]) { 7 | super(controls, ...rest); 8 | } 9 | 10 | override setValue(value: Record, options: {onlySelf?: boolean, emitEvent?: boolean} = {}): void { 11 | this.setShape(Object.keys(value)); 12 | super.setValue(value, options); 13 | } 14 | 15 | /** 16 | * Sets child controls for a specified list of keys 17 | * @param keys list of keys new form group should contain 18 | */ 19 | setShape(keys: string[]) { 20 | const allKeys = new Set([...keys, ...Object.keys(this.controls)]); 21 | allKeys.forEach(key => { 22 | // add control for a new one 23 | if (!(key in this.controls)) this.addControl(key, this.createControl()); 24 | // remove control if missing 25 | else if (!keys.includes(key)) this.removeControl(key); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /demo/generated/store/registration/registration/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RegistrationService} from '../../../../controllers/Registration'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RegistrationEffects { 20 | Registration = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.registrationService.registration(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private registrationService: RegistrationService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserUpdate/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RestAuthService} from '../../../../controllers/RestAuth'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RestAuthUserUpdateEffects { 20 | RestAuthUserUpdate = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.restauthService.restAuthUserUpdate(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private restauthService: RestAuthService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/product-detail/productDetail/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {ProductDetailService} from '../../../../controllers/ProductDetail'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class ProductDetailEffects { 20 | ProductDetail = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.productdetailService.productDetail(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private productdetailService: ProductDetailService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/structures/map/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface MapState { 14 | data: void | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialMapState: MapState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Structures_Map'; 26 | export const getMapStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function MapReducer( 29 | state: MapState = initialMapState, 30 | action: actions.MapAction): MapState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserPartialUpdate/restAuthUserPartialUpdate.module.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {NgModule} from '@angular/core'; 9 | import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects'; 10 | import {StoreModule as NgrxStoreModule} from '@ngrx/store'; 11 | 12 | import {RestAuthService} from '../../../controllers/RestAuth'; 13 | import {FormsSharedModule} from '../../forms-shared.module'; 14 | import {RestAuthUserPartialUpdateFormService} from './restAuthUserPartialUpdate.service'; 15 | 16 | import {RestAuthUserPartialUpdateEffects} from './states/effects'; 17 | import {RestAuthUserPartialUpdateReducer} from './states/reducers'; 18 | import {selectorName} from './states/reducers'; 19 | 20 | @NgModule({ 21 | imports: [ 22 | FormsSharedModule, 23 | NgrxStoreModule.forFeature(selectorName, RestAuthUserPartialUpdateReducer), 24 | NgrxEffectsModule.forFeature([RestAuthUserPartialUpdateEffects]), 25 | ], 26 | providers: [ 27 | RestAuthService, 28 | RestAuthUserPartialUpdateFormService, 29 | ], 30 | }) 31 | export class RestAuthUserPartialUpdateModule {} 32 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserPartialUpdate/states/actions.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length max-classes-per-file */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Action} from '@ngrx/store'; 10 | import {RestAuthUserPartialUpdateParams} from '../../../../controllers/RestAuth'; 11 | import * as __model from '../../../../model'; 12 | 13 | export enum Actions { 14 | START = '[RestAuth restAuthUserPartialUpdate] Start', 15 | SUCCESS = '[RestAuth restAuthUserPartialUpdate] Success', 16 | ERROR = '[RestAuth restAuthUserPartialUpdate] Error', 17 | } 18 | 19 | export class Start implements Action { 20 | readonly type = Actions.START; 21 | constructor(public payload: RestAuthUserPartialUpdateParams) {} 22 | } 23 | 24 | export class Success implements Action { 25 | readonly type = Actions.SUCCESS; 26 | constructor(public payload: __model.UserDetails) {} 27 | } 28 | 29 | export class Error implements Action { 30 | readonly type = Actions.ERROR; 31 | constructor(public payload: HttpErrorResponse) {} 32 | } 33 | 34 | export type RestAuthUserPartialUpdateAction = Start | Success | Error; 35 | -------------------------------------------------------------------------------- /demo/generated/store/login/login/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface LoginState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialLoginState: LoginState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Login_Login'; 26 | export const getLoginStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function LoginReducer( 29 | state: LoginState = initialLoginState, 30 | action: actions.LoginAction): LoginState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/order/order/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface OrderState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialOrderState: OrderState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Order_Order'; 26 | export const getOrderStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function OrderReducer( 29 | state: OrderState = initialOrderState, 30 | action: actions.OrderAction): OrderState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserPartialUpdate/states/effects.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpErrorResponse} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Actions, createEffect, ofType} from '@ngrx/effects'; 11 | 12 | import {of} from 'rxjs'; 13 | 14 | import {catchError, map, switchMap} from 'rxjs/operators'; 15 | import {RestAuthService} from '../../../../controllers/RestAuth'; 16 | import * as actions from './actions'; 17 | 18 | @Injectable() 19 | export class RestAuthUserPartialUpdateEffects { 20 | RestAuthUserPartialUpdate = createEffect(() => this.storeActions.pipe( 21 | ofType(actions.Actions.START), 22 | switchMap((action: actions.Start) => this.restauthService.restAuthUserPartialUpdate(action.payload) 23 | .pipe( 24 | map(result => new actions.Success(result)), 25 | catchError((error: HttpErrorResponse) => of(new actions.Error(error))), 26 | ), 27 | ), 28 | )); 29 | 30 | constructor( 31 | private storeActions: Actions, 32 | private restauthService: RestAuthService, 33 | ) {} 34 | } 35 | -------------------------------------------------------------------------------- /demo/generated/store/logout/logout/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface LogoutState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialLogoutState: LogoutState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Logout_Logout'; 26 | export const getLogoutStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function LogoutReducer( 29 | state: LogoutState = initialLogoutState, 30 | action: actions.LogoutAction): LogoutState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/params/dashed/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface DashedState { 14 | data: void | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialDashedState: DashedState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Params_Dashed'; 26 | export const getDashedStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function DashedReducer( 29 | state: DashedState = initialDashedState, 30 | action: actions.DashedAction): DashedState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/order/putOrder/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface PutOrderState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialPutOrderState: PutOrderState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Order_PutOrder'; 26 | export const getPutOrderStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function PutOrderReducer( 29 | state: PutOrderState = initialPutOrderState, 30 | action: actions.PutOrderAction): PutOrderState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/registration/registration/registration.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {RegistrationService} from '../../../controllers/Registration'; 11 | 12 | @Injectable() 13 | export class RegistrationFormService { 14 | form: FormGroup; 15 | constructor( 16 | private registrationService: RegistrationService, 17 | ) { 18 | this.form = new FormGroup({ 19 | email: new FormControl(undefined, [Validators.email, Validators.required]), 20 | password1: new FormControl(undefined, [Validators.required]), 21 | password2: new FormControl(undefined, [Validators.required]), 22 | selfRefParam: new FormGroup({ 23 | prop1: new FormControl(undefined, []), 24 | }, [Validators.required]), 25 | registrationType: new FormControl(undefined, [Validators.required]), 26 | }); 27 | } 28 | 29 | submit(raw = false) { 30 | const data = raw ? 31 | this.form.getRawValue() : 32 | this.form.value; 33 | return this.registrationService.registration(data); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/requests/requests.models.ts: -------------------------------------------------------------------------------- 1 | import {HttpResponse, Method, MethodName, Parameter} from '../types'; 2 | 3 | export interface Paths { 4 | [key: string]: { 5 | [key in MethodName]?: Method; 6 | }; 7 | } 8 | 9 | export type MethodOrParameters = 10 | {[key in MethodName]?: Method} & 11 | {parameters: Parameter[]}; 12 | 13 | export interface PathsWithParameters { 14 | [key: string]: MethodOrParameters; 15 | } 16 | 17 | export interface Dictionary { 18 | [index: string]: T; 19 | } 20 | 21 | export interface ResponseDef { 22 | type: string; 23 | enumDeclaration: string; 24 | usesGlobalType: boolean; 25 | } 26 | 27 | export interface ControllerMethod { 28 | summary: string; 29 | operationId: string; 30 | description: string; 31 | methodName: MethodName; 32 | simpleName: string; 33 | name: string; 34 | url: string; 35 | swaggerUrl: string; 36 | responses: HttpResponse; 37 | responseDef: ResponseDef; 38 | paramDef: Parameter[]; 39 | basePath: string; 40 | } 41 | 42 | export interface MethodOutput { 43 | methodDef: string; 44 | interfaceDef: string; 45 | usesGlobalType: boolean; 46 | paramGroups: Dictionary; 47 | responseDef: ResponseDef; 48 | simpleName: string; 49 | methodName: string; 50 | } 51 | -------------------------------------------------------------------------------- /demo/generated/store/career/positions/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface PositionsState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialPositionsState: PositionsState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Career_Positions'; 26 | export const getPositionsStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function PositionsReducer( 29 | state: PositionsState = initialPositionsState, 30 | action: actions.PositionsAction): PositionsState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/order/patchOrder/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface PatchOrderState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialPatchOrderState: PatchOrderState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Order_PatchOrder'; 26 | export const getPatchOrderStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function PatchOrderReducer( 29 | state: PatchOrderState = initialPatchOrderState, 30 | action: actions.PatchOrderAction): PatchOrderState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/order/deleteORDER/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface DeleteORDERState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialDeleteORDERState: DeleteORDERState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Order_DeleteORDER'; 26 | export const getDeleteORDERStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function DeleteORDERReducer( 29 | state: DeleteORDERState = initialDeleteORDERState, 30 | action: actions.DeleteORDERAction): DeleteORDERState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/get/products.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {ProductsParams, ProductsService} from '../../demo/generated/controllers/Products'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`ProductsService`, () => { 7 | let service: ProductsService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(ProductsService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check service makes request as expected`, () => { 19 | const params: ProductsParams = { 20 | stringField: 'example-producer', 21 | int32Field: 10, 22 | BooleanField: true, 23 | longField: 100000, 24 | floatField: 10, 25 | doubleField: 10, 26 | dateField: '2017-04-12', 27 | dateTimeField: '2017-04-12T23:20:50.52Z', 28 | }; 29 | 30 | service.products(params).subscribe(); 31 | 32 | const req = backend.expectOne(r => r.url === '/api-base-path/products').request; 33 | expect(req.method).toBe('GET'); 34 | expect(req.body).toBe(null); 35 | 36 | Object.entries(params).forEach(([k, v]) => expect(req.params.get(k)).toBe(v.toString())); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /demo/generated/store/structures/array/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface ArrayState { 15 | data: __model.ArrayGeneratedInlineModel | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialArrayState: ArrayState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'Structures_Array'; 27 | export const getArrayStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function ArrayReducer( 30 | state: ArrayState = initialArrayState, 31 | action: actions.ArrayAction): ArrayState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | Object.defineProperty(exports, "__esModule", { value: true }); 4 | const commander_1 = require("commander"); 5 | const conf = require("./conf"); 6 | const generate_1 = require("./generate"); 7 | commander_1.program 8 | .option('-s, --src ', `Source directory, default: ${conf.apiFile}`) 9 | .option('-d, --dest ', `Destination directory, default: ${conf.outDir}`) 10 | .option('--no-store', 'Do not generate store') 11 | .option('-w, --unwrap-single-param-methods', 'Controller methods with a single parameter get a method_() where the parameter object is unwrapped') 12 | /* tslint:disable-next-line:max-line-length */ 13 | .option('-u, --swagger-url-path ', `swagger URL path, where the swagger ui documentation can be found; default: ${conf.swaggerUrlPath}, i.e. the resulting address would be http://example${conf.swaggerUrlPath}`) 14 | .option('-o, --omit-version', `Write version info, default: ${conf.omitVersion}`) 15 | .parse(process.argv); 16 | commander_1.program.parse(); 17 | const options = commander_1.program.opts(); 18 | (0, generate_1.generate)(options.src, options.dest, options.store, options.unwrapSingleParamMethods, options.swaggerUrlPath, options.omitVersion); 19 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /demo/generated/store/registration/registration/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface RegistrationState { 14 | data: object | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialRegistrationState: RegistrationState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'Registration_Registration'; 26 | export const getRegistrationStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function RegistrationReducer( 29 | state: RegistrationState = initialRegistrationState, 30 | action: actions.RegistrationAction): RegistrationState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/products/products/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface ProductsState { 15 | data: __model.Products | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialProductsState: ProductsState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'Products_Products'; 27 | export const getProductsStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function ProductsReducer( 30 | state: ProductsState = initialProductsState, 31 | action: actions.ProductsAction): ProductsState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserUpdate/restAuthUserUpdate.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {RestAuthService} from '../../../controllers/RestAuth'; 11 | 12 | @Injectable() 13 | export class RestAuthUserUpdateFormService { 14 | form: FormGroup; 15 | constructor( 16 | private restAuthService: RestAuthService, 17 | ) { 18 | this.form = new FormGroup({ 19 | data: new FormGroup({ 20 | pk: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 21 | username: new FormControl(undefined, [Validators.maxLength(150), Validators.pattern(/^[\w.@+-]+$/), Validators.required]), 22 | email: new FormControl(undefined, [Validators.email]), 23 | first_name: new FormControl(undefined, [Validators.maxLength(30)]), 24 | last_name: new FormControl(undefined, [Validators.maxLength(150)]), 25 | }, [Validators.required]), 26 | }); 27 | } 28 | 29 | submit(raw = false) { 30 | const data = raw ? 31 | this.form.getRawValue() : 32 | this.form.value; 33 | return this.restAuthService.restAuthUserUpdate(data); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/post/regitration.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {RegistrationParams, RegistrationService} from '../../demo/generated/controllers/Registration'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`LoginService`, () => { 7 | let service: RegistrationService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(RegistrationService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | const params: RegistrationParams = { 20 | registrationType: 'admin', 21 | email: 'test@test.com', 22 | password1: 'password1', 23 | password2: 'password2', 24 | selfRefParam: { 25 | prop1: 'property1', 26 | parent: { 27 | prop1: 'property1', 28 | }, 29 | }, 30 | }; 31 | service.registration(params).subscribe(); 32 | 33 | const req = backend.expectOne('/api-base-path/registration/admin').request; 34 | expect(req.method).toBe('POST'); 35 | const bodyParams = {...params}; 36 | delete (bodyParams as Partial).registrationType; 37 | expect(req.body).toEqual(bodyParams); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /tests/post/order.service.spec.ts: -------------------------------------------------------------------------------- 1 | import {HttpTestingController} from '@angular/common/http/testing'; 2 | 3 | import {OrderService} from '../../demo/generated/controllers/Order'; 4 | import {initHttpBed} from '../common'; 5 | 6 | describe(`OrderService`, () => { 7 | let service: OrderService; 8 | let backend: HttpTestingController; 9 | 10 | beforeEach(() => { 11 | ({service, backend} = initHttpBed(OrderService)); 12 | }); 13 | 14 | afterEach(() => { 15 | backend.verify(); 16 | }); 17 | 18 | it(`should check request parameters are correct`, () => { 19 | const bodyParam = {id: 15, name: 'example order'}; 20 | service.order({orderDto: bodyParam, producer: 'test-producer'}).subscribe(); 21 | 22 | const req = backend.expectOne(r => r.url === '/api-base-path/order').request; 23 | expect(req.method).toBe('POST'); 24 | expect(req.params.get('producer')).toBe('test-producer'); 25 | expect(req.body).toEqual(bodyParam); 26 | }); 27 | 28 | it(`should check missing single optional body param works and produces empty body object {}`, () => { 29 | service.order({}).subscribe(); 30 | 31 | const req = backend.expectOne('/api-base-path/order').request; 32 | expect(req.method).toBe('POST'); 33 | expect(req.params.toString()).toBe(''); 34 | expect(req.body).toEqual({}); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserPartialUpdate/restAuthUserPartialUpdate.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {RestAuthService} from '../../../controllers/RestAuth'; 11 | 12 | @Injectable() 13 | export class RestAuthUserPartialUpdateFormService { 14 | form: FormGroup; 15 | constructor( 16 | private restAuthService: RestAuthService, 17 | ) { 18 | this.form = new FormGroup({ 19 | data: new FormGroup({ 20 | pk: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 21 | username: new FormControl(undefined, [Validators.maxLength(150), Validators.pattern(/^[\w.@+-]+$/), Validators.required]), 22 | email: new FormControl(undefined, [Validators.email]), 23 | first_name: new FormControl(undefined, [Validators.maxLength(30)]), 24 | last_name: new FormControl(undefined, [Validators.maxLength(150)]), 25 | }, [Validators.required]), 26 | }); 27 | } 28 | 29 | submit(raw = false) { 30 | const data = raw ? 31 | this.form.getRawValue() : 32 | this.form.value; 33 | return this.restAuthService.restAuthUserPartialUpdate(data); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutList/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface RestAuthLogoutListState { 14 | data: void | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialRestAuthLogoutListState: RestAuthLogoutListState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'RestAuth_RestAuthLogoutList'; 26 | export const getRestAuthLogoutListStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function RestAuthLogoutListReducer( 29 | state: RestAuthLogoutListState = initialRestAuthLogoutListState, 30 | action: actions.RestAuthLogoutListAction): RestAuthLogoutListState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/goods/getGoodsList/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface GetGoodsListState { 15 | data: __model.GetGoodsListGeneratedInlineModel | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialGetGoodsListState: GetGoodsListState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'Goods_GetGoodsList'; 27 | export const getGetGoodsListStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function GetGoodsListReducer( 30 | state: GetGoodsListState = initialGetGoodsListState, 31 | action: actions.GetGoodsListAction): GetGoodsListState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dist/conf.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"conf.js","sourceRoot":"","sources":["../src/conf.ts"],"names":[],"mappings":";;;AAGA,2BAA2B;AACd,QAAA,MAAM,GAAG,SAAS,CAAC;AACnB,QAAA,SAAS,GAAG,QAAQ,CAAC;AACrB,QAAA,OAAO,GAAG,MAAM,CAAC;AACjB,QAAA,MAAM,GAAG,aAAa,CAAC;AACvB,QAAA,QAAQ,GAAG,OAAO,CAAC;AACnB,QAAA,QAAQ,GAAG,QAAQ,CAAC;AACpB,QAAA,OAAO,GAAG,wBAAwB,CAAC;AACnC,QAAA,SAAS,GAAG,OAAO,CAAC;AACpB,QAAA,WAAW,GAAG,CAAC,CAAC;AAChB,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,WAAW,GAAG,KAAK,CAAC;AACjC,sBAAsB;AACT,QAAA,WAAW,GAAG,qBAAqB,CAAC;AAEjD,wDAAwD;AAC3C,QAAA,WAAW,GAAmC;IACzD,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,QAAQ;IACjB,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,8CAA8C;AAC9C,oDAAoD;AACpD,2GAA2G;AAC3G,oCAAoC;AACvB,QAAA,aAAa,GAA2C;IACnE,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;IAChC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;IACtD,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;IACrD,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;IACxC,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B,CAAC;AACF,0CAA0C;AAC1C,oCAAoC;AACvB,QAAA,iBAAiB,GAAG,CAAC,YAAY,CAAC,CAAC;AAChD,2BAA2B;AAC3B,+CAA+C;AAClC,QAAA,eAAe,GAAuD;IACjF,GAAG,EAAE;QACH,IAAI,EAAE,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;KAC/D;CACF,CAAC"} -------------------------------------------------------------------------------- /demo/generated/store/product-detail/productDetail/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface ProductDetailState { 15 | data: __model.ProductDetail | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialProductDetailState: ProductDetailState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'ProductDetail_ProductDetail'; 27 | export const getProductDetailStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function ProductDetailReducer( 30 | state: ProductDetailState = initialProductDetailState, 31 | action: actions.ProductDetailAction): ProductDetailState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthLogoutCreate/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as actions from './actions'; 12 | 13 | export interface RestAuthLogoutCreateState { 14 | data: void | null; 15 | loading: boolean; 16 | error: HttpErrorResponse | null; 17 | } 18 | 19 | export const initialRestAuthLogoutCreateState: RestAuthLogoutCreateState = { 20 | data: null, 21 | loading: false, 22 | error: null, 23 | }; 24 | 25 | export const selectorName = 'RestAuth_RestAuthLogoutCreate'; 26 | export const getRestAuthLogoutCreateStateSelector = createFeatureSelector(selectorName); 27 | 28 | export function RestAuthLogoutCreateReducer( 29 | state: RestAuthLogoutCreateState = initialRestAuthLogoutCreateState, 30 | action: actions.RestAuthLogoutCreateAction): RestAuthLogoutCreateState { 31 | switch (action.type) { 32 | case actions.Actions.START: return {...state, loading: true, error: null}; 33 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 34 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 35 | default: return state; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserRead/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface RestAuthUserReadState { 15 | data: __model.UserDetails | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialRestAuthUserReadState: RestAuthUserReadState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'RestAuth_RestAuthUserRead'; 27 | export const getRestAuthUserReadStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function RestAuthUserReadReducer( 30 | state: RestAuthUserReadState = initialRestAuthUserReadState, 31 | action: actions.RestAuthUserReadAction): RestAuthUserReadState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dist/forms/shared-module.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.createSharedModule = void 0; 4 | const path = require("path"); 5 | const conf = require("../conf"); 6 | const utils_1 = require("../utils"); 7 | function createSharedModule(config) { 8 | let content = ''; 9 | content += `import {CommonModule} from '@angular/common';\n`; 10 | content += `import {NgModule} from '@angular/core';\n`; 11 | content += `import {ReactiveFormsModule} from '@angular/forms';\n`; 12 | content += '\n'; 13 | content += '@NgModule({\n'; 14 | content += (0, utils_1.indent)('imports: [\n'); 15 | content += (0, utils_1.indent)('CommonModule,\n', 2); 16 | content += (0, utils_1.indent)('ReactiveFormsModule,\n', 2); 17 | content += (0, utils_1.indent)('],\n'); 18 | content += (0, utils_1.indent)('exports: [\n'); 19 | content += (0, utils_1.indent)('CommonModule,\n', 2); 20 | content += (0, utils_1.indent)('ReactiveFormsModule,\n', 2); 21 | content += (0, utils_1.indent)('],\n'); 22 | content += '})\n'; 23 | content += `export class FormsSharedModule {}\n`; 24 | const moduleFileName = path.join(config.dest, conf.storeDir, `forms-shared.module.ts`); 25 | (0, utils_1.writeFile)(moduleFileName, content, config.header); 26 | } 27 | exports.createSharedModule = createSharedModule; 28 | //# sourceMappingURL=shared-module.js.map -------------------------------------------------------------------------------- /demo/generated/store/ticketing/showTicketDetail/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface ShowTicketDetailState { 15 | data: __model.TicketDetailOutput[] | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialShowTicketDetailState: ShowTicketDetailState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'Ticketing_ShowTicketDetail'; 27 | export const getShowTicketDetailStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function ShowTicketDetailReducer( 30 | state: ShowTicketDetailState = initialShowTicketDetailState, 31 | action: actions.ShowTicketDetailAction): ShowTicketDetailState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserUpdate/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface RestAuthUserUpdateState { 15 | data: __model.UserDetails | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialRestAuthUserUpdateState: RestAuthUserUpdateState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'RestAuth_RestAuthUserUpdate'; 27 | export const getRestAuthUserUpdateStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function RestAuthUserUpdateReducer( 30 | state: RestAuthUserUpdateState = initialRestAuthUserUpdateState, 31 | action: actions.RestAuthUserUpdateAction): RestAuthUserUpdateState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/generated/controllers/Registration.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface RegistrationParams { 15 | /** 16 | * E-mail 17 | * format: email 18 | */ 19 | email: string; 20 | /** Password 1 */ 21 | password1: string; 22 | /** Password 2 */ 23 | password2: string; 24 | /** Self ref parameter */ 25 | selfRefParam: __model.SelfRefObject; 26 | /** Registration type */ 27 | registrationType: string; 28 | } 29 | 30 | @Injectable() 31 | export class RegistrationService { 32 | constructor(private http: HttpClient) {} 33 | 34 | /** 35 | * create registration credentials 36 | * http://example.com/swagger/swagger-ui.html#!/Registration/Registration 37 | */ 38 | registration(params: RegistrationParams): Observable { 39 | const formDataParams = { 40 | email: params.email, 41 | password1: params.password1, 42 | password2: params.password2, 43 | selfRefParam: params.selfRefParam, 44 | }; 45 | const pathParams = { 46 | registrationType: params.registrationType, 47 | }; 48 | return this.http.post(`/api-base-path/registration/${pathParams.registrationType}`, formDataParams); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /demo/generated/store/products/products/products.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {ProductsService} from '../../../controllers/Products'; 11 | 12 | @Injectable() 13 | export class ProductsFormService { 14 | form: FormGroup; 15 | constructor( 16 | private productsService: ProductsService, 17 | ) { 18 | this.form = new FormGroup({ 19 | stringField: new FormControl(undefined, []), 20 | BooleanField: new FormControl(undefined, []), 21 | int32Field: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 22 | longField: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 23 | floatField: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 24 | doubleField: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/)]), 25 | byteField: new FormControl(undefined, []), 26 | binaryField: new FormControl(undefined, []), 27 | dateField: new FormControl(undefined, []), 28 | dateTimeField: new FormControl(undefined, []), 29 | }); 30 | } 31 | 32 | submit(raw = false) { 33 | const data = raw ? 34 | this.form.getRawValue() : 35 | this.form.value; 36 | return this.productsService.products(data); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dist/forms/process-module.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"process-module.js","sourceRoot":"","sources":["../../src/forms/process-module.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,oCAA2C;AAE3C,SAAgB,YAAY,CAAC,MAAc,EAAE,IAAY,EAAE,mBAA2B,EACzD,cAAsB,EAAE,UAAkB,EAAE,SAAiB,EAC7D,OAAgB;IAC3C,IAAI,OAAO,GAAG,2CAA2C,CAAC;IAC1D,OAAO,IAAI,qEAAqE,CAAC;IACjF,OAAO,IAAI,+DAA+D,CAAC;IAC3E,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,WAAW,IAAI,uCAAuC,IAAI,MAAM,CAAC;IAE5E,sBAAsB;IACtB,OAAO,IAAI,gEAAgE,CAAC;IAC5E,IAAI,OAAO;QAAE,OAAO,IAAI,WAAW,SAAS,wBAAwB,UAAU,cAAc,CAAC;IAC7F,OAAO,IAAI,IAAI,CAAC;IAEhB,OAAO,IAAI,WAAW,mBAAmB,qCAAqC,CAAC;IAC/E,OAAO,IAAI,WAAW,mBAAmB,sCAAsC,CAAC;IAChF,OAAO,IAAI,mDAAmD,CAAC;IAC/D,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,eAAe,CAAC;IAC3B,OAAO,IAAI,IAAA,cAAM,EAAC,cAAc,CAAC,CAAC;IAElC,sBAAsB;IACtB,OAAO,IAAI,IAAA,cAAM,EAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;IAE7C,OAAO,IAAI,IAAA,cAAM,EAAC,4CAA4C,mBAAmB,aAAa,EAAE,CAAC,CAAC,CAAC;IACnG,OAAO,IAAI,IAAA,cAAM,EAAC,iCAAiC,mBAAmB,cAAc,EAAE,CAAC,CAAC,CAAC;IACzF,OAAO,IAAI,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC;IAE1B,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;IACtC,IAAI,OAAO;QAAE,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,cAAc,CAAC,CAAC;IACxD,OAAO,IAAI,IAAA,cAAM,EAAC,gBAAgB,CAAC,CAAC;IACpC,OAAO,IAAI,IAAA,cAAM,EAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAChC,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,IAAA,cAAM,EAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,IAAI,MAAM,CAAC;IAClB,OAAO,IAAI,gBAAgB,SAAS,aAAa,CAAC;IAElD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,UAAU,YAAY,CAAC,CAAC;IAC5E,IAAA,iBAAS,EAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACpD,CAAC;AAvCD,oCAuCC"} -------------------------------------------------------------------------------- /demo/generated/store/rest-auth/restAuthUserPartialUpdate/states/reducers.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {createFeatureSelector} from '@ngrx/store'; 9 | 10 | import {HttpErrorResponse} from '@angular/common/http'; 11 | import * as __model from '../../../../model'; 12 | import * as actions from './actions'; 13 | 14 | export interface RestAuthUserPartialUpdateState { 15 | data: __model.UserDetails | null; 16 | loading: boolean; 17 | error: HttpErrorResponse | null; 18 | } 19 | 20 | export const initialRestAuthUserPartialUpdateState: RestAuthUserPartialUpdateState = { 21 | data: null, 22 | loading: false, 23 | error: null, 24 | }; 25 | 26 | export const selectorName = 'RestAuth_RestAuthUserPartialUpdate'; 27 | export const getRestAuthUserPartialUpdateStateSelector = createFeatureSelector(selectorName); 28 | 29 | export function RestAuthUserPartialUpdateReducer( 30 | state: RestAuthUserPartialUpdateState = initialRestAuthUserPartialUpdateState, 31 | action: actions.RestAuthUserPartialUpdateAction): RestAuthUserPartialUpdateState { 32 | switch (action.type) { 33 | case actions.Actions.START: return {...state, loading: true, error: null}; 34 | case actions.Actions.SUCCESS: return {...state, data: action.payload, loading: false}; 35 | case actions.Actions.ERROR: return {...state, error: action.payload, loading: false}; 36 | default: return state; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo/generated/controllers/Goods.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient, HttpParams} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface GetGoodsListParams { 15 | /** Number of results to return per page. */ 16 | limit?: number; 17 | /** The initial index from which to return the results. */ 18 | offset?: number; 19 | } 20 | 21 | @Injectable() 22 | export class GoodsService { 23 | constructor(private http: HttpClient) {} 24 | 25 | /** http://example.com/swagger/swagger-ui.html#!/goods/goods_get-goods-list_list */ 26 | getGoodsList(params: GetGoodsListParams): Observable<__model.GetGoodsListGeneratedInlineModel> { 27 | const queryParamBase = { 28 | limit: params.limit, 29 | offset: params.offset, 30 | }; 31 | 32 | let queryParams = new HttpParams(); 33 | Object.entries(queryParamBase).forEach(([key, value]: [string, any]) => { 34 | if (value !== undefined) { 35 | if (typeof value === 'string') queryParams = queryParams.set(key, value); 36 | else if (Array.isArray(value)) value.forEach(v => queryParams = queryParams.append(key, v)); 37 | else queryParams = queryParams.set(key, JSON.stringify(value)); 38 | } 39 | }); 40 | 41 | return this.http.get<__model.GetGoodsListGeneratedInlineModel>(`/api-base-path/goods/get-goods-list/`, {params: queryParams}); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /demo/generated/controllers/Ticketing.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient, HttpParams} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface ShowTicketDetailParams { 15 | /** format: date-time */ 16 | date_from?: string; 17 | /** format: date-time */ 18 | date_to?: string; 19 | id: number; 20 | } 21 | 22 | @Injectable() 23 | export class TicketingService { 24 | constructor(private http: HttpClient) {} 25 | 26 | /** 27 | * show_ticket_detail 28 | * http://example.com/swagger/swagger-ui.html#!/ticketing/ticketing_show-ticket-detail_read 29 | */ 30 | showTicketDetail(params: ShowTicketDetailParams): Observable<__model.TicketDetailOutput[]> { 31 | const queryParamBase = { 32 | date_from: params.date_from, 33 | date_to: params.date_to, 34 | }; 35 | 36 | let queryParams = new HttpParams(); 37 | Object.entries(queryParamBase).forEach(([key, value]: [string, any]) => { 38 | if (value !== undefined) { 39 | if (typeof value === 'string') queryParams = queryParams.set(key, value); 40 | else if (Array.isArray(value)) value.forEach(v => queryParams = queryParams.append(key, v)); 41 | else queryParams = queryParams.set(key, JSON.stringify(value)); 42 | } 43 | }); 44 | 45 | const pathParams = { 46 | id: params.id, 47 | }; 48 | return this.http.get<__model.TicketDetailOutput[]>(`/api-base-path/ticketing/show-ticket-detail/${pathParams.id}/`, {params: queryParams}); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dist/requests/process-responses.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"process-responses.js","sourceRoot":"","sources":["../../src/requests/process-responses.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,4BAA4B;AAE5B,yBAAyB;AACzB,6BAA6B;AAC7B,sCAA0D;AAC1D,gCAAgC;AAChC,gDAAoF;AAIpF;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,YAA0B,EAAE,IAAY,EAAE,MAAc;IACvF,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,MAAgB,EAAE,EAAE,CAAC,CAChE,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,UAAU,GAAqB,EAAE,CAAC;IAEtC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE;YACjD,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACzF,MAAM,cAAc,GAAmB;gBACrC,QAAQ,EAAE,WAAW,mBAAmB,CAAC,IAAI,EAAE;gBAC/C,yBAAyB,EAAE,EAAE;gBAC7B,eAAe,EAAE,SAAS;gBAC1B,MAAM,EAAE,KAAK;gBACb,UAAU,EAAE,KAAK;aAClB,CAAC;YACF,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACjC;aAAM;YACL,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,IAAA,wBAAe,EAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;SACnF;KACF;IAED,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1F,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAEvD,IAAI,IAAY,CAAC;IACjB,IAAI,QAAQ,CAAC,MAAM,EAAE;QACnB,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KACpD;SAAM;QACL,IAAI,GAAG,MAAM,CAAC;KACf;IAED,OAAO,EAAC,IAAI,EAAE,eAAe,EAAE,cAAc,EAAC,CAAC;AACjD,CAAC;AAjCD,4CAiCC;AAED,SAAS,6BAA6B,CAAC,MAAc,EAAE,IAAY,EAAE,MAAc;IACjF,MAAM,YAAY,GAAG,IAAA,+BAAiB,EAAC,MAAM,EAAE,GAAG,IAAI,sBAAsB,EAAE,MAAM,CAAC,CAAC;IACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,KAAK,CAAC,CAAC;IAChE,MAAM,eAAe,GAAG,IAAA,0BAAY,EAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACxD,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,GAAG,eAAe,IAAI,CAAC,CAAC;IAEpD,OAAO,YAAY,CAAC;AACtB,CAAC"} -------------------------------------------------------------------------------- /dist/requests/process-params.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"process-params.js","sourceRoot":"","sources":["../../src/requests/process-params.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,4BAA4B;AAE5B,sCAA0C;AAE1C,oCAAgC;AAShC;;;;GAIG;AACH,SAAgB,aAAa,CAAC,GAAgB,EAAE,UAAkB;IAChE,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,QAAQ,IAAI,oBAAoB,UAAU,MAAM,CAAC;IAEjD,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAA,wBAAe,EAC5C,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAEnD,QAAQ,IAAI,IAAA,cAAM,EAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAa,CAAC,CAAC;IAC1D,QAAQ,IAAI,IAAI,CAAC;IACjB,QAAQ,IAAI,KAAK,CAAC;IAClB,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,KAAK,CAAC,MAAM,EAAE;QAChB,QAAQ,IAAI,IAAI,CAAC;QACjB,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/B,QAAQ,IAAI,IAAI,CAAC;KAClB;IAED,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpE,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAC,CAAC;AACjE,CAAC;AA1BD,sCA0BC;AAED,+CAA+C;AAC/C,sDAAsD;AACtD,oDAAoD;AACpD,SAAgB,iBAAiB,CAAC,KAAgB;IAChD,OAAO;QACL,GAAG;YACD,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,KAAK,CAAC,WAAW;SAC/B;QACD,GAAG,KAAK,CAAC,MAAM,EAAE,gBAAgB;KAClC,CAAC;AACJ,CAAC;AAnBD,8CAmBC"} -------------------------------------------------------------------------------- /dist/forms/generate-form-modules.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generate-form-modules.js","sourceRoot":"","sources":["../../src/forms/generate-form-modules.ts"],"names":[],"mappings":";;;AAAA,4BAA4B;AAC5B,6BAA6B;AAE7B,gCAAgC;AAKhC,oCAAmC;AACnC,eAAe;AACf,mEAA4D;AAC5D,qDAA8C;AAC9C,mDAAmD;AACnD,0EAAyG;AACzG,0EAAmE;AACnE,4EAAqE;AAErE,SAAgB,WAAW,CAAC,MAAc,EAAE,IAAY,EAAE,gBAAgC,EAC9D,WAAkC;IAC5D,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC;IAC3D,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC;IAEvB,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC9C,MAAM,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC;QAChD,MAAM,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC;QAChD,MAAM,UAAU,GAAG,eAAe,CAAC,UAAU,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;QAC1E,IAAA,iBAAS,EAAC,cAAc,CAAC,CAAC;QAE1B,IAAI,UAAU,GAAgB,EAAE,CAAC;QACjC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC1C,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,MAAM,mBAAmB,GAAG,IAAA,8CAAsB,EAAC,UAAU,CAAC,CAAC;QAC/D,MAAM,SAAS,GAAG,IAAA,oCAAY,EAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,IAAI,CAAC,CAAC;QAE7C,IAAI,aAAa,EAAE;YACjB,eAAe;YACf,IAAA,2CAAmB,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;SACnG;QAED,IAAI,MAAM,CAAC,aAAa,EAAE;YACxB,SAAS;YACT,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/D,IAAA,iBAAS,EAAC,aAAa,CAAC,CAAC;YAEzB,aAAa;YACb,IAAA,2CAAmB,EAAC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,mBAAmB,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;YAC5G,cAAc;YACd,IAAA,6CAAoB,EAAC,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YAC1F,aAAa;YACb,IAAA,2CAAmB,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;YAC/F,wBAAwB;YACxB,IAAA,kCAAkB,EAAC,MAAM,CAAC,CAAC;YAC3B,YAAY;YACZ,IAAA,6BAAY,EAAC,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;SACvG;KACF;AACH,CAAC;AA7CD,kCA6CC"} -------------------------------------------------------------------------------- /src/common/templates/utils.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray, FormControl, FormGroup} from '@angular/forms'; 2 | 3 | import {FormArrayExtended} from './formArrayExtended'; 4 | import {FormMap} from './formMap'; 5 | 6 | export type ControlFactory = () => AbstractControl; 7 | 8 | /** 9 | * Recursively sets values of nested controls so nested object === null/undefined 10 | * does not cause failure as in case of AbstractControl.patchValue 11 | * @param control target FormControl, FormArray or FormGroup 12 | * @param value source data 13 | */ 14 | export function safeSetValue(control: AbstractControl, value: any) { 15 | if (control instanceof FormControl) { 16 | control.setValue(value, {emitEvent: false}); 17 | return; 18 | } 19 | 20 | if (control instanceof FormArrayExtended) { 21 | if (nullOrUndef(value)) value = []; 22 | if (!Array.isArray(value)) throw new TypeError(`Cannot set value '${value}' on FormArrayExtended`); 23 | 24 | control.setSize(value.length); 25 | control.controls.forEach((c, idx) => safeSetValue(c, value[idx])); 26 | } else if (control instanceof FormMap) { 27 | if (nullOrUndef(value)) value = {}; 28 | if (typeof value !== 'object' || Array.isArray(value)) { 29 | throw new TypeError(`Cannot set value '${value}' on FormMap`); 30 | } 31 | 32 | control.setShape(Object.keys(value)); 33 | Object.entries(control.controls).forEach(([name, c]) => safeSetValue(c, value[name])); 34 | } else if (control instanceof FormArray) { 35 | control.controls.forEach((child, idx) => 36 | safeSetValue(child, getValue(value, idx))); 37 | } else if (control instanceof FormGroup) { 38 | Object.keys(control.controls).forEach(name => { 39 | safeSetValue(control.controls[name], getValue(value, name)); 40 | }); 41 | } 42 | } 43 | 44 | function nullOrUndef(input: any) { 45 | return input === undefined || input === null; 46 | } 47 | 48 | function getValue(input: any, attribute: string | number) { 49 | return nullOrUndef(input) || typeof input !== 'object' ? 50 | undefined : 51 | input[attribute]; 52 | } 53 | -------------------------------------------------------------------------------- /demo/generated/common/utils.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray, FormControl, FormGroup} from '@angular/forms'; 2 | 3 | import {FormArrayExtended} from './formArrayExtended'; 4 | import {FormMap} from './formMap'; 5 | 6 | export type ControlFactory = () => AbstractControl; 7 | 8 | /** 9 | * Recursively sets values of nested controls so nested object === null/undefined 10 | * does not cause failure as in case of AbstractControl.patchValue 11 | * @param control target FormControl, FormArray or FormGroup 12 | * @param value source data 13 | */ 14 | export function safeSetValue(control: AbstractControl, value: any) { 15 | if (control instanceof FormControl) { 16 | control.setValue(value, {emitEvent: false}); 17 | return; 18 | } 19 | 20 | if (control instanceof FormArrayExtended) { 21 | if (nullOrUndef(value)) value = []; 22 | if (!Array.isArray(value)) throw new TypeError(`Cannot set value '${value}' on FormArrayExtended`); 23 | 24 | control.setSize(value.length); 25 | control.controls.forEach((c, idx) => safeSetValue(c, value[idx])); 26 | } else if (control instanceof FormMap) { 27 | if (nullOrUndef(value)) value = {}; 28 | if (typeof value !== 'object' || Array.isArray(value)) { 29 | throw new TypeError(`Cannot set value '${value}' on FormMap`); 30 | } 31 | 32 | control.setShape(Object.keys(value)); 33 | Object.entries(control.controls).forEach(([name, c]) => safeSetValue(c, value[name])); 34 | } else if (control instanceof FormArray) { 35 | control.controls.forEach((child, idx) => 36 | safeSetValue(child, getValue(value, idx))); 37 | } else if (control instanceof FormGroup) { 38 | Object.keys(control.controls).forEach(name => { 39 | safeSetValue(control.controls[name], getValue(value, name)); 40 | }); 41 | } 42 | } 43 | 44 | function nullOrUndef(input: any) { 45 | return input === undefined || input === null; 46 | } 47 | 48 | function getValue(input: any, attribute: string | number) { 49 | return nullOrUndef(input) || typeof input !== 'object' ? 50 | undefined : 51 | input[attribute]; 52 | } 53 | -------------------------------------------------------------------------------- /dist/common/templates/utils.ts: -------------------------------------------------------------------------------- 1 | import {AbstractControl, FormArray, FormControl, FormGroup} from '@angular/forms'; 2 | 3 | import {FormArrayExtended} from './formArrayExtended'; 4 | import {FormMap} from './formMap'; 5 | 6 | export type ControlFactory = () => AbstractControl; 7 | 8 | /** 9 | * Recursively sets values of nested controls so nested object === null/undefined 10 | * does not cause failure as in case of AbstractControl.patchValue 11 | * @param control target FormControl, FormArray or FormGroup 12 | * @param value source data 13 | */ 14 | export function safeSetValue(control: AbstractControl, value: any) { 15 | if (control instanceof FormControl) { 16 | control.setValue(value, {emitEvent: false}); 17 | return; 18 | } 19 | 20 | if (control instanceof FormArrayExtended) { 21 | if (nullOrUndef(value)) value = []; 22 | if (!Array.isArray(value)) throw new TypeError(`Cannot set value '${value}' on FormArrayExtended`); 23 | 24 | control.setSize(value.length); 25 | control.controls.forEach((c, idx) => safeSetValue(c, value[idx])); 26 | } else if (control instanceof FormMap) { 27 | if (nullOrUndef(value)) value = {}; 28 | if (typeof value !== 'object' || Array.isArray(value)) { 29 | throw new TypeError(`Cannot set value '${value}' on FormMap`); 30 | } 31 | 32 | control.setShape(Object.keys(value)); 33 | Object.entries(control.controls).forEach(([name, c]) => safeSetValue(c, value[name])); 34 | } else if (control instanceof FormArray) { 35 | control.controls.forEach((child, idx) => 36 | safeSetValue(child, getValue(value, idx))); 37 | } else if (control instanceof FormGroup) { 38 | Object.keys(control.controls).forEach(name => { 39 | safeSetValue(control.controls[name], getValue(value, name)); 40 | }); 41 | } 42 | } 43 | 44 | function nullOrUndef(input: any) { 45 | return input === undefined || input === null; 46 | } 47 | 48 | function getValue(input: any, attribute: string | number) { 49 | return nullOrUndef(input) || typeof input !== 'object' ? 50 | undefined : 51 | input[attribute]; 52 | } 53 | -------------------------------------------------------------------------------- /src/forms/process-module.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import {Config} from '../generate'; 3 | import {indent, writeFile} from '../utils'; 4 | 5 | export function createModule(config: Config, name: string, actionClassNameBase: string, 6 | formSubDirName: string, simpleName: string, className: string, 7 | addForm: boolean) { 8 | let content = `import {NgModule} from '@angular/core';\n`; 9 | content += `import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects';\n`; 10 | content += `import {StoreModule as NgrxStoreModule} from '@ngrx/store';\n`; 11 | content += '\n'; 12 | content += `import {${name}Service} from '../../../controllers/${name}';\n`; 13 | 14 | // TODO! use or remove 15 | content += `import {FormsSharedModule} from '../../forms-shared.module';\n`; 16 | if (addForm) content += `import {${className}FormService} from './${simpleName}.service';\n`; 17 | content += `\n`; 18 | 19 | content += `import {${actionClassNameBase}Effects} from './states/effects';\n`; 20 | content += `import {${actionClassNameBase}Reducer} from './states/reducers';\n`; 21 | content += `import {selectorName} from './states/reducers';\n`; 22 | content += '\n'; 23 | content += '@NgModule({\n'; 24 | content += indent('imports: [\n'); 25 | 26 | // TODO! use or remove 27 | content += indent('FormsSharedModule,\n', 2); 28 | 29 | content += indent(`NgrxStoreModule.forFeature(selectorName, ${actionClassNameBase}Reducer),\n`, 2); 30 | content += indent(`NgrxEffectsModule.forFeature([${actionClassNameBase}Effects]),\n`, 2); 31 | content += indent('],\n'); 32 | 33 | const providers = [`${name}Service,`]; 34 | if (addForm) providers.push(`${className}FormService,`); 35 | content += indent('providers: [\n'); 36 | content += indent(providers, 2); 37 | content += '\n'; 38 | content += indent('],\n'); 39 | content += '})\n'; 40 | content += `export class ${className}Module {}\n`; 41 | 42 | const moduleFileName = path.join(formSubDirName, `${simpleName}.module.ts`); 43 | writeFile(moduleFileName, content, config.header); 44 | } 45 | -------------------------------------------------------------------------------- /src/conf.ts: -------------------------------------------------------------------------------- 1 | /** Configuration constants */ 2 | import {MethodName, NativeNames, ParamLocation} from './types'; 3 | 4 | // relative to project root 5 | export const outDir = 'src/api'; 6 | export const commonDir = 'common'; 7 | export const defsDir = 'defs'; 8 | export const apiDir = 'controllers'; 9 | export const storeDir = 'store'; 10 | export const stateDir = 'states'; 11 | export const apiFile = 'conf/api/api-docs.json'; 12 | export const modelFile = 'model'; 13 | export const indentation = 2; 14 | export const swaggerUrlPath = '/swagger'; 15 | export const omitVersion = false; 16 | // part of path in url 17 | export const swaggerFile = '/swagger-ui.html#!/'; 18 | 19 | // mapping from swagger native types to javascript types 20 | export const nativeTypes: {[key in NativeNames]: string} = { 21 | binary: 'number', 22 | boolean: 'boolean', 23 | byte: 'number', 24 | date: 'string', 25 | dateTime: 'string', 26 | double: 'number', 27 | file: 'File', 28 | float: 'number', 29 | integer: 'number', 30 | long: 'number', 31 | number: 'number', 32 | object: 'object', 33 | password: 'string', 34 | string: 'string', 35 | }; 36 | 37 | // list of parameter types accepted by methods 38 | // ordered as they are passed to api service methods 39 | // The 'parameters: []' type is only technical and serves for situations when common parameters are defined 40 | // on the same level as HTTP methods 41 | export const allowedParams: {[key in MethodName]: ParamLocation[]} = { 42 | get: ['path', 'query', 'header'], 43 | patch: ['path', 'body', 'query', 'formData', 'header'], 44 | post: ['path', 'body', 'query', 'formData', 'header'], 45 | put: ['path', 'body', 'query', 'header'], 46 | delete: ['path', 'header'], 47 | }; 48 | // list of simplified names of controllers 49 | // that do not to generate api layer 50 | export const controllerIgnores = ['BackOffice']; 51 | // implemented only for api 52 | // once other one is needed, make it file-based 53 | export const adHocExceptions: {[key: string]: {[key: string]: [RegExp, string]}} = { 54 | api: { 55 | Help: [/^ itemNumbers\?: ref;$/m, ' itemNumbers?: number[]'], 56 | }, 57 | }; 58 | -------------------------------------------------------------------------------- /dist/forms/states/generate-http-reducers.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generate-http-reducers.js","sourceRoot":"","sources":["../../../src/forms/states/generate-http-reducers.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,qCAAoC;AAEpC,uCAA8C;AAE9C,SAAgB,oBAAoB,CAAC,MAAc,EAAE,IAAY,EAAE,mBAA2B,EACzD,cAAsB,EAAE,YAAoB;IAC/E,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO,IAAI,iBAAiB,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IAClE,OAAO,IAAI,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC/D,OAAO,IAAI,eAAe,CAAC,mBAAmB,CAAC,CAAC;IAChD,OAAO,IAAI,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACzD,OAAO,IAAI,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;IAErD,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,eAAQ,EAAE,aAAa,CAAC,CAAC;IAC5E,IAAA,iBAAS,EAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAXD,oDAWC;AAED,SAAS,iBAAiB,CAAC,UAAmB;IAC5C,IAAI,GAAG,GAAG,wDAAwD,CAAC;IACnE,GAAG,IAAI,2DAA2D,CAAC;IACnE,IAAI,UAAU;QAAE,GAAG,IAAI,iDAAiD,CAAC;IACzE,GAAG,IAAI,2CAA2C,CAAC;IAEnD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,gBAAgB,CAAC,mBAA2B,EAAE,IAAY;IACjE,IAAI,GAAG,GAAG,oBAAoB,mBAAmB,WAAW,CAAC;IAC7D,GAAG,IAAI,IAAA,cAAM,EAAC,SAAS,IAAI,YAAY,CAAC,CAAC;IACzC,GAAG,IAAI,IAAA,cAAM,EAAC,qBAAqB,CAAC,CAAC;IACrC,GAAG,IAAI,IAAA,cAAM,EAAC,oCAAoC,CAAC,CAAC;IACpD,GAAG,IAAI,OAAO,CAAC;IAEf,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,eAAe,CAAC,mBAA2B;IAClD,IAAI,GAAG,GAAG,uBAAuB,mBAAmB,UAAU,mBAAmB,aAAa,CAAC;IAC/F,GAAG,IAAI,IAAA,cAAM,EAAC,eAAe,CAAC,CAAC;IAC/B,GAAG,IAAI,IAAA,cAAM,EAAC,mBAAmB,CAAC,CAAC;IACnC,GAAG,IAAI,IAAA,cAAM,EAAC,gBAAgB,CAAC,CAAC;IAChC,GAAG,IAAI,QAAQ,CAAC;IAEhB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,mBAA2B;IACnE,IAAI,GAAG,GAAG,gCAAgC,IAAI,IAAI,mBAAmB,MAAM,CAAC;IAC5E,GAAG,IAAI,mBAAmB,mBAAmB,kBAAkB;QACxD,yBAAyB,mBAAmB,2BAA2B,CAAC;IAE/E,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,oBAAoB,CAAC,mBAA2B;IACvD,IAAI,GAAG,GAAG,mBAAmB,mBAAmB,YAAY,CAAC;IAC7D,GAAG,IAAI,IAAA,cAAM,EAAC,UAAU,mBAAmB,kBAAkB,mBAAmB,UAAU,CAAC,CAAC;IAC5F,GAAG,IAAI,IAAA,cAAM,EAAC,mBAAmB,mBAAmB,YAAY,mBAAmB,aAAa,CAAC,CAAC;IAClG,GAAG,IAAI,IAAA,cAAM,EAAC,0BAA0B,CAAC,CAAC;IAC1C,GAAG,IAAI,IAAA,cAAM,EAAC;QACZ,4EAA4E;QAC5E,wFAAwF;QACxF,uFAAuF;QACvF,wBAAwB;KACzB,EAAE,CAAC,CAAC,CAAC;IACN,GAAG,IAAI,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IACvB,GAAG,IAAI,KAAK,CAAC;IAEb,OAAO,GAAG,CAAC;AACb,CAAC"} -------------------------------------------------------------------------------- /demo/generated/controllers/Structures.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient, HttpParams} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface ArrayParams { 15 | /** testing number */ 16 | id: number; 17 | /** array structures */ 18 | arraySection: __model.ArrayStructure; 19 | } 20 | 21 | export interface MapParams { 22 | /** map structures */ 23 | mapSection: __model.MapStructure; 24 | } 25 | 26 | @Injectable() 27 | export class StructuresService { 28 | constructor(private http: HttpClient) {} 29 | 30 | /** 31 | * structural test for arrays and arrays of arrays 32 | * http://example.com/swagger/swagger-ui.html#!/Structures/structures_array 33 | */ 34 | array(params: ArrayParams): Observable<__model.ArrayGeneratedInlineModel> { 35 | const queryParamBase = { 36 | id: params.id, 37 | }; 38 | 39 | let queryParams = new HttpParams(); 40 | Object.entries(queryParamBase).forEach(([key, value]: [string, any]) => { 41 | if (value !== undefined) { 42 | if (typeof value === 'string') queryParams = queryParams.set(key, value); 43 | else if (Array.isArray(value)) value.forEach(v => queryParams = queryParams.append(key, v)); 44 | else queryParams = queryParams.set(key, JSON.stringify(value)); 45 | } 46 | }); 47 | 48 | const bodyParams = params.arraySection; 49 | 50 | return this.http.post<__model.ArrayGeneratedInlineModel>(`/api-base-path/structures/array`, bodyParams || {}, {params: queryParams}); 51 | } 52 | 53 | /** 54 | * structural test for maps 55 | * http://example.com/swagger/swagger-ui.html#!/Structures/structures_map 56 | */ 57 | map(params: MapParams): Observable { 58 | const bodyParams = params.mapSection; 59 | 60 | return this.http.post(`/api-base-path/structures/map`, bodyParams || {}); 61 | } 62 | map_(mapSection: __model.MapStructure): Observable { 63 | return this.map({mapSection}); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | /** Shared types */ 2 | /* The 'parameters' MethodName type is only technical and serves for situations when common parameters are defined 3 | * on the same level as HTTP methods */ 4 | export type MethodName = 'get' | 'patch' | 'post' | 'put' | 'delete'; 5 | export type ParamLocation = 'path' | 'body' | 'query' | 'formData' | 'header'; 6 | export type HttpCode = '200' | '201' | '204' | 7 | '400' | '401' | '403' | '404' | '409' | '417' | 8 | '500'; 9 | 10 | export interface Method { 11 | tags: [string]; 12 | summary: string; 13 | operationId: string; 14 | description: string; 15 | parameters: Parameter[]; 16 | responses: HttpResponse; 17 | } 18 | 19 | export type HttpResponse = { 20 | [key in HttpCode]?: Response; 21 | }; 22 | 23 | interface ParameterSchemaBase { 24 | allowEmptyValue?: boolean; 25 | default?: any; 26 | description?: string; 27 | enum?: string[] | number[]; 28 | format?: string; 29 | items?: Schema; 30 | maximum?: number; 31 | maxLength?: number; 32 | minimum?: number; 33 | minLength?: number; 34 | pattern?: string; 35 | type?: string; 36 | uniqueItems?: boolean; 37 | } 38 | 39 | // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject 40 | export interface Parameter extends ParameterSchemaBase { 41 | description: string; 42 | in: ParamLocation; 43 | name: string; 44 | required: boolean; 45 | schema?: Schema; 46 | collectionFormat?: QueryCollectionFormat; 47 | } 48 | 49 | export type QueryCollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; 50 | 51 | export interface Schema extends ParameterSchemaBase { 52 | $ref?: string; 53 | additionalProperties?: Schema; 54 | example?: any; 55 | readOnly?: boolean; 56 | required?: string[]; 57 | type?: string; 58 | properties?: { 59 | [key: string]: Schema; 60 | }; 61 | } 62 | 63 | export interface Response { 64 | description?: string; 65 | schema?: Schema; 66 | } 67 | 68 | export type NativeNames = 69 | 'binary' | 'boolean' | 'byte' | 'date' | 'dateTime' | 'double' | 70 | 'file' | 'float' | 'integer' | 'long' | 'number' | 'object' | 71 | 'password' | 'string'; 72 | 73 | export type FileType = 'ts' | 'html' | 'scss'; 74 | -------------------------------------------------------------------------------- /demo/generated/controllers/Products.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {HttpClient, HttpParams} from '@angular/common/http'; 9 | import {Injectable} from '@angular/core'; 10 | import {Observable} from 'rxjs'; 11 | 12 | import * as __model from '../model'; 13 | 14 | export interface ProductsParams { 15 | stringField?: string; 16 | BooleanField?: boolean; 17 | /** format: int32 */ 18 | int32Field?: number; 19 | /** format: int64 */ 20 | longField?: number; 21 | /** format: float */ 22 | floatField?: number; 23 | /** format: double */ 24 | doubleField?: number; 25 | /** format: byte */ 26 | byteField?: string; 27 | /** format: binary */ 28 | binaryField?: string; 29 | /** format: date */ 30 | dateField?: string; 31 | /** format: date-time */ 32 | dateTimeField?: string; 33 | } 34 | 35 | @Injectable() 36 | export class ProductsService { 37 | constructor(private http: HttpClient) {} 38 | 39 | /** 40 | * Get all products 41 | * http://example.com/swagger/swagger-ui.html#!/Products/Products 42 | */ 43 | products(params: ProductsParams): Observable<__model.Products> { 44 | const queryParamBase = { 45 | stringField: params.stringField, 46 | BooleanField: params.BooleanField, 47 | int32Field: params.int32Field, 48 | longField: params.longField, 49 | floatField: params.floatField, 50 | doubleField: params.doubleField, 51 | byteField: params.byteField, 52 | binaryField: params.binaryField, 53 | dateField: params.dateField, 54 | dateTimeField: params.dateTimeField, 55 | }; 56 | 57 | let queryParams = new HttpParams(); 58 | Object.entries(queryParamBase).forEach(([key, value]: [string, any]) => { 59 | if (value !== undefined) { 60 | if (typeof value === 'string') queryParams = queryParams.set(key, value); 61 | else if (Array.isArray(value)) value.forEach(v => queryParams = queryParams.append(key, v)); 62 | else queryParams = queryParams.set(key, JSON.stringify(value)); 63 | } 64 | }); 65 | 66 | return this.http.get<__model.Products>(`/api-base-path/products`, {params: queryParams}); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /demo/generated/store/structures/map/map.service.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:max-line-length */ 2 | /** 3 | * Test Swagger 4 | * v1 5 | * example.com/api-base-path 6 | */ 7 | 8 | import {Injectable} from '@angular/core'; 9 | import {FormControl, FormGroup, Validators} from '@angular/forms'; 10 | import {FormArrayExtended} from '../../../common/formArrayExtended'; 11 | import {FormMap} from '../../../common/formMap'; 12 | import {StructuresService} from '../../../controllers/Structures'; 13 | 14 | @Injectable() 15 | export class MapFormService { 16 | form: FormGroup; 17 | constructor( 18 | private structuresService: StructuresService, 19 | ) { 20 | this.form = new FormGroup({ 21 | mapSection: new FormMap(() => ( 22 | new FormGroup({ 23 | control: new FormControl(undefined, []), 24 | group: new FormGroup({ 25 | id: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 26 | name: new FormControl(undefined, []), 27 | }, []), 28 | arrayOfObjects: new FormArrayExtended(() => ( 29 | new FormGroup({ 30 | id: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 31 | name: new FormControl(undefined, []), 32 | }, [])), [], []), 33 | mapRef: new FormMap(() => ( 34 | new FormControl(undefined, [])), {}, []), 35 | mapInlinePrimitive: new FormMap(() => ( 36 | new FormControl(undefined, [])), {}, []), 37 | mapInlineRef: new FormMap(() => ( 38 | new FormGroup({ 39 | id: new FormControl(undefined, [Validators.pattern(/^([+-]?[1-9]\d*|0)$/), Validators.required]), 40 | name: new FormControl(undefined, []), 41 | }, [])), {}, []), 42 | arrayOfMaps: new FormArrayExtended(() => ( 43 | new FormMap(() => ( 44 | new FormControl(undefined, [])), {}, [])), [], []), 45 | }, [Validators.required])), {}, [Validators.required]), 46 | }); 47 | } 48 | 49 | submit(raw = false) { 50 | const data = raw ? 51 | this.form.getRawValue() : 52 | this.form.value; 53 | return this.structuresService.map(data); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /dist/requests/process-paths.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"process-paths.js","sourceRoot":"","sources":["../../src/requests/process-paths.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,4BAA4B;AAC5B,gCAAgC;AAIhC,oCAA+B;AAC/B,6DAAuD;AAGvD;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,mBAAwC,EAAE,WAAmB,EAAE,MAAc,EAC7E,WAAkC,EAAE,QAAgB;IAE/E,MAAM,KAAK,GAAG,eAAe,CAAC,mBAAmB,CAAC,CAAC;IACnD,MAAM,WAAW,GAAuB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,GAAW,EAAE,EAAE,CAAC,CACjF,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAsB,EAAE,EAAE,CAAC,CAAC;QAClD,GAAG;QACH,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC;QACrB,UAAU;QACV,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC;QAC9B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,GAAG,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE;QACnE,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,QAAQ,EAAE,MAAM,CAAC,UAAU;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,IAAI;QACjB,QAAQ;KACT,CAAC,CAAC,CACJ,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;IACnE,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,IAAA,sCAAiB,EAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AACvG,CAAC;AAxBD,oCAwBC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,GAAW;IAChC,oBAAoB;IACpB,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC3C,iCAAiC;IACjC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnC,2BAA2B;IAC3B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACvC,+BAA+B;IAC/B,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,MAAc;IAC7B,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAA0B;IACjD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACvC,IAAI,SAAS,CAAC,UAAU,EAAE;YACxB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACnC,IAAI,GAAG,KAAK,YAAY;oBAAE,OAAO;gBAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAiB,CAAC,CAAC;gBAC5C,MAAM,CAAC,UAAU,GAAG,IAAA,aAAK,EAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YACnF,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,SAAS,CAAC,UAAU,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,OAAO,KAAc,CAAC;AACxB,CAAC"} -------------------------------------------------------------------------------- /dist/forms/process-module.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.createModule = void 0; 4 | const path = require("path"); 5 | const utils_1 = require("../utils"); 6 | function createModule(config, name, actionClassNameBase, formSubDirName, simpleName, className, addForm) { 7 | let content = `import {NgModule} from '@angular/core';\n`; 8 | content += `import {EffectsModule as NgrxEffectsModule} from '@ngrx/effects';\n`; 9 | content += `import {StoreModule as NgrxStoreModule} from '@ngrx/store';\n`; 10 | content += '\n'; 11 | content += `import {${name}Service} from '../../../controllers/${name}';\n`; 12 | // TODO! use or remove 13 | content += `import {FormsSharedModule} from '../../forms-shared.module';\n`; 14 | if (addForm) 15 | content += `import {${className}FormService} from './${simpleName}.service';\n`; 16 | content += `\n`; 17 | content += `import {${actionClassNameBase}Effects} from './states/effects';\n`; 18 | content += `import {${actionClassNameBase}Reducer} from './states/reducers';\n`; 19 | content += `import {selectorName} from './states/reducers';\n`; 20 | content += '\n'; 21 | content += '@NgModule({\n'; 22 | content += (0, utils_1.indent)('imports: [\n'); 23 | // TODO! use or remove 24 | content += (0, utils_1.indent)('FormsSharedModule,\n', 2); 25 | content += (0, utils_1.indent)(`NgrxStoreModule.forFeature(selectorName, ${actionClassNameBase}Reducer),\n`, 2); 26 | content += (0, utils_1.indent)(`NgrxEffectsModule.forFeature([${actionClassNameBase}Effects]),\n`, 2); 27 | content += (0, utils_1.indent)('],\n'); 28 | const providers = [`${name}Service,`]; 29 | if (addForm) 30 | providers.push(`${className}FormService,`); 31 | content += (0, utils_1.indent)('providers: [\n'); 32 | content += (0, utils_1.indent)(providers, 2); 33 | content += '\n'; 34 | content += (0, utils_1.indent)('],\n'); 35 | content += '})\n'; 36 | content += `export class ${className}Module {}\n`; 37 | const moduleFileName = path.join(formSubDirName, `${simpleName}.module.ts`); 38 | (0, utils_1.writeFile)(moduleFileName, content, config.header); 39 | } 40 | exports.createModule = createModule; 41 | //# sourceMappingURL=process-module.js.map -------------------------------------------------------------------------------- /dist/conf.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.adHocExceptions = exports.controllerIgnores = exports.allowedParams = exports.nativeTypes = exports.swaggerFile = exports.omitVersion = exports.swaggerUrlPath = exports.indentation = exports.modelFile = exports.apiFile = exports.stateDir = exports.storeDir = exports.apiDir = exports.defsDir = exports.commonDir = exports.outDir = void 0; 4 | // relative to project root 5 | exports.outDir = 'src/api'; 6 | exports.commonDir = 'common'; 7 | exports.defsDir = 'defs'; 8 | exports.apiDir = 'controllers'; 9 | exports.storeDir = 'store'; 10 | exports.stateDir = 'states'; 11 | exports.apiFile = 'conf/api/api-docs.json'; 12 | exports.modelFile = 'model'; 13 | exports.indentation = 2; 14 | exports.swaggerUrlPath = '/swagger'; 15 | exports.omitVersion = false; 16 | // part of path in url 17 | exports.swaggerFile = '/swagger-ui.html#!/'; 18 | // mapping from swagger native types to javascript types 19 | exports.nativeTypes = { 20 | binary: 'number', 21 | boolean: 'boolean', 22 | byte: 'number', 23 | date: 'string', 24 | dateTime: 'string', 25 | double: 'number', 26 | file: 'File', 27 | float: 'number', 28 | integer: 'number', 29 | long: 'number', 30 | number: 'number', 31 | object: 'object', 32 | password: 'string', 33 | string: 'string', 34 | }; 35 | // list of parameter types accepted by methods 36 | // ordered as they are passed to api service methods 37 | // The 'parameters: []' type is only technical and serves for situations when common parameters are defined 38 | // on the same level as HTTP methods 39 | exports.allowedParams = { 40 | get: ['path', 'query', 'header'], 41 | patch: ['path', 'body', 'query', 'formData', 'header'], 42 | post: ['path', 'body', 'query', 'formData', 'header'], 43 | put: ['path', 'body', 'query', 'header'], 44 | delete: ['path', 'header'], 45 | }; 46 | // list of simplified names of controllers 47 | // that do not to generate api layer 48 | exports.controllerIgnores = ['BackOffice']; 49 | // implemented only for api 50 | // once other one is needed, make it file-based 51 | exports.adHocExceptions = { 52 | api: { 53 | Help: [/^ itemNumbers\?: ref;$/m, ' itemNumbers?: number[]'], 54 | }, 55 | }; 56 | //# sourceMappingURL=conf.js.map -------------------------------------------------------------------------------- /dist/forms/states/generate-http-effects.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generate-http-effects.js","sourceRoot":"","sources":["../../../src/forms/states/generate-http-effects.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAG7B,uCAA8C;AAE9C,SAAgB,mBAAmB,CAAC,MAAc,EAAE,IAAY,EAAE,UAAkB,EAAE,mBAA2B,EAC7E,cAAsB,EAAE,WAAwB;IAClF,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,IAAI,yBAAyB,CAAC,mBAAmB,CAAC,CAAC;IAC1D,OAAO,IAAI,mBAAmB,CAAC,mBAAmB,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAC/F,OAAO,IAAI,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,IAAI,KAAK,CAAC;IAEjB,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC1E,IAAA,iBAAS,EAAC,eAAe,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAXD,kDAWC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAI,GAAG,GAAG,2DAA2D,CAAC;IACtE,GAAG,IAAI,6CAA6C,CAAC;IACrD,GAAG,IAAI,gEAAgE,CAAC;IACxE,GAAG,IAAI,IAAI,CAAC;IACZ,GAAG,IAAI,4BAA4B,CAAC;IACpC,GAAG,IAAI,IAAI,CAAC;IACZ,GAAG,IAAI,8DAA8D,CAAC;IACtE,GAAG,IAAI,WAAW,IAAI,0CAA0C,IAAI,MAAM,CAAC;IAC3E,GAAG,IAAI,yCAAyC,CAAC;IACjD,GAAG,IAAI,IAAI,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,yBAAyB,CAAC,mBAA2B;IAC5D,IAAI,GAAG,GAAG,iBAAiB,CAAC;IAC5B,GAAG,IAAI,gBAAgB,mBAAmB,aAAa,CAAC;IAExD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,wBAAwB,CAAC,IAAY;IAC5C,IAAI,GAAG,GAAG,gBAAgB,CAAC;IAC3B,GAAG,IAAI,IAAA,cAAM,EAAC,kCAAkC,CAAC,CAAC;IAClD,GAAG,IAAI,IAAA,cAAM,EAAC,WAAW,IAAI,CAAC,WAAW,EAAE,YAAY,IAAI,YAAY,CAAC,CAAC;IACzE,GAAG,IAAI,UAAU,CAAC;IAElB,OAAO,IAAA,cAAM,EAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED,SAAS,mBAAmB,CAAC,mBAA2B,EAAE,IAAY,EAAE,UAAkB,EAAE,SAAkB;IAC5G,MAAM,4BAA4B,GAAG,+BAA+B,CAAC,SAAS,CAAC,CAAC;IAEhF,IAAI,GAAG,GAAG,IAAA,cAAM,EAAC,GAAG,mBAAmB,iDAAiD,CAAC,CAAC;IAC1F,GAAG,IAAI,IAAA,cAAM,EAAC,iDAAiD,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,GAAG,IAAI,IAAA,cAAM,EACX,cAAc,WAAW,OAAO;QAChC,QAAQ,IAAI,CAAC,WAAW,EAAE,WAAW,UAAU,IAAI,4BAA4B,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3F,GAAG,IAAI,IAAA,cAAM,EAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC7B,GAAG,IAAI,IAAA,cAAM,EAAC,+CAA+C,EAAE,CAAC,CAAC,CAAC;IAClE,GAAG,IAAI,IAAA,cAAM,EAAC,2EAA2E,EAAE,CAAC,CAAC,CAAC;IAC9F,GAAG,IAAI,IAAA,cAAM,EAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACzB,GAAG,IAAI,IAAA,cAAM,EAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACzB,GAAG,IAAI,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IACvB,GAAG,IAAI,IAAI,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,+BAA+B,CAAC,SAAkB;IACzD,IAAI,SAAS;QAAE,OAAO,gBAAgB,CAAC;IACvC,OAAO,EAAE,CAAC;AACZ,CAAC"} -------------------------------------------------------------------------------- /dist/generate.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC5D,yBAAyB;AACzB,6BAA6B;AAE7B,+BAA+B;AAE/B,gDAA8D;AAC9D,+CAAiD;AACjD,4DAAsD;AACtD,mCAA4E;AAS5E;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CACtB,MAAc,IAAI,CAAC,OAAO,EAC1B,OAAe,IAAI,CAAC,MAAM,EAC1B,aAAa,GAAG,IAAI,EACpB,wBAAwB,GAAG,KAAK,EAChC,iBAAyB,IAAI,CAAC,cAAc,EAC5C,WAAW,GAAG,KAAK;IAEnB,IAAI,MAAW,CAAC;IAEhB,IAAI;QACF,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,WAAW,EAAE;YAC5B,IAAA,WAAG,EAAC,GAAG,GAAG,yEAAyE,EAAE,kBAAU,CAAC,GAAG,CAAC,CAAC;SACtG;;YAAM,IAAA,WAAG,EAAC,qBAAqB,GAAG,kBAAkB,EAAE,kBAAU,CAAC,GAAG,CAAC,CAAC;QAEvE,IAAA,WAAG,EAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACZ,OAAO;KACR;IAED,0CAA0C;IAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;KAChD;;QAAM,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;IAE5B,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAE1B,MAAM,MAAM,GAAG,IAAA,qBAAa,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClD,MAAM,MAAM,GAAW,EAAC,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB,EAAC,CAAC;IAE/E,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAA,gCAAkB,EAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACnE,IAAA,4BAAY,EAAC,MAAM,CAAC,KAAK,EAAE,UAAU,MAAM,CAAC,IAAI,GAAG,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,EACzE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AACrD,CAAC;AAvCD,4BAuCC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAA,gBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IAChD,IAAA,gBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;IAC9C,IAAA,gBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IAC7C,IAAA,gBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;IAE/C,IAAA,iBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3C,IAAA,iBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,IAAA,iBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,IAAA,iBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,+CAA+C;AAC/C,SAAS,cAAc,CAAC,IAAY;IAClC,IAAA,mBAAQ,EAAC,IAAI,CAAC,CAAC;IACf,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"} -------------------------------------------------------------------------------- /src/requests/process-params.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Processing of custom types from `paths` section 3 | * in the schema 4 | */ 5 | import * as _ from 'lodash'; 6 | 7 | import {processProperty} from '../common'; 8 | import {Parameter, Schema} from '../types'; 9 | import {indent} from '../utils'; 10 | 11 | export interface ProcessParamsOutput { 12 | paramDef: string; 13 | typesOnly: string; 14 | usesGlobalType: boolean; 15 | isInterfaceEmpty: boolean; 16 | } 17 | 18 | /** 19 | * Transforms input parameters to interfaces definition 20 | * @param def definition 21 | * @param paramsType name of the type 22 | */ 23 | export function processParams(def: Parameter[], paramsType: string): ProcessParamsOutput { 24 | let paramDef = ''; 25 | let typesOnly = ''; 26 | 27 | paramDef += `export interface ${paramsType} {\n`; 28 | 29 | const params = _.map(def, p => processProperty( 30 | parameterToSchema(p), p.name, paramsType, p.required)[0]); 31 | const isInterfaceEmpty = !params.length; 32 | const usesGlobalType = params.some(p => !p.native); 33 | 34 | paramDef += indent(_.map(params, 'property') as string[]); 35 | paramDef += `\n`; 36 | paramDef += `}\n`; 37 | const enums = _.map(params, 'enumDeclaration').filter(Boolean); 38 | 39 | if (enums.length) { 40 | paramDef += `\n`; 41 | paramDef += enums.join('\n\n'); 42 | paramDef += `\n`; 43 | } 44 | 45 | params.sort((p1, p2) => (p1.isRequired ? 0 : 1) - (p2.isRequired ? 0 : 1)); 46 | typesOnly = params.map(p => p.propertyAsMethodParameter).join(', '); 47 | 48 | return {paramDef, typesOnly, usesGlobalType, isInterfaceEmpty}; 49 | } 50 | 51 | // TODO! use required array to set the variable 52 | // TODO might be unnecessary for v3.0+ of OpenAPI spec 53 | // https://swagger.io/specification/#parameterObject 54 | export function parameterToSchema(param: Parameter): Schema { 55 | return { 56 | ...{ 57 | allowEmptyValue: param.allowEmptyValue, 58 | default: param.default, 59 | description: param.description, 60 | enum: param.enum, 61 | format: param.format, 62 | items: param.items, 63 | maximum: param.maximum, 64 | maxLength: param.maxLength, 65 | minimum: param.minimum, 66 | minLength: param.minLength, 67 | pattern: param.pattern, 68 | type: param.type, 69 | uniqueItems: param.uniqueItems, 70 | }, 71 | ...param.schema, // move level up 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /src/utils.spec.ts: -------------------------------------------------------------------------------- 1 | import * as test from 'tape'; 2 | import {merge} from './utils'; 3 | 4 | test( 5 | 'Merge arrays of objects favouring dup elems from one (dups determined by keys)', 6 | t => { 7 | const a = [ 8 | { 9 | name: 'date_from', 10 | in: 'query', 11 | required: false, 12 | type: 'string', 13 | format: 'date-time', 14 | }, 15 | { 16 | name: 'amount', 17 | in: 'path', 18 | required: false, 19 | type: 'integer', 20 | }, 21 | { 22 | name: 'date_to', 23 | in: 'query', 24 | required: false, 25 | type: 'string', 26 | format: 'date-time', 27 | }, 28 | { 29 | name: 'id', 30 | in: 'path', 31 | type: 'integer', 32 | required: true, 33 | }, 34 | ]; 35 | const b = [ 36 | { 37 | name: 'id', 38 | in: 'query', 39 | required: true, 40 | type: 'string', 41 | }, 42 | { 43 | name: 'amount', 44 | in: 'path', 45 | required: true, 46 | type: 'string', 47 | }, 48 | { 49 | name: 'firstName', 50 | in: 'path', 51 | required: false, 52 | type: 'string', 53 | }, 54 | ]; 55 | const expected = [ 56 | { 57 | name: 'date_from', 58 | in: 'query', 59 | required: false, 60 | type: 'string', 61 | format: 'date-time', 62 | }, 63 | { 64 | name: 'amount', 65 | in: 'path', 66 | required: false, 67 | type: 'integer', 68 | }, 69 | { 70 | name: 'date_to', 71 | in: 'query', 72 | required: false, 73 | type: 'string', 74 | format: 'date-time', 75 | }, 76 | { 77 | name: 'id', 78 | in: 'path', 79 | type: 'integer', 80 | required: true, 81 | }, 82 | { 83 | name: 'id', 84 | in: 'query', 85 | required: true, 86 | type: 'string', 87 | }, 88 | { 89 | name: 'firstName', 90 | in: 'path', 91 | required: false, 92 | type: 'string', 93 | }, 94 | ]; 95 | const result = merge(a, b, 'in', 'name'); 96 | 97 | t.equal(result.length, 6); 98 | t.deepEqual(result, expected); 99 | t.end(); 100 | }); 101 | -------------------------------------------------------------------------------- /dist/requests/process-params.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.parameterToSchema = exports.processParams = void 0; 4 | /** 5 | * Processing of custom types from `paths` section 6 | * in the schema 7 | */ 8 | const _ = require("lodash"); 9 | const common_1 = require("../common"); 10 | const utils_1 = require("../utils"); 11 | /** 12 | * Transforms input parameters to interfaces definition 13 | * @param def definition 14 | * @param paramsType name of the type 15 | */ 16 | function processParams(def, paramsType) { 17 | let paramDef = ''; 18 | let typesOnly = ''; 19 | paramDef += `export interface ${paramsType} {\n`; 20 | const params = _.map(def, p => (0, common_1.processProperty)(parameterToSchema(p), p.name, paramsType, p.required)[0]); 21 | const isInterfaceEmpty = !params.length; 22 | const usesGlobalType = params.some(p => !p.native); 23 | paramDef += (0, utils_1.indent)(_.map(params, 'property')); 24 | paramDef += `\n`; 25 | paramDef += `}\n`; 26 | const enums = _.map(params, 'enumDeclaration').filter(Boolean); 27 | if (enums.length) { 28 | paramDef += `\n`; 29 | paramDef += enums.join('\n\n'); 30 | paramDef += `\n`; 31 | } 32 | params.sort((p1, p2) => (p1.isRequired ? 0 : 1) - (p2.isRequired ? 0 : 1)); 33 | typesOnly = params.map(p => p.propertyAsMethodParameter).join(', '); 34 | return { paramDef, typesOnly, usesGlobalType, isInterfaceEmpty }; 35 | } 36 | exports.processParams = processParams; 37 | // TODO! use required array to set the variable 38 | // TODO might be unnecessary for v3.0+ of OpenAPI spec 39 | // https://swagger.io/specification/#parameterObject 40 | function parameterToSchema(param) { 41 | return { 42 | ...{ 43 | allowEmptyValue: param.allowEmptyValue, 44 | default: param.default, 45 | description: param.description, 46 | enum: param.enum, 47 | format: param.format, 48 | items: param.items, 49 | maximum: param.maximum, 50 | maxLength: param.maxLength, 51 | minimum: param.minimum, 52 | minLength: param.minLength, 53 | pattern: param.pattern, 54 | type: param.type, 55 | uniqueItems: param.uniqueItems, 56 | }, 57 | ...param.schema, // move level up 58 | }; 59 | } 60 | exports.parameterToSchema = parameterToSchema; 61 | //# sourceMappingURL=process-params.js.map -------------------------------------------------------------------------------- /src/requests/process-responses.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Processing of custom types from `paths` section 3 | * in the schema 4 | */ 5 | import * as _ from 'lodash'; 6 | 7 | import * as fs from 'fs'; 8 | import * as path from 'path'; 9 | import {processProperty, PropertyOutput} from '../common'; 10 | import * as conf from '../conf'; 11 | import {createExport, processDefinition, ProcessedDefinition} from '../definitions'; 12 | import {Config} from '../generate'; 13 | import {HttpCode, HttpResponse, Schema} from '../types'; 14 | 15 | /** 16 | * Process all responses of one method 17 | * @param httpResponse response object 18 | * @param name of the context for type name uniqueness 19 | * @param config global config 20 | */ 21 | export function processResponses(httpResponse: HttpResponse, name: string, config: Config) { 22 | const responses = _.filter(httpResponse, (r, status: HttpCode) => ( 23 | r.schema && Math.floor(Number(status) / 100) === 2)); 24 | let properties: PropertyOutput[] = []; 25 | 26 | for (const response of responses) { 27 | if (response.schema && response.schema.properties) { 28 | const processedDefinition = processNestedSchemaDefinition(response.schema, name, config); 29 | const propertyOutput: PropertyOutput = { 30 | property: `__model.${processedDefinition.name}`, 31 | propertyAsMethodParameter: '', 32 | enumDeclaration: undefined, 33 | native: false, 34 | isRequired: false, 35 | }; 36 | properties.push(propertyOutput); 37 | } else { 38 | properties = properties.concat(processProperty(response.schema, undefined, name)); 39 | } 40 | } 41 | 42 | const property = _.map(properties, 'property'); 43 | const enumDeclaration = _.map(properties, 'enumDeclaration').filter(Boolean).join('\n\n'); 44 | const usesGlobalType = properties.some(p => !p.native); 45 | 46 | let type: string; 47 | if (property.length) { 48 | type = _.uniqWith(property, _.isEqual).join(' | '); 49 | } else { 50 | type = 'void'; 51 | } 52 | 53 | return {type, enumDeclaration, usesGlobalType}; 54 | } 55 | 56 | function processNestedSchemaDefinition(schema: Schema, name: string, config: Config): ProcessedDefinition { 57 | const processedDef = processDefinition(schema, `${name}GeneratedInlineModel`, config); 58 | const filename = path.join(config.dest, `${conf.modelFile}.ts`); 59 | const exportDefiniton = createExport(processedDef.name); 60 | fs.appendFileSync(filename, `${exportDefiniton}\n`); 61 | 62 | return processedDef; 63 | } 64 | --------------------------------------------------------------------------------