-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Considering the following schema:
FooProperties:
type: object
properties:
uuid:
type: string
format: uuid
readOnly: true
firstname:
type: string
lastname:
type: string
Foo:
allOf:
- $ref: "#/components/schemas/FooProperties"
- type: object
required:
- uuid
- firstname
- lastname
NewFoo:
allOf:
- $ref: "#/components/schemas/FooProperties"
- type: object
required:
- firstnameAccording to the specs, also confirmed in the https://editor.swagger.io/, and swagger-api/swagger-editor#1212, NewFoo should have firstname as required, and Foo should have all properties as required.
The validation works as expected.
However, the resulting objects in Go are:
type Foo struct {
// Embedded struct due to allOf(#/components/schemas/FooProperties)
FooProperties `yaml:",inline"`
// Embedded fields due to inline allOf schema
}
// FooProperties defines model for FooProperties.
type FooProperties struct {
Firstname *string `json:"firstname,omitempty"`
Lastname *string `json:"lastname,omitempty"`
Uuid *string `json:"uuid,omitempty"`
}
// NewFoo defines model for NewFoo.
type NewFoo struct {
// Embedded struct due to allOf(#/components/schemas/FooProperties)
FooProperties `yaml:",inline"`
// Embedded fields due to inline allOf schema
}Because of the struct embedding, the properties are all pointers instead of values (like when using "required" directly in objects).
Now, because the validation works as expected, this might not be an issue at all. I wonder however if in this case, if the generated code should embed FooProperties as is, or if a new struct should be generated per "merge".
This has been discussed, and sometimes fixed, in several other projects:
- Can optional properties be made required when "allOf" and "discriminator" are used? OAI/OpenAPI-Specification#1870
- Required properties on an extended schema are not handled expectedly cyclosproject/ng-openapi-gen#108
- Required properties in the models with inheritance sylvainlaurent/swagger-validator-maven-plugin#19
- Making fields required during use of allOf acacode/swagger-typescript-api#275
- Failure to correctly validate required in allOf python-openapi/openapi-schema-validator#15
Swiftwork, sausax and hexfusion
Metadata
Metadata
Assignees
Labels
No labels