What version of ogen are you using?
v1.20.3
Can this issue be reproduced with the latest version?
Yes
What did you do?
openapi: "3.0.3"
info:
title: ogen refcache tag leak repro
version: "0.0.1"
paths:
/foo:
post:
operationId: createFoo
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Foo"
responses:
"200":
description: ok
/bar:
get:
operationId: getBar
responses:
"200":
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/Bar"
components:
schemas:
SharedString:
type: string
# Parsed first — sets extra tags on the shared $ref pointer
Foo:
type: object
properties:
name:
x-oapi-codegen-extra-tags:
mytag: ignore
$ref: "#/components/schemas/SharedString"
# Parsed second — no extra tags, but gets them via mutated refcache
Bar:
type: object
required: [name]
properties:
name:
$ref: "#/components/schemas/SharedString"
What did you expect to see?
The generated struct for Bar should have no extra properties:
// Ref: #/components/schemas/Bar
type Bar struct {
Name SharedString `json:"name"
}
What did you see instead?
The generated struct for Bar has mytag:"ignore" due to a leak from Foo.
// Ref: #/components/schemas/Bar
type Bar struct {
Name SharedString `json:"name" mytag:"ignore"`
}
Workaround
To those facing this, we were able to workaround this issue by wrapping the $ref in allOf which prevents the leak:
# Parsed first — sets extra tags, wrapped in allOf to avoid refcache mutation
Foo:
type: object
properties:
name:
x-oapi-codegen-extra-tags:
mytag: ignore
allOf:
- $ref: "#/components/schemas/SharedString"
What version of ogen are you using?
v1.20.3
Can this issue be reproduced with the latest version?
Yes
What did you do?
What did you expect to see?
The generated struct for
Barshould have no extra properties:What did you see instead?
The generated struct for
Barhasmytag:"ignore"due to a leak fromFoo.Workaround
To those facing this, we were able to workaround this issue by wrapping the
$refinallOfwhich prevents the leak: