@@ -4,118 +4,132 @@ import { libraryGenerator } from '@nrwl/js';
44
55import generator from './generator' ;
66
7- const MOCK_SWAGGER_JSON = `{
8- "openapi": "3.0.1",
9- "info": {
10- "title": "NxDotnet.Test.Webapi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
11- "version": "1.0"
12- },
13- "paths": {
14- "/WeatherForecast": {
15- "get": {
16- "tags": [
17- "WeatherForecast"
18- ],
19- "operationId": "GetWeatherForecast",
20- "responses": {
21- "200": {
22- "description": "Success",
23- "content": {
24- "text/plain": {
25- "schema": {
26- "type": "array",
27- "items": {
28- "$ref": "#/components/schemas/WeatherForecast"
29- }
30- }
31- },
32- "application/json": {
33- "schema": {
34- "type": "array",
35- "items": {
36- "$ref": "#/components/schemas/WeatherForecast"
37- }
38- }
7+ const MOCK_SWAGGER_JSON = JSON . stringify (
8+ {
9+ openapi : '3.0.1' ,
10+ info : {
11+ title :
12+ 'NxDotnet.Test.Webapi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ,
13+ version : '1.0' ,
14+ } ,
15+ paths : {
16+ '/WeatherForecast' : {
17+ get : {
18+ tags : [ 'WeatherForecast' ] ,
19+ operationId : 'GetWeatherForecast' ,
20+ responses : {
21+ '200' : {
22+ description : 'Success' ,
23+ content : {
24+ 'text/plain' : {
25+ schema : {
26+ type : 'array' ,
27+ items : {
28+ $ref : '#/components/schemas/WeatherForecast' ,
29+ } ,
30+ } ,
31+ } ,
32+ 'application/json' : {
33+ schema : {
34+ type : 'array' ,
35+ items : {
36+ $ref : '#/components/schemas/WeatherForecast' ,
37+ } ,
38+ } ,
39+ } ,
40+ 'text/json' : {
41+ schema : {
42+ type : 'array' ,
43+ items : {
44+ $ref : '#/components/schemas/WeatherForecast' ,
45+ } ,
46+ } ,
47+ } ,
3948 } ,
40- "text/json": {
41- "schema": {
42- "type": "array",
43- "items": {
44- "$ref": "#/components/schemas/WeatherForecast"
45- }
46- }
47- }
48- }
49- }
50- }
51- }
52- }
53- },
54- "components": {
55- "schemas": {
56- "Company": {
57- "type": "object",
58- "properties": {
59- "CEO": {
60- "$ref": "#/components/schemas/Person"
61- },
62- "employees": {
63- "type": "array",
64- "items": {
65- "$ref": "#/components/schemas/Person"
6649 } ,
67- "nullable": true
68- }
50+ } ,
6951 } ,
70- "additionalProperties": false
7152 } ,
72- "Person": {
73- "type": "object",
74- "properties": {
75- "employer": {
76- "$ref": "#/components/schemas/Company"
77- }
53+ } ,
54+ components : {
55+ schemas : {
56+ Company : {
57+ type : 'object' ,
58+ properties : {
59+ CEO : {
60+ $ref : '#/components/schemas/Person' ,
61+ } ,
62+ employees : {
63+ type : 'array' ,
64+ items : {
65+ $ref : '#/components/schemas/Person' ,
66+ } ,
67+ nullable : true ,
68+ } ,
69+ } ,
70+ additionalProperties : false ,
7871 } ,
79- "additionalProperties": false
80- },
81- "Temperature": {
82- "type": "object",
83- "properties": {
84- "temperatureC": {
85- "type": "integer",
86- "format": "int32"
72+ Person : {
73+ type : 'object' ,
74+ properties : {
75+ employer : {
76+ $ref : '#/components/schemas/Company' ,
77+ } ,
8778 } ,
88- "temperatureF": {
89- "type": "integer",
90- "format": "int32",
91- "readOnly": true
92- }
79+ additionalProperties : false ,
9380 } ,
94- "additionalProperties": false
95- },
96- "WeatherForecast": {
97- "type": "object",
98- "properties": {
99- "date": {
100- "type": "string",
101- "format": "date-time"
81+ Temperature : {
82+ type : 'object' ,
83+ properties : {
84+ temperatureC : {
85+ type : 'integer' ,
86+ format : 'int32' ,
87+ } ,
88+ temperatureF : {
89+ type : 'integer' ,
90+ format : 'int32' ,
91+ readOnly : true ,
92+ } ,
10293 } ,
103- "temperature": {
104- "$ref": "#/components/schemas/Temperature"
94+ additionalProperties : false ,
95+ } ,
96+ WeatherForecast : {
97+ type : 'object' ,
98+ properties : {
99+ date : {
100+ type : 'string' ,
101+ format : 'date-time' ,
102+ } ,
103+ temperature : {
104+ $ref : '#/components/schemas/Temperature' ,
105+ } ,
106+ summary : {
107+ type : 'string' ,
108+ nullable : true ,
109+ } ,
110+ forecaster : {
111+ $ref : '#/components/schemas/Person' ,
112+ } ,
105113 } ,
106- "summary": {
107- "type": "string",
108- "nullable": true
114+ additionalProperties : false ,
115+ } ,
116+ MyType : {
117+ type : 'object' ,
118+ properties : {
119+ id : {
120+ type : 'string' ,
121+ } ,
122+ children : {
123+ $ref : '#/components/schemas/MyType' ,
124+ } ,
109125 } ,
110- "forecaster": {
111- "$ref": "#/components/schemas/Person"
112- }
113126 } ,
114- "additionalProperties": false
115- }
116- }
117- }
118- }` ;
127+ } ,
128+ } ,
129+ } ,
130+ null ,
131+ 2 ,
132+ ) ;
119133
120134describe ( 'swagger-typescript generator' , ( ) => {
121135 let tree : Tree ;
@@ -154,6 +168,11 @@ describe('swagger-typescript generator', () => {
154168 'libs/generated-ts/src/interfaces/company.ts' ,
155169 tree ,
156170 ) ;
171+ expectFileToMatchSnapshot (
172+ 'libs/generated-ts/src/interfaces/my-type.ts' ,
173+ tree ,
174+ ) ;
175+
157176 expectFileToMatchSnapshot ( 'libs/generated-ts/src/index.ts' , tree ) ;
158177 } ) ;
159178} ) ;
0 commit comments