Skip to content

Proposal: New flag "--empty-objects-ignore" #2529

@hexxone

Description

@hexxone

Description

The current problem with --empty-objects-unknown is, that Empty objects are either fully respresented as "never" or as "any". Even though it might be preferrable to just completely ignore them.

E.g.: assume I have the following Entity structure which I expose on a Controller...

public abstract class PolicyEntity<TEntity> : IEntity
{
    public abstract int Id { get; set; }
}

public class Plant : PolicyEntity<Plant>
{
    public override int Id { get; set; }
}

[HttpGet("Get/{id}")]
public ActionResult<Plant>? Get([FromRoute] int id)
{
    // ...
}

Then I convert this to equivalent Typescript Code and get something like this:

export type components = {
    schemas: {
         PolicyEntity_Plant_: Record<string, unknown>;
         Plant: components['schemas']['PolicyEntity_Plant_'] & ({
            /** Format: int32 */
            Id: number;
       }
   }
}

which essentially means, that Schema<'Plant'>.Id and all other Properties are ALWAYS any.

Proposal

Instead, there should be aflag to fully ignore empty objects and "strip" them from the source, instead of having them as eiher Record<string, unknown> OR Record<string, never>.

Extra

Might be verry similar to this issue and provide a possible solution for: #1520

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions