Skip to content

Unable to use content.application/json in parameter. "Converter" has no member setQueryItemAsJson #853

@alteredtech

Description

@alteredtech

Description

I am attempting to find a solution to this #832, when I found in the openapi docs that I could just use content. in the parameter. I saw in the faq that content is supported in parameters.

When attempting to build. I get this error.

Value of type 'Converter' has no member 'setQueryItemAsJSON'
Cannot infer contextual base in reference to member 'form'

I am attempting to get a parameter with the following style
filters=[{"key":"status","operator":"eq","value":"active"},{"key":"price","operator":"lt","value":"100"}]

Reproduction

Using both array and the ref singular in the schema, get the same error.

internal func getPetById(_ input: Operations.getPetById.Input) async throws -> Operations.getPetById.Output {
        try await client.send(
            input: input,
            forOperation: Operations.getPetById.id,
            serializer: { input in
                let path = try converter.renderedPath(
                    template: "/pet/{}",
                    parameters: [
                        input.path.petId
                    ]
                )
                var request: HTTPTypes.HTTPRequest = .init(
                    soar_path: path,
                    method: .get
                )
                suppressMutabilityWarning(&request)
                try converter.setQueryItemAsJSON(
                    in: &request,
                    style: .form,
                    explode: true,
                    name: "filters",
                    value: input.query.filters
                )
                converter.setAcceptHeader(
                    in: &request.headerFields,
                    contentTypes: input.headers.accept
                )
                return (request, nil)
            },
openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.

    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)

  termsOfService: http://swagger.io/terms/
  contact:
    email: [email protected]
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.11
externalDocs:
  description: Find out more about Swagger
  url: http://swagger.io
servers:
  - url: http://127.0.0.1:3000
  
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: http://swagger.io
      
paths:
        
  /pet/{petId}:
    get:
      tags:
        - pet
      summary: Find pet by ID
      description: Returns a single pet
      operationId: getPetById
      parameters:
        - $ref: "#/components/parameters/SearchFiltersQueryOptional"
        - name: petId
          in: path
          description: ID of pet to return
          required: true
          example: 0
          schema:
            type: integer
            format: int64
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/Pet'
        '400':
          description: Bad Request Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: Bad Gateway Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        
components:
  parameters:
    SearchFiltersQueryOptional:
      name: filters
      in: query
      description: Filters to refine search
      required: false
      content:
        application/json:
          schema:
            type: array
            items:
              $ref: "#/components/schemas/Filter"
  schemas:
    FilterOperation:
      description: An operation to filter data from atlas
      type: string
      enum:
        - "="
        - "!="
        - ">"
        - ">="
        - "<"
        - "<="
        - "contains"
        - "not_contains"
        - "begins_with"
    Filter:
      description: A full filter to sort data in atlas
      type: object
      required:
        - key
        - operation
        - value
      properties:
        key:
          type: string
        operation:
          $ref: "#/components/schemas/FilterOperation"
        value:
          type: string
    Error:
      description: Error message format
      type: object
      example:
        message: I am a teapot
        code: 412
      required:
        - message
        - code
      properties:
        message:
          type: string
          example: teapot
        code:
          type: integer
          example: 412

          
    Pet:
      description: The pet object that is defined.
      required:
        - name
        - photoUrls
      type: object
      example:
        id: 2
        name: Koda
        photoUrls:
          - "https://example.com"
      properties:
        id:
          type: integer
          format: int64
          example: 10
        name:
          type: string
          example: doggie
        photoUrls:
          type: array
          items:
            type: string
generate:
  - types
  - client
accessModifier: internal

Package version(s)

.
├── swift-argument-parser<https://github.com/apple/[email protected]>
├── swift-openapi-runtime<https://github.com/apple/[email protected]>
│   └── swift-http-types<https://github.com/apple/[email protected]>
├── swift-openapi-generator<https://github.com/apple/[email protected]>
│   ├── swift-algorithms<https://github.com/apple/[email protected]>
│   │   └── swift-numerics<https://github.com/apple/[email protected]>
│   ├── swift-collections<https://github.com/apple/[email protected]>
│   ├── openapikit<https://github.com/mattpolzin/[email protected]>
│   │   └── yams<https://github.com/jpsim/[email protected]>
│   ├── yams<https://github.com/jpsim/[email protected]>
│   └── swift-argument-parser<https://github.com/apple/[email protected]>
└── swift-openapi-urlsession<https://github.com/apple/[email protected]>
    ├── swift-openapi-runtime<https://github.com/apple/[email protected]>
    │   └── swift-http-types<https://github.com/apple/[email protected]>
    ├── swift-http-types<https://github.com/apple/[email protected]>
    └── swift-collections<https://github.com/apple/[email protected]>

Expected behavior

Would expect the generator to build.

Environment

Apple Swift version 6.2-dev (LLVM 4197ac1672a278c, Swift acbdfef4f4d71b1)
Target: arm64-apple-macosx26.0
Build config: +assertions

Additional information

Trying to follow the example here for using content in the parameter.

https://swagger.io/docs/specification/v3_0/describing-parameters/

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugFeature doesn't work as expected.status/triageCollecting information required to triage the issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions