|
8 | 8 | import io.swagger.v3.oas.models.headers.Header; |
9 | 9 | import io.swagger.v3.oas.models.links.Link; |
10 | 10 | import io.swagger.v3.oas.models.media.ArraySchema; |
| 11 | +import io.swagger.v3.oas.models.media.ComposedSchema; |
11 | 12 | import io.swagger.v3.oas.models.media.Schema; |
12 | 13 | import io.swagger.v3.oas.models.parameters.Parameter; |
13 | 14 | import io.swagger.v3.oas.models.parameters.RequestBody; |
@@ -83,64 +84,88 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) { |
83 | 84 |
|
84 | 85 | String file = $ref.split("#/")[0]; |
85 | 86 | if (schema.get$ref() != null) { |
86 | | - RefFormat format = computeRefFormat(schema.get$ref()); |
87 | | - if (isAnExternalRefFormat(format)) { |
88 | | - schema.set$ref(processRefToExternalSchema(schema.get$ref(), format)); |
89 | | - } else { |
90 | | - processRefToExternalSchema(file + schema.get$ref(), RefFormat.RELATIVE); |
| 87 | + processRefSchema(schema,file); |
| 88 | + } |
| 89 | + |
| 90 | + if(schema instanceof ComposedSchema){ |
| 91 | + ComposedSchema composedSchema = (ComposedSchema) schema; |
| 92 | + if (composedSchema.getAllOf() != null){ |
| 93 | + for(Schema item : composedSchema.getAllOf()){ |
| 94 | + if (item.get$ref() != null){ |
| 95 | + processRefSchema(item,file); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + }else if (composedSchema.getOneOf() != null){ |
| 100 | + for(Schema item : composedSchema.getOneOf()){ |
| 101 | + if (item.get$ref() != null){ |
| 102 | + if (item.get$ref() != null){ |
| 103 | + processRefSchema(item,file); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + }else if (composedSchema.getAnyOf() != null){ |
| 108 | + for(Schema item : composedSchema.getAnyOf()){ |
| 109 | + if (item.get$ref() != null){ |
| 110 | + if (item.get$ref() != null){ |
| 111 | + processRefSchema(item,file); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
91 | 116 | } |
92 | 117 | } |
93 | 118 | //Loop the properties and recursively call this method; |
94 | 119 | Map<String, Schema> subProps = schema.getProperties(); |
95 | 120 | if (subProps != null) { |
96 | 121 | for (Map.Entry<String, Schema> prop : subProps.entrySet()) { |
97 | 122 | if (prop.getValue().get$ref() != null) { |
98 | | - processRefProperty(prop.getValue(), file); |
| 123 | + processRefSchema(prop.getValue(), file); |
99 | 124 | } else if (prop.getValue() instanceof ArraySchema) { |
100 | 125 | ArraySchema arrayProp = (ArraySchema) prop.getValue(); |
101 | 126 | if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null && |
102 | 127 | StringUtils.isNotBlank(arrayProp.get$ref())) { |
103 | | - processRefProperty(arrayProp.getItems(), file); |
| 128 | + processRefSchema(arrayProp.getItems(), file); |
104 | 129 | } |
105 | 130 | } else if (prop.getValue().getAdditionalProperties() != null && prop.getValue().getAdditionalProperties() instanceof Schema) { |
106 | 131 | Schema mapProp = (Schema) prop.getValue().getAdditionalProperties(); |
107 | 132 | if (mapProp.get$ref() != null) { |
108 | | - processRefProperty(mapProp, file); |
| 133 | + processRefSchema(mapProp, file); |
109 | 134 | } else if (mapProp.getAdditionalProperties() instanceof ArraySchema && |
110 | 135 | ((ArraySchema) mapProp).getItems()!= null && |
111 | 136 | ((ArraySchema) mapProp).getItems().get$ref() != null |
112 | 137 | && StringUtils.isNotBlank(((ArraySchema) mapProp).getItems().get$ref())) { |
113 | | - processRefProperty(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file); |
| 138 | + processRefSchema(((ArraySchema) mapProp.getAdditionalProperties()).getItems(), file); |
114 | 139 | } |
115 | 140 | } |
116 | 141 | } |
117 | 142 | } |
118 | 143 | if(schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema){ |
119 | 144 | Schema additionalProperty = (Schema) schema.getAdditionalProperties(); |
120 | 145 | if (additionalProperty.get$ref() != null) { |
121 | | - processRefProperty(additionalProperty, file); |
| 146 | + processRefSchema(additionalProperty, file); |
122 | 147 | } else if (additionalProperty instanceof ArraySchema) { |
123 | 148 | ArraySchema arrayProp = (ArraySchema) additionalProperty; |
124 | 149 | if (arrayProp.getItems() != null && arrayProp.getItems().get$ref() != null && |
125 | 150 | StringUtils.isNotBlank(arrayProp.get$ref())) { |
126 | | - processRefProperty(arrayProp.getItems(), file); |
| 151 | + processRefSchema(arrayProp.getItems(), file); |
127 | 152 | } |
128 | 153 | } else if (additionalProperty.getAdditionalProperties() != null && additionalProperty.getAdditionalProperties() instanceof Schema) { |
129 | 154 | Schema mapProp = (Schema) additionalProperty.getAdditionalProperties(); |
130 | 155 | if (mapProp.get$ref() != null) { |
131 | | - processRefProperty(mapProp, file); |
| 156 | + processRefSchema(mapProp, file); |
132 | 157 | } else if (mapProp.getAdditionalProperties() instanceof ArraySchema && |
133 | 158 | ((ArraySchema) mapProp).getItems() != null && |
134 | 159 | ((ArraySchema) mapProp).getItems().get$ref() != null |
135 | 160 | && StringUtils.isNotBlank(((ArraySchema) mapProp).getItems().get$ref())) { |
136 | | - processRefProperty(((ArraySchema) mapProp).getItems(), file); |
| 161 | + processRefSchema(((ArraySchema) mapProp).getItems(), file); |
137 | 162 | } |
138 | 163 | } |
139 | 164 |
|
140 | 165 | } |
141 | 166 | if (schema instanceof ArraySchema && ((ArraySchema) schema).getItems() != null && ((ArraySchema) schema).getItems().get$ref() != null |
142 | 167 | && StringUtils.isNotBlank(((ArraySchema) schema).getItems().get$ref())) { |
143 | | - processRefProperty(((ArraySchema) schema).getItems(), file); |
| 168 | + processRefSchema(((ArraySchema) schema).getItems(), file); |
144 | 169 | } |
145 | 170 | } |
146 | 171 |
|
@@ -614,7 +639,7 @@ public String processRefToExternalCallback(String $ref, RefFormat refFormat) { |
614 | 639 | } |
615 | 640 |
|
616 | 641 |
|
617 | | - private void processRefProperty(Schema subRef, String externalFile) { |
| 642 | + private void processRefSchema(Schema subRef, String externalFile) { |
618 | 643 | RefFormat format = computeRefFormat(subRef.get$ref()); |
619 | 644 | if (isAnExternalRefFormat(format)) { |
620 | 645 | String $ref = constructRef(subRef, externalFile); |
|
0 commit comments