1
1
/*
2
+ * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3
+ *
2
4
* Licensed under the Apache License, Version 2.0 (the "License");
3
5
* you may not use this file except in compliance with the License.
4
6
* You may obtain a copy of the License at
@@ -66,7 +68,7 @@ public ScalaHttp4sServerCodegen() {
66
68
supportsMultipleInheritance = true ;
67
69
supportsInheritance = true ;
68
70
supportsMixins = true ;
69
- addOneOfInterfaceImports =true ;
71
+ addOneOfInterfaceImports = true ;
70
72
71
73
72
74
setReservedWordsLowerCase (
@@ -141,7 +143,6 @@ public ScalaHttp4sServerCodegen() {
141
143
additionalProperties .put ("licenseUrl" , "http://apache.org/licenses/LICENSE-2.0.html" );
142
144
143
145
144
-
145
146
languageSpecificPrimitives = new HashSet <>(
146
147
Arrays .asList (
147
148
"String" ,
@@ -197,6 +198,7 @@ public ScalaHttp4sServerCodegen() {
197
198
}
198
199
199
200
private final static Map <String , String > locationStatusToResponse = new HashMap <>();
201
+
200
202
static {
201
203
locationStatusToResponse .put ("300" , "MultipleChoices" );
202
204
locationStatusToResponse .put ("301" , "MovedPermanently" );
@@ -207,16 +209,19 @@ public ScalaHttp4sServerCodegen() {
207
209
}
208
210
209
211
private final static Map <String , String > wwwAuthStatusToResponse = new HashMap <>();
212
+
210
213
static {
211
214
wwwAuthStatusToResponse .put ("401" , "Unauthorized" );
212
215
}
213
216
214
217
private final static Map <String , String > allowStatusToResponse = new HashMap <>();
218
+
215
219
static {
216
220
allowStatusToResponse .put ("405" , "MethodNotAllowed" );
217
221
}
218
222
219
223
private final static Map <String , String > proxyAuthStatusToResponse = new HashMap <>();
224
+
220
225
static {
221
226
proxyAuthStatusToResponse .put ("407" , "ProxyAuthenticationRequired" );
222
227
}
@@ -314,7 +319,7 @@ public void processOpts() {
314
319
315
320
apiTemplateFiles .put ("api.mustache" , ".scala" );
316
321
317
- if (!additionalProperties .containsKey (EXCLUDE_SBT ) && !Boolean .parseBoolean ((String )additionalProperties .get (EXCLUDE_SBT ))) {
322
+ if (!additionalProperties .containsKey (EXCLUDE_SBT ) && !Boolean .parseBoolean ((String ) additionalProperties .get (EXCLUDE_SBT ))) {
318
323
supportingFiles .add (new SupportingFile ("build.sbt" , "" , "build.sbt" ));
319
324
supportingFiles .add (new SupportingFile ("build.properties" , "project" , "build.properties" ));
320
325
}
@@ -328,18 +333,18 @@ public Map<String, String> inlineSchemaOption() {
328
333
329
334
@ Override
330
335
public boolean isEnablePostProcessFile () {
331
- return true ;
336
+ return true ;
332
337
}
333
338
334
339
@ Override
335
340
public void postProcessFile (File file , String fileType ) {
336
- System . out . println ("postprocess " + file .toString ());
341
+ LOGGER . debug ("postprocess " + file .toString ());
337
342
super .postProcessFile (file , fileType );
338
343
}
339
344
340
345
@ Override
341
346
public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > objs ) {
342
- Map <String , ModelsMap > modelsMap = super .postProcessAllModels (objs );
347
+ Map <String , ModelsMap > modelsMap = super .postProcessAllModels (objs );
343
348
344
349
for (ModelsMap mm : modelsMap .values ()) {
345
350
for (ModelMap model : mm .getModels ()) {
@@ -367,7 +372,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
367
372
368
373
// add refined constraints
369
374
370
- for (CodegenProperty prop : cModel .vars ) {
375
+ for (CodegenProperty prop : cModel .vars ) {
371
376
Set <String > imports = new TreeSet <>();
372
377
373
378
prop .getVendorExtensions ().putAll (refineProp (prop , imports ));
@@ -389,8 +394,8 @@ private Map<String, Object> makeRefiined(Set<String> imports, String dataType, A
389
394
390
395
vendorExtensions .put ("x-type" , "Refined[" + dataType + ", " + refinedRgt + "]" );
391
396
vendorExtensions .put ("x-refined-lft" , dataType );
392
- vendorExtensions .put ("x-refined-rgt" , refinedRgt );
393
- vendorExtensions .put ("x-refined" , true );
397
+ vendorExtensions .put ("x-refined-rgt" , refinedRgt );
398
+ vendorExtensions .put ("x-refined" , true );
394
399
} else {
395
400
vendorExtensions .put ("x-type" , dataType );
396
401
}
@@ -407,8 +412,8 @@ private Map<String, Object> refineProp(IJsonSchemaValidationProperties prop, Set
407
412
ArrayList <String > refined = new ArrayList <>();
408
413
409
414
if (prop .getMinLength () != null ) {
410
- refined .add ("MinSize[" + prop .getMinLength () + "]" );
411
- imports .add ("MinSize" );
415
+ refined .add ("MinSize[" + prop .getMinLength () + "]" );
416
+ imports .add ("MinSize" );
412
417
}
413
418
if (prop .getMaxLength () != null ) {
414
419
refined .add ("MaxSize[" + prop .getMaxLength () + "]" );
@@ -485,7 +490,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
485
490
486
491
List <ModelMap > models = (List <ModelMap >) bundle .get ("models" );
487
492
TreeSet <String > allImports = new TreeSet <>();
488
- for (ModelMap mm : models ) {
493
+ for (ModelMap mm : models ) {
489
494
for (String nextImport : mm .getModel ().imports ) {
490
495
String mapping = importMapping ().get (nextImport );
491
496
if (mapping != null && !defaultIncludes ().contains (mapping )) {
@@ -504,9 +509,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
504
509
505
510
ApiInfoMap apiInfoMap = (ApiInfoMap ) bundle .get ("apiInfo" );
506
511
Map <String , List <String >> authToOperationMap = new TreeMap <>();
507
- for (OperationsMap op : apiInfoMap .getApis ()) {
512
+ for (OperationsMap op : apiInfoMap .getApis ()) {
508
513
List <HashMap <String , Object >> opsByAuth = (List <HashMap <String , Object >>) op .get ("operationsByAuth" );
509
- for (HashMap <String , Object > auth : opsByAuth ) {
514
+ for (HashMap <String , Object > auth : opsByAuth ) {
510
515
String autName = (String ) auth .get ("auth" );
511
516
String classname = (String ) op .get ("classname" );
512
517
List <String > classnames = authToOperationMap .computeIfAbsent (autName , k -> new ArrayList <>());
@@ -549,7 +554,7 @@ public String escapeReservedWord(String name) {
549
554
550
555
@ Override
551
556
public String apiFileFolder () {
552
- return outputFolder + File .separator + apiFileFolderRelative () ;
557
+ return outputFolder + File .separator + apiFileFolderRelative ();
553
558
}
554
559
555
560
private String apiFileFolderRelative () {
@@ -599,7 +604,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objsI, List<M
599
604
}
600
605
601
606
// decide wat methods do we need in responses:
602
- for (CodegenResponse resp : op .responses ) {
607
+ for (CodegenResponse resp : op .responses ) {
603
608
if (resp .code .equals ("0" ))
604
609
resp .code = "200" ; // 200 by default
605
610
@@ -649,11 +654,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objsI, List<M
649
654
}
650
655
651
656
if (op .authMethods != null ) {
652
- for (CodegenSecurity cs : op .authMethods ) {
657
+ for (CodegenSecurity cs : op .authMethods ) {
653
658
allAuth .add (cs .name );
654
659
}
655
660
List <Map <String , Object >> authDup = new ArrayList <>();
656
- for (CodegenSecurity authMeth : op .authMethods ) {
661
+ for (CodegenSecurity authMeth : op .authMethods ) {
657
662
Map <String , Object > vals = new HashMap <>();
658
663
vals .put ("authName" , authMeth .name );
659
664
vals .put ("operation" , op );
@@ -781,7 +786,7 @@ private void generateScalaPath(CodegenOperation op) {
781
786
op .imports .addAll (imports );
782
787
}
783
788
784
- private String cpToPathParameter (CodegenParameter cp , Set <String > imports , Map <String , Object > vendorExtensions ) {
789
+ private String cpToPathParameter (CodegenParameter cp , Set <String > imports , Map <String , Object > vendorExtensions ) {
785
790
// don't support containers and arrays yet, reset to string
786
791
if (cp .isContainer || cp .isArray ) {
787
792
cp .setDataType ("String" );
@@ -809,20 +814,20 @@ private void generateQueryParameters(CodegenOperation op) {
809
814
String queryString = "" ;
810
815
811
816
for (CodegenParameter cp : op .queryParams ) {
812
- if (queryString .isEmpty ()) {
813
- queryString = queryString + " :? " ;
814
- } else {
815
- queryString = queryString + " +& " ;
816
- }
817
+ if (queryString .isEmpty ()) {
818
+ queryString = queryString + " :? " ;
819
+ } else {
820
+ queryString = queryString + " +& " ;
821
+ }
817
822
818
- queryString = queryString + cpToQueryParameter (cp , imports , cp .vendorExtensions );
823
+ queryString = queryString + cpToQueryParameter (cp , imports , cp .vendorExtensions );
819
824
}
820
825
821
826
op .vendorExtensions .put ("x-codegen-query" , queryString );
822
827
op .imports .addAll (imports );
823
828
}
824
829
825
- private String cpToQueryParameter (CodegenParameter cp , Set <String > imports , Map <String , Object > vendorExtensions ) {
830
+ private String cpToQueryParameter (CodegenParameter cp , Set <String > imports , Map <String , Object > vendorExtensions ) {
826
831
// don't support containers and arrays yet, reset to string
827
832
if (cp .isContainer && !cp .isArray ) {
828
833
cp .setDataType ("String" );
@@ -848,5 +853,7 @@ public void postProcess() {
848
853
}
849
854
850
855
@ Override
851
- public GeneratorLanguage generatorLanguage () { return GeneratorLanguage .SCALA ; }
856
+ public GeneratorLanguage generatorLanguage () {
857
+ return GeneratorLanguage .SCALA ;
858
+ }
852
859
}
0 commit comments