Title: `allOf` code generation does not work with types from other packages · Issue #655 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: `allOf` code generation does not work with types from other packages · Issue #655 · oapi-codegen/oapi-codegen
X Title: `allOf` code generation does not work with types from other packages · Issue #655 · oapi-codegen/oapi-codegen
Description: I have some standardized error struct which is used for all parts of my API, and put it into a separate package to make it easily reuasble components: schemas: Error: type: object properties: message: type: string details: type: array it...
Open Graph Description: I have some standardized error struct which is used for all parts of my API, and put it into a separate package to make it easily reuasble components: schemas: Error: type: object properties: messa...
X Description: I have some standardized error struct which is used for all parts of my API, and put it into a separate package to make it easily reuasble components: schemas: Error: type: object properties: messa...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/655
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`allOf` code generation does not work with types from other packages","articleBody":"I have some standardized error struct which is used for all parts of my API, and put it into a separate package to make it easily reuasble\r\n```yaml\r\ncomponents:\r\n schemas:\r\n Error:\r\n type: object\r\n properties:\r\n message:\r\n type: string\r\n details:\r\n type: array\r\n items:\r\n $ref: \"#/components/schemas/ErrorDetail\"\r\n ErrorDetail:\r\n type: object\r\n properties:\r\n message:\r\n type: string\r\n target:\r\n type: string\r\n```\r\n\r\nThis all works fine, but in some scenarios I'd like to have an example error message. So I use `allOf` to merge this struct with additional details:\r\n```yaml\r\nallOf:\r\n - $ref: \"#/components/schemas/Error\" # I imported the errors.yaml in this components/schema to make errors.Error available.\r\n - type: object\r\n properties:\r\n message:\r\n example: \"File non-existing.txt not found\"\r\n```\r\n\r\nThis results in the follow code:\r\n```go\r\ntype FileNotFound struct {\r\n\t// Optional list of additional error details.\r\n\tDetails *[]ErrorDetail `json:\"details,omitempty\"`\r\n\tMessage interface{} `json:\"message\"`\r\n}\r\n```\r\n\r\nThe problem is that `ErrorDetail` is not defined (it is defined in another package containing the generated code of errors.yaml). Error itself is working as the code generator created this line\r\n```go\r\ntype Error = externalRef0.Error\r\n```\r\n\r\n# Workaround\r\nImport ErrorDetail in the yaml file as well:\r\n```yaml\r\n ErrorDetail:\r\n # This is needed for workaround a code generation bug\r\n $ref: \"./errors.yaml#/components/schemas/ErrorDetail\"\r\n```\r\nand it generates\r\n```go\r\ntype ErrorDetail = externalRef0.ErrorDetail\r\n```\r\n\r\nUnfortunately, linter detect that the ErrorDetail object is not used/referenced, so it issues a warning (in my IDE)","author":{"url":"https://github.com/veger","@type":"Person","name":"veger"},"datePublished":"2022-07-04T09:01:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/655/oapi-codegen/issues/655"}
| 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:f35e20ff-ad85-9d7e-214a-c6543d59b68a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D6DE:383777:34D73A2:490C654:6A4F2DFD |
| html-safe-nonce | cfdeca871017f9d48d29c2cf5336b18333bcbd458e3b65ea8de84d9db572d0a7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkRFOjM4Mzc3NzozNEQ3M0EyOjQ5MEM2NTQ6NkE0RjJERkQiLCJ2aXNpdG9yX2lkIjoiNDc1ODM4MDU2Mzc4MTMzMjQ3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 48fc7719f8bd84de62a33a307916505a279efc88dd8c102d848cb199dc734a9c |
| hovercard-subject-tag | issue:1292854702 |
| 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/655/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cdaab1deac77a52bd843a1d7944f38d24646de2248197065e7c0c7f7976d3338/oapi-codegen/oapi-codegen/issues/655 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cdaab1deac77a52bd843a1d7944f38d24646de2248197065e7c0c7f7976d3338/oapi-codegen/oapi-codegen/issues/655 |
| og:image:alt | I have some standardized error struct which is used for all parts of my API, and put it into a separate package to make it easily reuasble components: schemas: Error: type: object properties: messa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | veger |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| 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 | 2b8f23afb982271f1b22258a94aede67a6b77760 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width