Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Free-form models without validation which are not allOf
included in any composed schema are not generated, though valid OpenAPI documents exist which make use of these objects. In larger, specification-based OpenAPI documents (such as [DMTF's Redfish schema|https://redfish.dmtf.org/]), these objects are leveraged to specify implementation-defined objects, which can contain any number of properties required by a valid implementation of the specification. This allows, for example, me to use a different request body for some requests than that which is required for a Redfish-compliant implementation provided by IBM or HP Enterprise hardware (etc).
Actual output: The model User
in the below schema is not generated, though it is referenced in the requestBody
of an action on a URL.
Expected output: The model User
is generated.
openapi-generator version
Version 6.3.0, HEAD
of master. This is not a regression.
OpenAPI declaration file content or url
openapi: 3.0.0
info:
description: "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/)\
\ or HTML."
title: Sample API
version: 0.1.9
servers:
- description: "Optional server description, e.g. Main (production) server"
url: http://api.example.com/v1
- description: "Optional server description, e.g. Internal staging server for testing"
url: http://staging-api.example.com
paths:
/users:
get:
description: Optional extended description in CommonMark or HTML.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
responses:
"200":
description: A JSON array of user names
summary: Returns a list of users.
components:
schemas:
User:
additionalProperties: false
description: A user
properties: {}
type: object
Generation Details
See steps to reproduce
Steps to reproduce
- Attempt to generate the source using the
rust-server
generator.
openapi-generator -g rust-server -i openapi.yaml -o test-models
- Attempt to compile the source (observe compilation errors about missing struct definitions)
cargo build
Compiling openapi_client v0.1.9 (/home/edtwardy/Git/redfish/small-test/test-models)
error[E0412]: cannot find type `User` in module `models`
--> src/lib.rs:34:30
|
34 | body: Option<models::User>,
| ^^^^ not found in `models`
error[E0412]: cannot find type `User` in module `models`
--> src/lib.rs:51:30
|
51 | body: Option<models::User>,
| ^^^^ not found in `models`
error[E0412]: cannot find type `User` in module `models`
--> src/lib.rs:82:30
|
82 | body: Option<models::User>,
| ^^^^ not found in `models`
error[E0412]: cannot find type `User` in module `models`
--> src/client/mod.rs:385:36
|
385 | param_body: Option<models::User>,
| ^^^^ not found in `models`
error[E0412]: cannot find type `User` in module `models`
--> src/server/mod.rs:151:64
|
151 | ... let param_body: Option<models::User> = if !body.is_empty() {
| ^^^^ not found in `models`
For more information about this error, try `rustc --explain E0412`.
error: could not compile `openapi_client` due to 5 previous errors
Related issues/PRs
#5969, #5970: The same issue, observed for the same generator, a few years ago. Presumably, the PR was closed because isFreeFormObject
was still provided by the Mustache object model at the time. This is no longer the case since commit #d4b8ff60
#7361, #7373: Implementation of a subset of use cases for free-form objects in OpenAPI documents.
Suggest a fix
I have a commit which fixes the issue on my fork. This commit allows templates to once again use {{#isFreeFormObject}}
to specially handle free-form objects. Additionally, the third case of free-form objects not handled by #7373 is enabled if global property generateFreeFormModels
is true
.
Since CONTRIBUTING.md
requests that an issue be opened first to enable discussion, I did not open a PR. testFreeFormSchemas(DefaultCodegenTest.java:2526) is currently failing. As soon as the community feels a PR is appropriate, I would be happy to open one and update the tests!