Title: Generates duplicate types and wrong references to enums · Issue #899 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Generates duplicate types and wrong references to enums · Issue #899 · oapi-codegen/oapi-codegen
X Title: Generates duplicate types and wrong references to enums · Issue #899 · oapi-codegen/oapi-codegen
Description: Hi, I am trying to generate a client with the following config: package: "adguardhome" generate: models: true embedded-spec: true client: true output: pkg/go-adguard-home/client.go output-options: skip-prune: false client-type-name: Adgu...
Open Graph Description: Hi, I am trying to generate a client with the following config: package: "adguardhome" generate: models: true embedded-spec: true client: true output: pkg/go-adguard-home/client.go output-options: ...
X Description: Hi, I am trying to generate a client with the following config: package: "adguardhome" generate: models: true embedded-spec: true client: true output: pkg/go-adguard-home/client.go output...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/899
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generates duplicate types and wrong references to enums","articleBody":"Hi,\r\n\r\nI am trying to generate a client with the following config:\r\n\r\n```yaml\r\npackage: \"adguardhome\"\r\ngenerate:\r\n models: true\r\n embedded-spec: true\r\n client: true\r\noutput: pkg/go-adguard-home/client.go\r\noutput-options:\r\n skip-prune: false\r\n client-type-name: AdguardHomeClient\r\n```\r\n\r\nwith this openapi\r\n\r\nhttps://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/openapi/openapi.yaml\r\n\r\nBut have some minor issues:\r\n\r\n1. Duplicate Types\r\n```golang\r\n// AccessListResponse Client and host access list. Each of the lists should contain only unique elements. In addition, allowed and disallowed lists cannot contain the same elements.\r\ntype AccessListResponse = AccessList\r\n\r\n// ClientsFindResponse Client search results.\r\ntype ClientsFindResponse = []ClientsFindEntry\r\n\r\n...\r\n\r\ntype AccessListResponse struct {\r\n\tBody []byte\r\n\tHTTPResponse *http.Response\r\n // Think this reference to self is \"wrong\" and the other type should be used\r\n\tJSON200 *AccessListResponse\r\n}\r\n\r\ntype ClientsFindResponse struct {\r\n\tBody []byte\r\n\tHTTPResponse *http.Response\r\n // Think this reference to self is \"wrong\" and the other type should be used\r\n\tJSON200 *ClientsFindResponse\r\n}\r\n```\r\n\r\nI think this collision is unintended and only because the \"schema\" that is referenced has the same name as the generated type for the answer of the get request.\r\n\r\nFor the second type collision x-go-name rewrite works, for the first it does not\r\n\r\n```yaml\r\n 'AccessListResponse':\r\n 'x-go-name': 'AccessListResponseType'\r\n '$ref': '#/components/schemas/AccessList'\r\n 'AccessSetRequest':\r\n '$ref': '#/components/schemas/AccessList'\r\n 'AccessList':\r\n 'description': >\r\n Client and host access list. Each of the lists should contain only\r\n unique elements. In addition, allowed and disallowed lists cannot\r\n contain the same elements.\r\n 'properties':\r\n``` \r\nthis does not work,\r\n\r\n```yaml\r\n 'ClientsFindResponse':\r\n 'x-go-name': 'ClientsFindResponseType'\r\n 'type': 'array'\r\n 'description': 'Client search results.'\r\n 'items':\r\n '$ref': '#/components/schemas/ClientsFindEntry\r\n```\r\nthis works as expected\r\n\r\n2. Wrong references for enums\r\n\r\n```golang\r\n// Defines values for DNSConfigBlockingMode.\r\nconst (\r\n\tCustomIp DNSConfigBlockingMode = \"custom_ip\"\r\n\tDefault DNSConfigBlockingMode = \"default\"\r\n\tNullIp DNSConfigBlockingMode = \"null_ip\"\r\n\tNxdomain DNSConfigBlockingMode = \"nxdomain\"\r\n\tRefused DNSConfigBlockingMode = \"refused\"\r\n)\r\n\r\n... \r\n\r\ntype DnsInfoResponse struct {\r\n\tBody []byte\r\n\tHTTPResponse *http.Response\r\n\tJSON200 *struct {\r\n\t\tBlockingIpv4 *string `json:\"blocking_ipv4,omitempty\"`\r\n\t\tBlockingIpv6 *string `json:\"blocking_ipv6,omitempty\"`\r\n // think this should be DNSConfigBlockingMode, as there is no other blocking mode in the openapi.yaml\r\n\t\tBlockingMode *N200BlockingMode `json:\"blocking_mode,omitempty\"`\r\n```\r\n\r\nthe openapi lines matching this seem to be\r\n\r\n```yaml\r\n '/dns_info':\r\n 'get':\r\n 'tags':\r\n - 'global'\r\n 'operationId': 'dnsInfo'\r\n 'summary': 'Get general DNS parameters'\r\n 'responses':\r\n '200':\r\n 'description': 'OK'\r\n 'content':\r\n 'application/json':\r\n 'schema':\r\n 'allOf':\r\n - '$ref': '#/components/schemas/DNSConfig'\r\n - 'type': 'object'\r\n 'properties':\r\n```\r\n\r\nand\r\n\r\n```yaml\r\n 'DNSConfig':\r\n 'type': 'object'\r\n 'description': 'Query log configuration'\r\n 'properties':\r\n 'bootstrap_dns':\r\n 'type': 'array'\r\n 'description': >\r\n Bootstrap servers, port is optional after colon. Empty value will\r\n reset it to default values.\r\n 'items':\r\n 'type': 'string'\r\n 'example':\r\n - '8.8.8.8:53'\r\n - '1.1.1.1:53'\r\n 'upstream_dns':\r\n 'type': 'array'\r\n 'description': >\r\n Upstream servers, port is optional after colon. Empty value will\r\n reset it to default values.\r\n 'items':\r\n 'type': 'string'\r\n 'example':\r\n - 'tls://1.1.1.1'\r\n - 'tls://1.0.0.1'\r\n 'upstream_dns_file':\r\n 'type': 'string'\r\n 'protection_enabled':\r\n 'type': 'boolean'\r\n 'dhcp_available':\r\n 'type': 'boolean'\r\n 'ratelimit':\r\n 'type': 'integer'\r\n 'blocking_mode':\r\n 'type': 'string'\r\n 'enum':\r\n - 'default'\r\n - 'refused'\r\n - 'nxdomain'\r\n - 'null_ip'\r\n - 'custom_ip'\r\n```\r\n\r\nsomehow this isn't resolved correctly\r\nAs I am new into openapi and generating clients, I don't know if it something that I should solve via config - or a bug (in oapi-codegen - or the openapi yaml). Would be great if I could get some input on this issues.","author":{"url":"https://github.com/markussiebert","@type":"Person","name":"markussiebert"},"datePublished":"2022-12-13T20:28:21Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/899"}
| 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:ae7d6036-f397-75ce-24de-965430bcaf65 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82E6:33A683:2BCF616:398199A:6AF9C1FC |
| html-safe-nonce | 075b9992fc7a1386e1b24c98b33826a498f5009f1226a43fa748294e30d801a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkU2OjMzQTY4MzoyQkNGNjE2OjM5ODE5OUE6NkFGOUMxRkMiLCJ2aXNpdG9yX2lkIjoiNzA3NTg5NjMwNjI3NDI1NTM1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7c42edc87c69518b0c567309684d36a208af4ad75353c4efb7f9843d180956e9 |
| hovercard-subject-tag | issue:1495099128 |
| 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/899/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fc269dceefee761f1def07e9c1029c4193c8e066e187e3347a742d2e5773ed78/oapi-codegen/oapi-codegen/issues/899 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fc269dceefee761f1def07e9c1029c4193c8e066e187e3347a742d2e5773ed78/oapi-codegen/oapi-codegen/issues/899 |
| og:image:alt | Hi, I am trying to generate a client with the following config: package: "adguardhome" generate: models: true embedded-spec: true client: true output: pkg/go-adguard-home/client.go output-options: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markussiebert |
| 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