Repository navigation
Closed as duplicate
Description
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:
oapi-codegen/pkg/codegen/schema.go
Line 569 in 3eff0a2
| 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"Metadata
Metadata
Assignees
Labels
No labels
Activity
LarsStegman commentedon Sep 15, 2025
Duplicate of #2008