Skip to content

Commit 073ad8f

Browse files
committed
Fix recursion tests
1 parent 47680b2 commit 073ad8f

16 files changed

Lines changed: 184 additions & 82 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
generatorName: ocaml
22
outputDir: samples/client/petstore/ocaml-recursion-test
3-
inputSpec: modules/openapi-generator/src/test/resources/3_0/recursion.yaml
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/ocaml/direct-recursion.yaml
44
templateDir: modules/openapi-generator/src/main/resources/ocaml
55
additionalProperties:
66
packageName: recursion_test
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
openapi: 3.0.0
2+
info:
3+
description: |
4+
Test for direct recursive types in OCaml generator.
5+
6+
This spec only tests direct recursion (A -> A) and NOT mutual recursion (A -> B -> A).
7+
8+
The OCaml generator does not support mutual recursion because OCaml requires mutually
9+
recursive types to be declared together in the same file using "type a = ... and b = ..."
10+
syntax. The generator's architecture uses one model per file, making this infeasible.
11+
12+
Note: The generic test file modules/openapi-generator/src/test/resources/3_0/recursion.yaml
13+
contains both Foo (direct recursion) and Bar/Baz (mutual recursion), which is why we
14+
cannot use it for OCaml testing.
15+
version: 1.0.0
16+
title: OCaml Direct Recursion Test
17+
paths:
18+
/tree:
19+
get:
20+
operationId: getTree
21+
description: Get a tree structure
22+
responses:
23+
'200':
24+
description: Success
25+
content:
26+
application/json:
27+
schema:
28+
$ref: '#/components/schemas/Tree'
29+
/node:
30+
post:
31+
operationId: createNode
32+
description: Create a node
33+
requestBody:
34+
required: true
35+
content:
36+
application/json:
37+
schema:
38+
$ref: '#/components/schemas/Node'
39+
responses:
40+
'201':
41+
description: Created
42+
content:
43+
application/json:
44+
schema:
45+
$ref: '#/components/schemas/Node'
46+
components:
47+
schemas:
48+
Tree:
49+
type: object
50+
description: A tree with optional children (direct self-reference)
51+
properties:
52+
value:
53+
type: integer
54+
format: int32
55+
children:
56+
type: array
57+
items:
58+
$ref: '#/components/schemas/Tree'
59+
required:
60+
- value
61+
62+
Node:
63+
type: object
64+
description: A node with an optional self-reference
65+
properties:
66+
id:
67+
type: string
68+
next:
69+
$ref: '#/components/schemas/Node'
70+
required:
71+
- id

samples/client/petstore/ocaml-additional-properties/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.ocamlformat
2+
.openapi-generator-ignore
23
README.md
34
dune
45
dune-project

samples/client/petstore/ocaml-enum-in-composed-schema/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.ocamlformat
2+
.openapi-generator-ignore
23
README.md
34
dune
45
dune-project

samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.ocamlformat
2+
.openapi-generator-ignore
23
README.md
34
dune
45
dune-project

samples/client/petstore/ocaml-oneOf-primitive/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.ocamlformat
2+
.openapi-generator-ignore
23
README.md
34
dune
45
dune-project
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.ocamlformat
2+
.openapi-generator-ignore
23
README.md
34
dune
45
dune-project
56
recursion_test.opam
67
src/apis/default_api.ml
78
src/apis/default_api.mli
8-
src/models/bar.ml
9-
src/models/baz.ml
10-
src/models/foo.ml
9+
src/models/node.ml
10+
src/models/tree.ml
1111
src/support/enums.ml
1212
src/support/jsonSupport.ml
1313
src/support/request.ml

samples/client/petstore/ocaml-recursion-test/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
#
2-
Test
2+
Test for direct recursive types in OCaml generator.
3+
4+
This spec only tests direct recursion (A -> A) and NOT mutual recursion (A -> B -> A).
5+
6+
The OCaml generator does not support mutual recursion because OCaml requires mutually
7+
recursive types to be declared together in the same file using \''type a = ... and b = ...\''
8+
syntax. The generator's architecture uses one model per file, making this infeasible.
9+
10+
Note: The generic test file modules/openapi-generator/src/test/resources/3_0/recursion.yaml
11+
contains both Foo (direct recursion) and Bar/Baz (mutual recursion), which is why we
12+
cannot use it for OCaml testing.
13+
314

415
This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
516

samples/client/petstore/ocaml-recursion-test/src/apis/default_api.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,32 @@
55
*
66
*)
77

8-
let foo_post () =
8+
let create_node ~node_t =
99
let open Lwt.Infix in
10-
let uri = Request.build_uri "/foo" in
10+
let uri = Request.build_uri "/node" in
1111
let headers = Request.default_headers in
12-
Cohttp_lwt_unix.Client.call `POST uri ~headers >>= fun (resp, body) ->
13-
Request.read_json_body_as (JsonSupport.unwrap Foo.of_yojson) resp body
12+
let body = Request.
13+
14+
write_as_json_body
15+
16+
17+
18+
19+
20+
21+
Node.to_yojson
22+
23+
24+
25+
node_t
26+
in
27+
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
28+
Request.read_json_body_as (JsonSupport.unwrap Node.of_yojson) resp body
29+
30+
let get_tree () =
31+
let open Lwt.Infix in
32+
let uri = Request.build_uri "/tree" in
33+
let headers = Request.default_headers in
34+
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
35+
Request.read_json_body_as (JsonSupport.unwrap Tree.of_yojson) resp body
1436

samples/client/petstore/ocaml-recursion-test/src/apis/default_api.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
*
66
*)
77

8-
val foo_post : unit -> Foo.t Lwt.t
8+
val create_node : node_t:Node.t -> Node.t Lwt.t
9+
val get_tree : unit -> Tree.t Lwt.t

0 commit comments

Comments
 (0)