Title: Required inheritance and generated objects when using allOf · Issue #531 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Required inheritance and generated objects when using allOf · Issue #531 · oapi-codegen/oapi-codegen
X Title: Required inheritance and generated objects when using allOf · Issue #531 · oapi-codegen/oapi-codegen
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: obje...
Open Graph 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: "#/compon...
X 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: "#/c...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/531
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Required inheritance and generated objects when using allOf","articleBody":"Considering the following schema:\r\n\r\n```yaml\r\n FooProperties:\r\n type: object\r\n properties:\r\n uuid:\r\n type: string\r\n format: uuid\r\n readOnly: true\r\n firstname:\r\n type: string\r\n lastname:\r\n type: string\r\n\r\n Foo:\r\n allOf:\r\n - $ref: \"#/components/schemas/FooProperties\"\r\n - type: object\r\n required:\r\n - uuid\r\n - firstname\r\n - lastname\r\n\r\n NewFoo:\r\n allOf:\r\n - $ref: \"#/components/schemas/FooProperties\"\r\n - type: object\r\n required:\r\n - firstname\r\n```\r\n\r\nAccording to the specs, also confirmed in the https://editor.swagger.io/, and https://github.com/swagger-api/swagger-editor/issues/1212, `NewFoo` should have `firstname` as required, and `Foo` should have all properties as required.\r\n\r\nThe validation works as expected.\r\n\r\nHowever, the resulting objects in Go are:\r\n\r\n```go\r\ntype Foo struct {\r\n\t// Embedded struct due to allOf(#/components/schemas/FooProperties)\r\n\tFooProperties `yaml:\",inline\"`\r\n\t// Embedded fields due to inline allOf schema\r\n}\r\n\r\n// FooProperties defines model for FooProperties.\r\ntype FooProperties struct {\r\n\tFirstname *string `json:\"firstname,omitempty\"`\r\n\tLastname *string `json:\"lastname,omitempty\"`\r\n\tUuid *string `json:\"uuid,omitempty\"`\r\n}\r\n\r\n// NewFoo defines model for NewFoo.\r\ntype NewFoo struct {\r\n\t// Embedded struct due to allOf(#/components/schemas/FooProperties)\r\n\tFooProperties `yaml:\",inline\"`\r\n\t// Embedded fields due to inline allOf schema\r\n}\r\n```\r\n\r\nBecause of the struct embedding, the properties are all pointers instead of values (like when using \"required\" directly in objects).\r\n\r\nNow, 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\".\r\n\r\nThis has been discussed, and sometimes fixed, in several other projects:\r\n- https://github.com/OAI/OpenAPI-Specification/issues/1870\r\n- https://github.com/cyclosproject/ng-openapi-gen/issues/108\r\n- https://github.com/sylvainlaurent/swagger-validator-maven-plugin/issues/19\r\n- https://github.com/acacode/swagger-typescript-api/issues/275\r\n- https://github.com/p1c2u/openapi-schema-validator/issues/15\r\n\r\n","author":{"url":"https://github.com/florentchauveau","@type":"Person","name":"florentchauveau"},"datePublished":"2022-02-23T10:25:58Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/531"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f26774eb-5a77-37c3-3dc1-5fce16341272 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CC6:3DEE78:2BA174D:3965869:6AF9C282 |
| html-safe-nonce | d956925429ffb9815bcf1d4d1a3d0a382fef9a2319d40945747de6b732b0c4de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0M2OjNERUU3ODoyQkExNzREOjM5NjU4Njk6NkFGOUMyODIiLCJ2aXNpdG9yX2lkIjoiNzgxNzU4NTQ4OTgzNjg4NDYxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eaea80dfe43d56e7777e60a711afdbeb2a95b0227432544ae511951ec538e5cf |
| hovercard-subject-tag | issue:1147909738 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/oapi-codegen/oapi-codegen/531/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7b17fe1794cbbd0763a41a16d676bacaadc43e319470f6132c75801c3b2def1a/oapi-codegen/oapi-codegen/issues/531 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7b17fe1794cbbd0763a41a16d676bacaadc43e319470f6132c75801c3b2def1a/oapi-codegen/oapi-codegen/issues/531 |
| og:image:alt | Considering the following schema: FooProperties: type: object properties: uuid: type: string format: uuid readOnly: true firstname: type: string lastname: type: string Foo: allOf: - $ref: "#/compon... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | florentchauveau |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| go-import | github.com/oapi-codegen/oapi-codegen git https://github.com/oapi-codegen/oapi-codegen.git |
| octolytics-dimension-user_id | 142752710 |
| octolytics-dimension-user_login | oapi-codegen |
| octolytics-dimension-repository_id | 173009358 |
| octolytics-dimension-repository_nwo | oapi-codegen/oapi-codegen |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 173009358 |
| octolytics-dimension-repository_network_root_nwo | oapi-codegen/oapi-codegen |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width