Skip to content

Cannot use 'value' (type []string) as the type string #2103

Description

@ManuelReschke

Error:
Cannot use 'value' (type []string) as the type string

The Problem is that the generated code line:

if value, found := headers[http.CanonicalHeaderKey("Authorization")]; found {

The value is the wrong type.

yml:

/upload:
    post:
      summary: Direct storage upload
      description: >-
        Uploads an image.
      operationId: postDirectUpload
      tags:
        - Upload
      servers:
        - url: http://localhost:8080/api/internal
          description: Internal storage upload server (development)
      security:
        - UploadTokenAuth: []
      parameters:
        - name: Authorization
          in: header
          description: "Bearer <UPLOAD_TOKEN>. Alternative: submit as multipart field 'token'"
          required: false
          schema:
            type: string
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                token:
                  type: string
                  description: "Alternative to Authorization header: pass upload token as multipart field"
              required: [file]
      responses:
        '200':
          description: Upload accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StorageUploadResponse'
        '400': { $ref: '#/components/responses/BadRequest' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '413': { $ref: '#/components/responses/PayloadTooLarge' }
        '415': { $ref: '#/components/responses/UnsupportedMediaType' }
        '429': { $ref: '#/components/responses/TooManyRequests' }
        '500': { $ref: '#/components/responses/InternalError' }

Generated Code:

`// PostDirectUpload operation middleware
func (siw *ServerInterfaceWrapper) PostDirectUpload(c *fiber.Ctx) error {

var err error

c.Context().SetUserValue(UploadTokenAuthScopes, []string{})

// Parameter object where we will unmarshal all parameters from the context
var params PostDirectUploadParams

headers := c.GetReqHeaders()

// ------------- Optional header parameter "Authorization" -------------
if value, found := headers[http.CanonicalHeaderKey("Authorization")]; found {
	var Authorization string

	err = runtime.BindStyledParameterWithOptions("simple", "Authorization", value, &Authorization, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: false})
	if err != nil {
		return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter Authorization: %w", err).Error())
	}

	params.Authorization = &Authorization

}

return siw.Handler.PostDirectUpload(c, params)

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions