@@ -3812,18 +3812,18 @@ protected void updateComponentsFilepath(String[] pathPieces) {
3812
3812
}
3813
3813
}
3814
3814
3815
- private void updatePathsFilepath (String [] pathPieces ) {
3815
+ private String [] updatePathsFilepath (String [] pathPieces ) {
3816
3816
String [] originalPieces = pathPieces .clone ();
3817
3817
originalPieces [0 ] = "#" ;
3818
3818
String jsonPath = String .join ("/" , originalPieces );
3819
3819
if (pathPieces .length < 3 ) {
3820
- return ;
3820
+ return pathPieces ;
3821
3821
}
3822
3822
// #/paths/somePath
3823
3823
String path = pathPieces [2 ];
3824
3824
pathPieces [2 ] = toPathFilename (ModelUtils .decodeSlashes (pathPieces [2 ]), null );
3825
3825
if (pathPieces .length < 4 ) {
3826
- return ;
3826
+ return pathPieces ;
3827
3827
}
3828
3828
Set <String > xParameters = new HashSet <>();
3829
3829
xParameters .add ("PathParameters" );
@@ -3842,11 +3842,11 @@ private void updatePathsFilepath(String[] pathPieces) {
3842
3842
pathPieces [4 ] = "server" + pathPieces [4 ];
3843
3843
pathPieces [5 ] = "Variables" ;
3844
3844
}
3845
- return ;
3845
+ return pathPieces ;
3846
3846
} else if (pathPieces [3 ].equals ("parameters" )) {
3847
3847
if (pathPieces .length == 4 ) {
3848
3848
// #/paths/somePath/parameters
3849
- return ;
3849
+ return pathPieces ;
3850
3850
}
3851
3851
// #/paths/somePath/parameters/0
3852
3852
pathPieces [4 ] = toParameterFilename (pathPieces [4 ], null );
@@ -3856,16 +3856,16 @@ private void updatePathsFilepath(String[] pathPieces) {
3856
3856
pathPieces [6 ] = toContentTypeFilename (contentType );
3857
3857
if (pathPieces .length == 8 ) {
3858
3858
pathPieces [7 ] = getSchemaFilename (jsonPath );
3859
- return ;
3859
+ return pathPieces ;
3860
3860
}
3861
3861
} else if (pathPieces .length == 6 && pathPieces [5 ].equals ("schema" )) {
3862
3862
// #/paths/somePath/parameters/0/schema -> length 7
3863
3863
pathPieces [5 ] = getSchemaFilename (jsonPath );
3864
- return ;
3864
+ return pathPieces ;
3865
3865
}
3866
3866
} else if (pathPieces .length == 4 ) {
3867
3867
// #/paths/SomePath/get
3868
- return ;
3868
+ return pathPieces ;
3869
3869
}
3870
3870
if (pathPieces [4 ].equals ("requestBody" )) {
3871
3871
// #/paths/somePath/get/requestBody
@@ -3895,11 +3895,11 @@ private void updatePathsFilepath(String[] pathPieces) {
3895
3895
// #/paths/somePath/get/security/0
3896
3896
pathPieces [5 ] = toSecurityRequirementObjectFilename (pathPieces [5 ], jsonPath );
3897
3897
}
3898
- return ;
3898
+ return pathPieces ;
3899
3899
} else if (pathPieces [4 ].equals ("responses" )) {
3900
3900
if (pathPieces .length < 6 ) {
3901
3901
// #/paths/user_login/get/responses -> length 5
3902
- return ;
3902
+ return pathPieces ;
3903
3903
}
3904
3904
// #/paths/user_login/get/responses/200 -> 200 -> response_200 -> length 6
3905
3905
String responseJsonPath = "#/paths/" + path + "/" + pathPieces [3 ] + "/responses/" + pathPieces [5 ];
@@ -3908,11 +3908,11 @@ private void updatePathsFilepath(String[] pathPieces) {
3908
3908
// synthetic json path
3909
3909
// #/paths/user_login/get/responses/200/Headers
3910
3910
pathPieces [6 ] = getSchemaFilename (jsonPath );
3911
- return ;
3911
+ return pathPieces ;
3912
3912
}
3913
3913
3914
3914
if (pathPieces .length < 8 ) {
3915
- return ;
3915
+ return pathPieces ;
3916
3916
}
3917
3917
if (pathPieces [6 ].equals ("content" )) {
3918
3918
// #/paths/somePath/get/responses/200/content/application-json -> length 8
@@ -3938,7 +3938,7 @@ private void updatePathsFilepath(String[] pathPieces) {
3938
3938
}
3939
3939
} else if (pathPieces [4 ].equals ("parameters" )) {
3940
3940
if (pathPieces .length == 5 ) {
3941
- return ;
3941
+ return pathPieces ;
3942
3942
}
3943
3943
// #/paths/somePath/get/parameters/0 -> length 6
3944
3944
pathPieces [5 ] = toParameterFilename (pathPieces [5 ], null );
@@ -3965,6 +3965,7 @@ private void updatePathsFilepath(String[] pathPieces) {
3965
3965
}
3966
3966
}
3967
3967
}
3968
+ return pathPieces ;
3968
3969
}
3969
3970
3970
3971
protected void updateServersFilepath (String [] pathPieces ) {
@@ -3981,15 +3982,17 @@ protected void updateServersFilepath(String[] pathPieces) {
3981
3982
}
3982
3983
}
3983
3984
3984
- private void updateSecurityFilepath (String [] pathPieces ) {
3985
+ protected String [] updateSecurityFilepath (String [] pathPieces ) {
3986
+ List <String > finalPathPieces = Arrays .asList (pathPieces );
3985
3987
String jsonPath = String .join ("/" , pathPieces );
3986
3988
if (pathPieces .length < 3 ) {
3987
3989
// #/security
3988
- pathPieces [ 1 ] = toSecurityFilename ("" , jsonPath );
3989
- return ;
3990
+ finalPathPieces . set ( 1 , toSecurityFilename ("" , jsonPath ) );
3991
+ return finalPathPieces . toArray ( String []:: new ) ;
3990
3992
}
3991
3993
// #/security/0
3992
- pathPieces [2 ] = toSecurityRequirementObjectFilename (pathPieces [2 ], jsonPath );
3994
+ finalPathPieces .set (2 , toSecurityRequirementObjectFilename (pathPieces [2 ], jsonPath ));
3995
+ return finalPathPieces .toArray (String []::new );
3993
3996
}
3994
3997
3995
3998
private void updateApisFilepath (String [] pathPieces ) {
@@ -4013,19 +4016,25 @@ private void updateApisFilepath(String[] pathPieces) {
4013
4016
public String getFilepath (String jsonPath ) {
4014
4017
String [] pathPieces = jsonPath .split ("/" );
4015
4018
pathPieces [0 ] = outputFolder + File .separatorChar + packagePath ();
4019
+ String [] usedPathPieces ;
4016
4020
if (jsonPath .startsWith ("#/components" )) {
4017
4021
updateComponentsFilepath (pathPieces );
4022
+ usedPathPieces = pathPieces ;
4018
4023
} else if (jsonPath .startsWith ("#/paths" )) {
4019
- updatePathsFilepath (pathPieces );
4024
+ usedPathPieces = updatePathsFilepath (pathPieces );
4020
4025
} else if (jsonPath .startsWith ("#/servers" )) {
4021
4026
updateServersFilepath (pathPieces );
4027
+ usedPathPieces = pathPieces ;
4022
4028
} else if (jsonPath .startsWith ("#/security" )) {
4023
- updateSecurityFilepath (pathPieces );
4029
+ usedPathPieces = updateSecurityFilepath (pathPieces );
4024
4030
} else if (jsonPath .startsWith ("#/apis" )) {
4025
4031
// this is a fake json path that the code generates and uses to generate apis
4026
4032
updateApisFilepath (pathPieces );
4033
+ usedPathPieces = pathPieces ;
4034
+ } else {
4035
+ throw new RuntimeException ("invalid jsonpath value" );
4027
4036
}
4028
- List <String > finalPathPieces = Arrays .stream (pathPieces )
4037
+ List <String > finalPathPieces = Arrays .stream (usedPathPieces )
4029
4038
.filter (Objects ::nonNull )
4030
4039
.collect (Collectors .toList ());
4031
4040
return String .join (File .separator , finalPathPieces );
@@ -4035,19 +4044,25 @@ public String getFilepath(String jsonPath) {
4035
4044
public String getSubpackage (String jsonPath ) {
4036
4045
String [] pathPieces = jsonPath .split ("/" );
4037
4046
pathPieces [0 ] = "" ;
4047
+ String [] usedPathPieces ;
4038
4048
if (jsonPath .startsWith ("#/components" )) {
4039
4049
updateComponentsFilepath (pathPieces );
4050
+ usedPathPieces = pathPieces ;
4040
4051
} else if (jsonPath .startsWith ("#/paths" )) {
4041
- updatePathsFilepath (pathPieces );
4052
+ usedPathPieces = updatePathsFilepath (pathPieces );
4042
4053
} else if (jsonPath .startsWith ("#/servers" )) {
4043
4054
updateServersFilepath (pathPieces );
4055
+ usedPathPieces = pathPieces ;
4044
4056
} else if (jsonPath .startsWith ("#/security" )) {
4045
- updateSecurityFilepath (pathPieces );
4057
+ usedPathPieces = updateSecurityFilepath (pathPieces );
4046
4058
} else if (jsonPath .startsWith ("#/apis" )) {
4047
4059
// this is a fake json path that the code generates and uses to generate apis
4048
4060
updateApisFilepath (pathPieces );
4061
+ usedPathPieces = pathPieces ;
4062
+ } else {
4063
+ throw new RuntimeException ("invalid value for jsonPath" );
4049
4064
}
4050
- List <String > finalPathPieces = Arrays .stream (pathPieces )
4065
+ List <String > finalPathPieces = Arrays .stream (usedPathPieces )
4051
4066
.filter (Objects ::nonNull )
4052
4067
.collect (Collectors .toList ());
4053
4068
String subpackage = String .join ("." , finalPathPieces );
@@ -4061,22 +4076,26 @@ public String getSubpackage(String jsonPath) {
4061
4076
public String getTestFilepath (String jsonPath ) {
4062
4077
String [] pathPieces = jsonPath .split ("/" );
4063
4078
pathPieces [0 ] = outputFolder + File .separatorChar + "test" ;
4079
+ String [] usedPathPieces ;
4064
4080
if (jsonPath .startsWith ("#/components" )) {
4065
4081
// #/components/schemas/someSchema
4066
4082
updateComponentsFilepath (pathPieces );
4067
4083
if (pathPieces .length == 4 ) {
4068
4084
int lastIndex = pathPieces .length - 1 ;
4069
4085
pathPieces [lastIndex ] = "test_" + pathPieces [lastIndex ];
4070
4086
}
4087
+ usedPathPieces = pathPieces ;
4071
4088
} else if (jsonPath .startsWith ("#/paths" )) {
4072
- updatePathsFilepath (pathPieces );
4089
+ usedPathPieces = updatePathsFilepath (pathPieces );
4073
4090
// #/paths/somePath/get
4074
4091
if (pathPieces .length == 4 ) {
4075
4092
int lastIndex = pathPieces .length - 1 ;
4076
- pathPieces [lastIndex ] = "test_" + pathPieces [lastIndex ];
4093
+ usedPathPieces [lastIndex ] = "test_" + pathPieces [lastIndex ];
4077
4094
}
4095
+ } else {
4096
+ throw new RuntimeException ("Invalid value for jsonPath" );
4078
4097
}
4079
- List <String > finalPathPieces = Arrays .stream (pathPieces )
4098
+ List <String > finalPathPieces = Arrays .stream (usedPathPieces )
4080
4099
.filter (Objects ::nonNull )
4081
4100
.collect (Collectors .toList ());
4082
4101
return String .join (File .separator , finalPathPieces );
@@ -4087,17 +4106,23 @@ public String getTestFilepath(String jsonPath) {
4087
4106
public String getDocsFilepath (String jsonPath ) {
4088
4107
String [] pathPieces = jsonPath .split ("/" );
4089
4108
pathPieces [0 ] = outputFolder + File .separatorChar + docsFolder ;
4109
+ String [] usedPathPieces ;
4090
4110
if (jsonPath .startsWith ("#/components" )) {
4091
4111
updateComponentsFilepath (pathPieces );
4112
+ usedPathPieces = pathPieces ;
4092
4113
} else if (jsonPath .startsWith ("#/paths" )) {
4093
- updatePathsFilepath (pathPieces );
4114
+ usedPathPieces = updatePathsFilepath (pathPieces );
4094
4115
} else if (jsonPath .startsWith ("#/servers" )) {
4095
4116
updateServersFilepath (pathPieces );
4117
+ usedPathPieces = pathPieces ;
4096
4118
} else if (jsonPath .startsWith ("#/apis" )) {
4097
4119
// this is a fake json path that the code generates and uses to generate apis
4098
4120
updateApisFilepath (pathPieces );
4121
+ usedPathPieces = pathPieces ;
4122
+ } else {
4123
+ throw new RuntimeException ("invalid json path" );
4099
4124
}
4100
- List <String > finalPathPieces = Arrays .stream (pathPieces )
4125
+ List <String > finalPathPieces = Arrays .stream (usedPathPieces )
4101
4126
.filter (Objects ::nonNull )
4102
4127
.collect (Collectors .toList ());
4103
4128
return String .join (File .separator , finalPathPieces );
0 commit comments