Skip to content

Array of externalRef does not work #2088

Closed as duplicate
Closed as duplicate

Description

@LarsStegman

Hello,

I have a type definition where the Response contains a property that is an array of items that are an external ref. The import-mapping works for items that are simple types, but items that are an array of items do not work.

type GetThings200JSONResponse struct {
	Data    *[]externalRef0.Thing `json:"data,omitempty"`
	Errors  *[]ResponseError      `json:"errors,omitempty"`
	Success bool                  `json:"success"`
}

This is the resulting type. As you can see the Data property is resolved correctly, but the Errors property does not resolve correctly. It should have generated this code:

type GetThings200JSONResponse struct {
	Data    *[]externalRef0.Thing          `json:"data,omitempty"`
	Errors  *[]externalRef0.ResponseError  `json:"errors,omitempty"`
	Success bool                           `json:"success"`
}

I think the logic should be changed here:

arrayType, err := GenerateGoSchema(schema.Items, path)


Schema definitions:

Types:

components:
  schemas:
    ResponseError:
      type: object
      required:
        - error
        - message
        - code
      properties:
        error:
          type: string
        message:
          type: string
        code:
          type: number
    Response:
      type: object
      required:
        - success
      properties:
        success:
          type: boolean
        errors:
          type: array
          items:
            $ref: "#/components/schemas/ResponseError"
    Thing:
      type: object
      required:
        - hi
      properties:
        hi:
          type: string

API

info:
  title: "Import mapping missing alias"
  version: 0.0.1
openapi: 3.0.4
paths:
  "/things":
    description: get all things
    get:
      responses:
        200:
          description: a list of things
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "../../testtypes/spec/openapi.yaml#/components/schemas/Response"
                  - properties:
                      data:
                        type: array
                        items:
                          $ref: "../../testtypes/spec/openapi.yaml#/components/schemas/Thing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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