File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages
samples/client/petstore/ocaml-enum-in-composed-schema/src/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -295,11 +295,37 @@ public ModelsMap postProcessModels(ModelsMap objs) {
295295 }
296296 }
297297 }
298+
299+ // Fix enum references in composed schemas (anyOf, oneOf, allOf)
300+ if (cm .getComposedSchemas () != null ) {
301+ fixEnumReferencesInComposedSchemas (cm .getComposedSchemas ().getAnyOf ());
302+ fixEnumReferencesInComposedSchemas (cm .getComposedSchemas ().getOneOf ());
303+ fixEnumReferencesInComposedSchemas (cm .getComposedSchemas ().getAllOf ());
304+ }
298305 }
299306
300307 return objs ;
301308 }
302309
310+ private void fixEnumReferencesInComposedSchemas (List <CodegenProperty > schemas ) {
311+ if (schemas == null ) {
312+ return ;
313+ }
314+
315+ for (CodegenProperty schema : schemas ) {
316+ // If this schema is an enum, add Enums. prefix to datatypeWithEnum
317+ if (schema .isEnum ) {
318+ if (!schema .datatypeWithEnum .startsWith ("Enums." )) {
319+ schema .datatypeWithEnum = "Enums." + schema .datatypeWithEnum ;
320+ }
321+ // Also update dataType for the variant constructor
322+ if (!schema .dataType .startsWith ("Enums." )) {
323+ schema .dataType = "Enums." + schema .dataType ;
324+ }
325+ }
326+ }
327+ }
328+
303329 private void enrichPropertiesWithEnumDefaultValues (List <CodegenProperty > properties ) {
304330 for (CodegenProperty property : properties ) {
305331 if (property .get_enum () != null && property .get_enum ().size () == 1 ) {
Original file line number Diff line number Diff line change 88
99 type t =
1010 | AnyOf0 of string
11- | AnyOf1 of any_of_1
11+ | AnyOf1 of Enums . any_of_1
1212 [@@ deriving show , eq ];;
1313
1414 let to_yojson = function
1515 | AnyOf0 v -> [% to_yojson: string ] v
16- | AnyOf1 v -> [% to_yojson: any_of_1] v
16+ | AnyOf1 v -> [% to_yojson: Enums. any_of_1] v
1717
1818 (* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *)
1919
2222 [% of_yojson: string ] json
2323 |> Stdlib.Result. to_option
2424 |> Stdlib.Option. map (fun v -> AnyOf0 v);
25- [% of_yojson: any_of_1] json
25+ [% of_yojson: Enums. any_of_1] json
2626 |> Stdlib.Result. to_option
2727 |> Stdlib.Option. map (fun v -> AnyOf1 v);
2828 ]
You can’t perform that action at this time.
0 commit comments