OpenAPITools / OpenAPITools/openapi-generator

[BUG][csharp] Method signatures contain models while models are not generated by default for form parameters

Open
#9,043 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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?

Hard to tell

Description
openapi-generator version
OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Clean Architecture Api Specification 
  description: Clean Architecture Api Specification 
  version: 1.0.1
servers:
  - url: 'https://localhost:5000'
    description: Local Development Server

paths:
  /ToDoItems:
    put:
      operationId: ToDoItem.Update
      description: Updates a ToDoItem
      tags:
        - TodoItemEndpoints
      requestBody:
        content: 
          multipart/form-data:
            schema:
              type: object
              properties: 
                orderId: 
                  type: integer
                updatedRequest:
                  $ref: '#/components/schemas/UpdateToDoItemRequest'      
      responses: 
        200:
          description: The updated ToDo Item
          content: 
            application/json:
              schema:
                $ref: '#/components/schemas/ToDoItemResponse'


components:
  schemas:
    UpdateToDoItemRequest:
      type: object
      properties:
        Id:
          type: integer
        Title:
          type: string
        Description:
          type: string
    ToDoItemResponse:
        type: object
        properties:
          Id:
            type: integer
          Title:
            type: string
          Description:
            type: string
          IsDone:
            type: boolean
          
  
Generation Details

Generate a csharp client or aspnetcore server with this spec and see that it fails to compile, reason being that the method signatures contians models which are not generated by default for form parameter model classes

Suggest a fix

Generate models by default for those generators, or flatten method signatures by default.

Discussion Start Point

Apparently the default right now is to not generate model classes for objects which are referenced in multipart/form-data sections. This was apparently done after people migrating from openapi 2 complained. This however results in those cases producing non compiling code for csharp, might as well for other languages, didn't try that.

I think producing non-compiling code in a default configuration for any apispec is not a good thing. The goal should be that whatever the spec the default configuration always results in valid code

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the csharp client and aspnetcore server from the multipart/form-data OpenAPI spec in the issue, then inspect the generated method signatures and model-generation behavior for form parameters. Confirm the failure and add a regression test; done means the default generated output compiles without requiring an ungenerated model or manual configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.