oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

fix(array-pointer): support array pointer for ref

Open zdunecki opened this issue 5 months ago • 1 comments

Hi,

There's a fix for this case:

components:
  schemas:
    response.Placeholder:
      x-go-embedding: true
      type: object
      allOf:
        - $ref: "#/components/schemas/Response"
        - type: object
          properties:
            hello:
              type: string
            past_7_days_histogram:
              type: array
              x-go-type-skip-optional-pointer: true
              nullable: true
              items:
                allOf:
                  - $ref: '#/components/schemas/DateHistogram'

    DateHistogram:
      type: object
      properties:
        key:
          type: string
        key_as_string:
          type: string
          nullable: true
        doc_count:
          type: integer

I would expect it will produce in Go code like that:

type ResponsePlaceholder struct {
	Hello              *string          `json:"hello,omitempty"`
	Past7DaysHistogram []*DateHistogram `json:"past_7_days_histogram"`
}

The key is - []*DateHistogram.

Currently, it's not possible to declare type: array with an external $ref and a pointer(*). I tried multiple ways and still get []DateHistogram.

This PR should fix that.

Best,

zdunecki avatar Sep 02 '25 17:09 zdunecki

Kusari Inspector

Kusari Analysis Results:

Proceed with these changes
✅ No Flagged Issues Detected All values appear to be within acceptable risk parameters.

No pinned version dependency changes, code issues or exposed secrets detected!

@kusari-inspector rerun - Trigger a re-analysis of this PR @kusari-inspector feedback [your message] - Send feedback to our AI and team See Kusari's documentation for setup and configuration. Commit: ada15fdc51604de2eb838c9924b71a7d50ae7af6, performed at: 2025-09-02T17:00:51Z

Found this helpful? Give it a 👍 or 👎 reaction!

kusari-inspector[bot] avatar Sep 02 '25 17:09 kusari-inspector[bot]