//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --generate=types,skip-prune --package=api -o test.gen.go test.yaml
test.yaml
openapi: 3.0.4
info:
description: example api
version: v1
title: example api
servers:
- url: "https://example.com"
description: Production
paths:
/download:
get:
summary: "download"
description: "download"
operationId: "getDownload"
responses:
200:
description: "download list"
content:
application/json:
schema:
$ref: "#/components/schemas/DownloadList"
components:
schemas:
DownloadList:
properties:
archiveDownloadList:
type: array
items:
$ref: "#/components/schemas/ArchiveDownload"
required:
- archiveDownloadList
ArchiveDownload:
properties:
downloadUrl:
type: string
sha256Sum:
type: string
targetDir:
type: string
permissionList:
type: array
items:
$ref: "#/components/schemas/PathPermissionItem"
required:
- downloadUrl
- targetDir
- sha256Sum
- permissionList
PathPermissionItem:
properties:
path:
type: string
recursive:
type: boolean
default: false
got code:
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.9.1 DO NOT EDIT.
package api
// ArchiveDownload defines model for ArchiveDownload.
type ArchiveDownload struct {
DownloadUrl string `json:"downloadUrl"`
PermissionList []PathPermissionItem `json:"permissionList"`
Sha256Sum string `json:"sha256Sum"`
TargetDir string `json:"targetDir"`
}
// DownloadList defines model for DownloadList.
type DownloadList struct {
ArchiveDownloadList ArchiveDownload `json:"archiveDownloadList"` // <--- no slice
}
// PathPermissionItem defines model for PathPermissionItem.
type PathPermissionItem struct {
Path *string `json:"path,omitempty"`
Recursive *bool `json:"recursive,omitempty"`
}
expected code
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.9.1 DO NOT EDIT.
package api
// ArchiveDownload defines model for ArchiveDownload.
type ArchiveDownload struct {
DownloadUrl string `json:"downloadUrl"`
PermissionList []PathPermissionItem `json:"permissionList"`
Sha256Sum string `json:"sha256Sum"`
TargetDir string `json:"targetDir"`
}
// DownloadList defines model for DownloadList.
type DownloadList struct {
ArchiveDownloadList []ArchiveDownload `json:"archiveDownloadList"` // <----- slice
}
// PathPermissionItem defines model for PathPermissionItem.
type PathPermissionItem struct {
Path *string `json:"path,omitempty"`
Recursive *bool `json:"recursive,omitempty"`
}
workaround:
openapi: 3.0.4
info:
description: example api
version: v1
title: example api
servers:
- url: "https://example.com"
description: Production
paths:
/download:
get:
summary: "download"
description: "download"
operationId: "getDownload"
responses:
200:
description: "download list"
content:
application/json:
schema:
$ref: "#/components/schemas/DownloadList"
components:
schemas:
DownloadList:
properties:
archiveDownloadList:
$ref: "#/components/schemas/ArchiveDownloadList"
required:
- archiveDownloadList
ArchiveDownloadList:
type: array
items:
$ref: "#/components/schemas/ArchiveDownload"
ArchiveDownload:
properties:
downloadUrl:
type: string
sha256Sum:
type: string
targetDir:
type: string
permissionList:
type: array
items:
$ref: "#/components/schemas/PathPermissionItem"
required:
- downloadUrl
- targetDir
- sha256Sum
- permissionList
PathPermissionItem:
properties:
path:
type: string
recursive:
type: boolean
default: false
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --generate=types,skip-prune --package=api -o test.gen.go test.yamltest.yaml
got code:
expected code
workaround: