Search code examples
c#openapiopenapi-generator

Why does openapi-generator create InlineObjects?


I'm using

https://github.com/OpenAPITools/openapi-generator

to create a client for my API. It's mostly working ok, but the generator creates a lot of InlineObject types that encapsulate parameters that include types of any complexity, e.g Dictionary, IFormFile, Stream

For example,

public async Task<ApiResponse<FileUploadResponseAPIModel>> MyApiClientMethod(InlineObject11 inlineObject11 = default(InlineObject11))
    {
    }

Where InlineObject11 is defined as

public partial class InlineObject11 : IEquatable<InlineObject11>, IValidatableObject
{
    
    [JsonConstructorAttribute]
    protected InlineObject11() { }
    
    public InlineObject11(Stream rebalanceTradeFile = default(Stream))
    {
        // to ensure "rebalanceTradeFile" is required (not null)
        this.RebalanceTradeFile = rebalanceTradeFile ?? throw new ArgumentNullException("rebalanceTradeFile is a required property for InlineObject11 and cannot be null");
    }

    [DataMember(Name = "RebalanceTradeFile", IsRequired = true, EmitDefaultValue = false)]
    public System.IO.Stream RebalanceTradeFile { get; set; }

What is the point of this? Why isn't the client generated to take Stream rebalanceTradeFile instead of wrapping it into an InlineObject? How can I fix it? This is breaking a bunch of my tools that use older versions of the generated client.


Solution

  • Inline Object is created from inline schema, e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/inline_model_resolver.yaml#L15-L24 is a schema with 2 properties defined inline for the payload with the MIME type application/json.

    To avoid OpenAPI Generator automatically generating a model for the inline schema, one can define the model separately (example) and use $ref instead:

            application/json:
              schema:
                $ref: '#/components/schemas/Pet'