Skip to content

Adding encoding section breaks model generation for multipart/form-data requests #7342

@JeroMiya

Description

@JeroMiya

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

There is a small possibility this is related to: #6451 (issue is closed, but the bug still exists)

When there is an endpoint in the OpenAPI spec that uses the multipart/form-data content type, and that part of the spec includes an encoding section that defines one but not all of the properties of the request, the generator will fail to generate models for properties of the request that do not have an encoding defined. If you completely remove the encoding section, the generator will generate the model for all properties. If you add an encoding for the property that doesn't get a model generated, it will then generate a model.

Expected behavior

If the endpoint has an encoding section, and a property of a multipart/form-data request does not have an encoding defined, it should still generate a model for that property in the same way it does when there is no encoding section at all.

How to reproduce

Save the Open API description file below to repro-api.yaml, then run this command:
dotnet tool run kiota generate --backing-store --exclude-backward-compatible --clean-output -l CSharp --dvr All -c UserClient -n KiotaContentTypeBugRepo -d ./repro-api.yaml -o ./KiotaContentTypeBugRepo

Expected a model created for #/components/schemas/create-user-info-request but none is generated.

Remove the encoding section from the Open API spec, and run the generator again.
Notice the model is now generated.

Open API description file

openapi: 3.0.3
info:
  title: User-API
  description: External api for users
  version: "1.0"
servers:
- url: https://example.com/api
paths:
  /users:
    post:
      tags:
      - create
      operationId: create-user
      requestBody:
        content:
          multipart/form-data:
            schema:
              required:
              - template
              - info
              type: object
              properties:
                info:
                  $ref: "#/components/schemas/create-user-info-request"
                template:
                  $ref: "#/components/schemas/user-email-template"
            encoding:
              template:
                contentType: text/html
                style: form
      responses:
        "201":
          description: Created
        "400":
          description: Bad Request
components:
  schemas:
    create-user-info-request:
      title: create-user-info-request
      required:
      - firstName
      - lastName
      type: object
      properties:
        firstName:
          type: string
        lastName:
          type: string
      x-internal: false
    user-email-template:
      title: user-email-template
      type: string
      format: binary

Kiota Version

1.30.0+6ccf6da832742181cba0ab02588c5795b2185e13

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

We have to remove the encoding section or add an encoding for the missing model schema. This is not ideal as the Open API spec we're using is from a third party, and we'd prefer to minimize the number of manual edits of the spec we have to do before generating the client.

Configuration

  • OS: Windows 11
  • Architecture: x64
  • Doesn't appear to be specific to this configuration

Debug output

info: Kiota.Builder.KiotaBuilder[659500454]
      Cleaning output directory C:\Users\username\source\repos\sandbox\KiotaContentTypeBugRepo\KiotaContentTypeBugRepo\.\KiotaContentTypeBugRepo
dbug: Kiota.Builder.KiotaBuilder[1405590561]
      kiota version 1.30.0
info: Kiota.Builder.KiotaBuilder[1423726202]
      loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 1 - reading the stream - took 00:00:00.0092098
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 2 - parsing the document - took 00:00:00.0598683
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 3 - updating generation configuration from kiota extension - took 00:00:00.0000810
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 4 - filtering API paths with patterns - took 00:00:00.0028770
info: Kiota.Builder.KiotaBuilder[543457275]
      Client root URL set to https://example.com/api
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 5 - checking whether the output should be updated - took 00:00:00.0249451
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 6 - create uri space - took 00:00:00.0039850
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      InitializeInheritanceIndex 00:00:00.0091914
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      MapTypeDefinitions 00:00:00.0050084
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 7 - create source model - took 00:00:00.0880633
dbug: Kiota.Builder.KiotaBuilder[1306343761]
      18ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 8 - refine by language - took 00:00:00.0224810
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 9 - writing files - took 00:00:00.0269109
info: Kiota.Builder.KiotaBuilder[1423726202]
      loaded description from local source
dbug: Kiota.Builder.KiotaBuilder[1605292753]
      step 10 - writing lock file - took 00:00:00.0128555
Generation completed successfully
Client base url set to https://example.com/api
dbug: Kiota.Builder.KiotaBuilder[2121673205]
      Api manifest path: C:\Users\username\source\repos\sandbox\KiotaContentTypeBugRepo\KiotaContentTypeBugRepo\apimanifest.json

Hint: use the info command to get the list of dependencies you need to add to your project.
Example: kiota info -d "C:\Users\username\source\repos\sandbox\KiotaContentTypeBugRepo\KiotaContentTypeBugRepo\.\repro-api.yaml" -l CSharp

Hint: use the --include-path and --exclude-path options with glob patterns to filter the paths generated.
Example: kiota generate --include-path "**/foo" -d "C:\Users\username\source\repos\sandbox\KiotaContentTypeBugRepo\KiotaContentTypeBugRepo\.\repro-api.yaml"

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions