-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Describe the bug
When using --inline-schema-options=skipSchemaReuse=true, nested inline objects inside top-level schemas are still merged into a single model if they are structurally identical. This results in fewer generated models than expected.
To Reproduce
Minimal OpenAPI spec (nested-inline-merge.yaml):
openapi: 3.0.3
info:
title: Nested Inline Merge
version: "1.0.0"
paths:
/foo:
get:
responses:
'200':
description: Foo response
content:
application/json:
schema:
type: object
properties:
firstItem:
type: object
properties:
name:
type: string
secondItem:
type: object
properties:
name:
type: stringCommand to generate code:
openapi-generator-cli generate \
-i nested-inline-merge.yaml \
-g go \
--package-name models \
--global-property models \
--inline-schema-options=skipSchemaReuse=true \
-o outExpected behavior
Each nested inline object (firstItem and secondItem) should generate distinct Go structs.
ie:
FooGet200ResponseFirstItemFooGet200ResponseSecondItem
// FooGet200Response struct for FooGet200Response
type FooGet200Response struct {
FirstItem *FooGet200ResponseFirstItem `json:"firstItem,omitempty"`
SecondItem *FooGet200ResponseSecondItem `json:"secondItem,omitempty"`
}Actual behavior
Only FooGet200ResponseFirstItem is generated and is reused for both properties, despite --inline-schema-options=skipSchemaReuse=true.
// FooGet200Response struct for FooGet200Response
type FooGet200Response struct {
FirstItem *FooGet200ResponseFirstItem `json:"firstItem,omitempty"`
SecondItem *FooGet200ResponseFirstItem `json:"secondItem,omitempty"`
}Proposed solution / enhancement
- Extend
InlineModelResolver(or language-specific generator logic) to honorskipSchemaReuse=truefor nested inline objects. - Consider generating unique model names based on path + property name hierarchy for nested inline schemas.
For the go generator, it would be great to be able to still merge the types but create an alias for the second type, so the code could look something like:
type FooGet200ResponseSecondItem = FooGet200ResponseFirstItem
// FooGet200Response struct for FooGet200Response
type FooGet200Response struct {
FirstItem *FooGet200ResponseFirstItem `json:"firstItem,omitempty"`
SecondItem *FooGet200ResponseSecondItem `json:"secondItem,omitempty"`
}which gives the best of both worlds, unique type for usage, but not necessary to create extra models and duplicate the code.