Skip to content

Commit aaa2d2b

Browse files
committed
feat(codegen): handle shared schemas
1 parent 26bee6d commit aaa2d2b

2 files changed

Lines changed: 207 additions & 200 deletions

File tree

codegen/pkg/builder/collect.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (b *Builder) collectSchemas() {
132132
c.collectSchemasInResponse(op)
133133
c.collectSchemasInParams(op)
134134
c.collectSchemasInRequest(op)
135-
135+
136136
for _, schema := range c {
137137
if schema.GetReference() == schemaRef {
138138
foundSchema = schema
@@ -147,7 +147,7 @@ func (b *Builder) collectSchemas() {
147147
break
148148
}
149149
}
150-
150+
151151
if foundSchema != nil && !slices.ContainsFunc(schemasByTag["_shared"], func(sp *base.SchemaProxy) bool {
152152
return sp.GetReference() == schemaRef
153153
}) {
@@ -159,6 +159,13 @@ func (b *Builder) collectSchemas() {
159159
}
160160
}
161161

162+
// Sort shared schemas to ensure deterministic order
163+
if sharedSchemas, ok := schemasByTag["_shared"]; ok {
164+
slices.SortFunc(sharedSchemas, func(a, b *base.SchemaProxy) int {
165+
return strings.Compare(a.GetReference(), b.GetReference())
166+
})
167+
}
168+
162169
b.schemasByTag = schemasByTag
163170
}
164171

0 commit comments

Comments
 (0)