OpenAPITools / OpenAPITools/openapi-generator

[BUG][aspnetcore] generated code fails to compile when using path with requestBody ref with 'multipart-form-data' content with schema ref

Open
#11,113 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Currently, the YAML file generated by openapi-yaml for file-upload endpoints creates files which use refs to the requestBody, which in turn use refs for their content schema. When trying to process these files with the aspnetcore generator, they fail.

openapi-generator version

5.3.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  description: test
  title: test
  version: 0.0.1
paths:
  /attachments:
    post:
      requestBody:
        $ref: '#/components/requestBodies/aaa'
      responses:
        "200":
          description: OK
components:
  requestBodies:
    aaa:
      content:
        multipart/form-data:
          schema:
            $ref: '#/components/schemas/bbb'
  schemas:
    bbb:
      properties:
        file:
          format: binary
          type: string
      type: object

Generation Details
  1. put the above yaml in test.yml
  2. if running in git-bash on Windows, export MSYS_NO_PATHCONV=1 to fix docker paths
  3. docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.3.0 generate --input-spec "/local/test.yml" --output "/local/out" --generator-name aspnetcore
Steps to reproduce
  1. run the above steps to generate your aspnetcore code
  2. ensure you've installed the dotnet CLI
  3. dotnet build out/*.sln
  4. see errors:
out\src\Org.OpenAPITools\Controllers\DefaultApi.cs(21,24): error CS0234: The type or namespace name 'Models' does not exist in the namespace 'Org.OpenAPITools' (are you missing an assembly reference?) [C:\Users\Matt\source\repos\ts-public-api\out\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
out\src\Org.OpenAPITools\Controllers\DefaultApi.cs(41,64): error CS0246: The type or namespace name 'Bbb' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Matt\source\repos\ts-public-api\out\src\Org.OpenAPITools\Org.OpenAPITools.csproj]

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

Reproduce from test.yml using the documented Docker command, then inspect the generated out/src/Org.OpenAPITools/Controllers/DefaultApi.cs and the reported project build errors. Trace how the aspnetcore generator handles the requestBody and multipart/form-data schema refs. Done means the generated solution builds successfully with dotnet build and includes the referenced Bbb model.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.