Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenAPI Bug] Golang generated code does not return an expect array #2813

Closed
Olshansk opened this issue Jan 26, 2024 · 2 comments
Closed

[OpenAPI Bug] Golang generated code does not return an expect array #2813

Olshansk opened this issue Jan 26, 2024 · 2 comments
Assignees
Labels
go Go models and clients

Comments

@Olshansk
Copy link

Describe the Bug

The golang generated code has a header that only returns an error like so: func (c *Client) PocketGatewayGatewayAll(ctx context.Context, request *poktroll.PocketGatewayGatewayAllRequest) error { even though the endpoint contains an array like so:

responses:
        "200":
          description: A successful response.
          schema:
            type: object
            properties:
              application:
                type: array

What is the source of the issue?

Information to Reproduce

CLI Version

{
    "organization": "olshansk",
    "version": "0.16.36"
}

Generator Config

default-group: local
groups:
  local:
    generators:
      - name: fernapi/fern-typescript-node-sdk
        version: 0.7.2
        output:
          location: local-file-system
          path: ../sdk/typescript
      - name: fernapi/fern-go-sdk
        version: 0.9.4
        config:
          module:
            path: github.com/pokt-network/poktroll
            version: "1.19"
        output:
          location: local-file-system
          path: ../sdk/go

Actual OpenAPI

  /pocket/application/application:
    get:
      operationId: PocketApplicationApplicationAll
      responses:
        "200":
          description: A successful response.
          schema:
            type: object
            properties:
              application:
                type: array
                items:
                  type: object
                  properties:
                    address:
                      type: string
                      title: >-
                        The Bech32 address of the application using cosmos'
                        ScalarDescriptor to ensure deterministic encoding
                    stake:
                      title: The total amount of uPOKT the application has staked
                      type: object
                      properties:
                        denom:
                          type: string
                        amount:
                          type: string
                      description: >-
                        Coin defines a token with a denomination and an amount.


                        NOTE: The amount field is an Int which implements the
                        custom method

                        signatures required by gogoproto.
                    service_configs:
                      type: array
                      items:
                        type: object
                        properties:
                          service:
                            title: >-
                              The Service for which the application is
                              configured
                            type: object
                            properties:
                              id:
                                type: string
                                description: Unique identifier for the service
                                title: >-
                                  For example, what if we want to request a
                                  session for a certain service but with some
                                  additional configs that identify it?
                              name:
                                type: string
                                description: >-
                                  (Optional) Semantic human readable name for
                                  the service
                                title: >-
                                  TODO_TECHDEBT: Name is currently unused but
                                  acts as a reminder than an optional onchain
                                  representation of the service is necessary
                        title: >-
                          ApplicationServiceConfig holds the service
                          configuration the application stakes for
                      title: >-
                        The list of services this appliccation is configured to
                        request service for
                    delegatee_gateway_addresses:
                      type: array
                      items:
                        type: string
                      title: >-
                        The Bech32 encoded addresses for all delegatee Gateways,
                        in a non-nullable slice
                  title: >-
                    Application defines the type used to store an on-chain
                    definition and state for an application
              pagination:
                type: object
                properties:
                  next_key:
                    type: string
                    format: byte
                    description: |-
                      next_key is the key to be passed to PageRequest.key to
                      query the next page most efficiently. It will be empty if
                      there are no more results.
                  total:
                    type: string
                    format: uint64
                    title: >-
                      total is total number of results available if
                      PageRequest.count_total

                      was set, its value is undefined otherwise
                description: >-
                  PageResponse is to be embedded in gRPC response messages where
                  the

                  corresponding request message has used PageRequest.

                   message SomeResponse {
                           repeated Bar results = 1;
                           PageResponse page = 2;
                   }
        default:
          description: An unexpected error response.
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
              message:
                type: string
              details:
                type: array
                items:
                  type: object
                  properties:
                    "@type":
                      type: string
                  additionalProperties: {}
      parameters:
        - name: pagination.key
          description: |-
            key is a value returned in PageResponse.next_key to begin
            querying the next page most efficiently. Only one of offset or key
            should be set.
          in: query
          required: false
          type: string
          format: byte
        - name: pagination.offset
          description: >-
            offset is a numeric offset that can be used when key is unavailable.

            It is less efficient than using key. Only one of offset or key
            should

            be set.
          in: query
          required: false
          type: string
          format: uint64
        - name: pagination.limit
          description: >-
            limit is the total number of results to be returned in the result
            page.

            If left empty it will default to a value to be set by each app.
          in: query
          required: false
          type: string
          format: uint64
        - name: pagination.count_total
          description: >-
            count_total is set to true  to indicate that the result set should
            include

            a count of the total number of items available for pagination in
            UIs.

            count_total is only respected when offset is used. It is ignored
            when key

            is set.
          in: query
          required: false
          type: boolean
        - name: pagination.reverse
          description: >-
            reverse is set to true if results are to be returned in the
            descending order.


            Since: cosmos-sdk 0.43
          in: query
          required: false
          type: boolean
      tags:
        - Query

Golang Generated Code

func (c *Client) PocketGatewayGatewayAll(ctx context.Context, request *poktroll.PocketGatewayGatewayAllRequest) error {
    baseURL := ""
    if c.baseURL != "" {
        baseURL = c.baseURL
    }
    endpointURL := baseURL + "/" + "pocket/gateway/gateway"

    queryParams := make(url.Values)
    if request.PaginationKey != nil {
        queryParams.Add("pagination.key", fmt.Sprintf("%v", *request.PaginationKey))
    }
    if request.PaginationOffset != nil {
        queryParams.Add("pagination.offset", fmt.Sprintf("%v", *request.PaginationOffset))
    }
    if request.PaginationLimit != nil {
        queryParams.Add("pagination.limit", fmt.Sprintf("%v", *request.PaginationLimit))
    }
    if request.PaginationCountTotal != nil {
        queryParams.Add("pagination.count_total", fmt.Sprintf("%v", *request.PaginationCountTotal))
    }
    if request.PaginationReverse != nil {
        queryParams.Add("pagination.reverse", fmt.Sprintf("%v", *request.PaginationReverse))
    }
    if len(queryParams) > 0 {
        endpointURL += "?" + queryParams.Encode()
    }

    if err := c.caller.Call(
        ctx,
        &core.CallParams{
            URL:     endpointURL,
            Method:  http.MethodGet,
            Headers: c.header,
        },
    ); err != nil {
        return err
    }
    return nil
}
@Olshansk
Copy link
Author

Got feedback from Oleg that You need to specify items field with data's types of array's elements. Looking into that now.

@amckinney
Copy link
Collaborator

Based on the description here as well as the referenced issue, it looks like this is caused by a bug in the OpenAPI generator you are using.

I'll follow-up in your most recent related issue, and we can continue the conversation there - I think I have a solution for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Go models and clients
Development

No branches or pull requests

4 participants