-
Notifications
You must be signed in to change notification settings - Fork 39
Description
I have a very large object definition that contains itself by reference on a single property. The generator will currently turn this object into a class when I need a struct for usage in my app (just strongly prefer value types in my case). In my specific case I can just ignore the property that is causing this issue entirely, as I have done previously with editing the config file.
With the following example, I can just ignore best_friend:
Pet:
title: A pet title
description: A pet description
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
example: "Buddy"
type: string
tag:
type: string
best_friend:
$ref: "#/components/schemas/Pet"
description: "Best friend of your pet!"entities:
- excludeProperties: ["Pet.best_friend"]Will create an expected struct with no bestFriend property.
This is more of a discussion if excludeProperties is a good config name and whether the analog includeProperties should be created. In both cases, I know that I would have to check against the existing exclude/include lists to see if the object should be included in the overall generation. I think an error should be thrown in cases where usage of these flags together don't make sense. Or, we can just ignore these and leave it up to the user to have a clean config file.
entities:
# file 1
- include: ["some-other-object"]
- excludeProperties: ["Pet.best_friend"] # Error as "Pet" is not included in generation
# file 2
- include: ["some-other-object"]
- includeProperties: ["Pet.best_friend"] # Error as "Pet" is not included in generation
# file 3
- exclude: ["Pet"]
- excludeProperties: ["Pet.best_friend"] # Error as "Pet" is not included in generation
# file 4
- exclude: ["Pet"]
- includeProperties: ["Pet.best_friend"] # Error as "Pet" not included in generationOr instead of a new flag we change the sections to:
entities:
exclude:
- objects: [...]
- properties: [...]
include:
- objects: [...]
- properties: [...]Refactor Idea
A brainstormed refactor to include/exclude could be the following:
entities:
# file 1
- include:
- Pet: # generates the "Pet" object with only the following properties
- properties:
- id
- name
- Store: # generates the "Store" object with no properties as it is empty
- properties:
- Error: ... # need some way to indicate "Error" object generation with all properties included?
# file 2
- exclude:
- Pet: # generates the original "Pet" object but excludes the following properties
- properties:
- id
- name
- Store: # generates the original "Store" object with no properties as it is empty
- properties:
- Error: ... # need some way to indicate the "Error" object should be excluded entirely?This refactor seems expansive but I feel a lot more declarative instead of splitting among a few lists that have to be checked against one another.
I will implement whatever option if approved.