Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions internal/test/array_pointer/array_pointer.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/test/array_pointer/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# yaml-language-server: $schema=../../configuration-schema.json
package: array_pointer
output: array_pointer.gen.go
generate:
models: true
3 changes: 3 additions & 0 deletions internal/test/array_pointer/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package array_pointer

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml openapi.yaml
51 changes: 51 additions & 0 deletions internal/test/array_pointer/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
openapi: "3.0.1"
info:
version: 1.0.0
title: Tests array pointer composition
paths:
/placeholder:
get:
operationId: placeholder
responses:
default:
description: placeholder
content:
application/json:
schema:
$ref: "#/components/schemas/response.Placeholder"
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

Response:
x-go-name: Response
type: object
properties:
status:
type: integer
10 changes: 5 additions & 5 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,10 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem

arrayType.RefType = typeName
}
arrayType.AdditionalPropertiesType = &arrayType
arrayType.AdditionalPropertiesType.OAPISchema = schema
outSchema.ArrayType = &arrayType
outSchema.GoType = "[]" + arrayType.TypeDecl()
outSchema.GoType = "[]" + additionalPropertiesType(arrayType)
outSchema.AdditionalTypes = arrayType.AdditionalTypes
outSchema.Properties = arrayType.Properties
outSchema.DefineViaAlias = true
Expand Down Expand Up @@ -795,10 +797,8 @@ func GenFieldsFromProperties(props []Property) []string {
}

func additionalPropertiesType(schema Schema) string {
addPropsType := schema.AdditionalPropertiesType.GoType
if schema.AdditionalPropertiesType.RefType != "" {
addPropsType = schema.AdditionalPropertiesType.RefType
}
addPropsType := schema.AdditionalPropertiesType.TypeDecl()

if schema.AdditionalPropertiesType.OAPISchema != nil && schema.AdditionalPropertiesType.OAPISchema.Nullable {
addPropsType = "*" + addPropsType
}
Expand Down