Created by: dschmidt
This makes sure all model classes are added to the forward declarations which makes it possible to create templates without any model includes. This helps to resolve circular inclusion issues.
This adds more forward declarations of which a lot are not strictly needed by the current templates, but they don't harm either. Trying to detect in which case declarations are needed or not or making it configurable does not seem to be worth the effort and would add a lot of complexity.
If you have a spec like this:
openapi: 3.0.1
info:
title: Libre Graph API
version: v0.9.0
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: https://ocis.ocis-traefik.latest.owncloud.works/
description: ownCloud Infinite Scale Latest
paths: {}
components:
schemas:
drive:
description: Storage Space. Read-only.
readOnly: true
type: object
properties:
root:
$ref: '#/components/schemas/driveItem'
user:
description: Represents an Active Directory user object.
type: object
properties:
drive:
$ref: '#/components/schemas/drive'
driveItem:
description: Reprensents a resource inside a drive. Read-only.
readOnly: true
type: object
properties:
lastModifiedByUser:
$ref: '#/components/schemas/user'
description: Identity of the user who last modified the item. Read-only.
readOnly: true
(excerpt from https://github.com/owncloud/libre-graph-api/blob/main/api/openapi-spec/v0.0.yaml)
You get issues with circular #include
s: Drive
requires DriveItem
requires User
requires Drive
I'm working on templates based on the cpp-qt-client
, but with the current implementation (without this PR) required forward declarations are missing: e.g., Drive
only has a User
forward declaration, the DriveItem
forward declaration is missing. With this PR all models used in the header are added to the forward declarations.
I found the old code hard to reason about so i'm not 100% sure this does not remove any forward declarations in some edge case, but it works for me for the original spec that my excerpt is from and it's not completely trivial.
Attention: This change alone is not enough to make the generator produce compilable code for the spec above, but it's all that's needed to create working templates. Templates are still work in progress because I've still got runtime issues to resolve.
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(5.3.0),6.0.x
-
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.