Title: strict server returns wrong JSON for array responses · Issue #1147 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: strict server returns wrong JSON for array responses · Issue #1147 · oapi-codegen/oapi-codegen
X Title: strict server returns wrong JSON for array responses · Issue #1147 · oapi-codegen/oapi-codegen
Description: spec: # openapi.yaml openapi: 3.0.3 info: title: Test description: Test version: 1.0.0 paths: /test/1: get: responses: 200: description: OK content: application/json: schema: type: object properties: string: type: string number: type: nu...
Open Graph Description: spec: # openapi.yaml openapi: 3.0.3 info: title: Test description: Test version: 1.0.0 paths: /test/1: get: responses: 200: description: OK content: application/json: schema: type: object propertie...
X Description: spec: # openapi.yaml openapi: 3.0.3 info: title: Test description: Test version: 1.0.0 paths: /test/1: get: responses: 200: description: OK content: application/json: schema: type: object propertie...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/1147
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"strict server returns wrong JSON for array responses","articleBody":"spec:\r\n```\r\n# openapi.yaml\r\nopenapi: 3.0.3\r\ninfo:\r\n title: Test\r\n description: Test\r\n version: 1.0.0\r\npaths:\r\n /test/1:\r\n get:\r\n responses:\r\n 200:\r\n description: OK\r\n content:\r\n application/json:\r\n schema:\r\n type: object\r\n properties:\r\n string:\r\n type: string\r\n number:\r\n type: number\r\n required:\r\n - string\r\n - number\r\n /test/2:\r\n get:\r\n responses:\r\n 200:\r\n $ref: '#/components/responses/test_response'\r\n /test/3:\r\n get:\r\n responses:\r\n 200:\r\n $ref: '#/components/responses/test_array_response'\r\n /test/4:\r\n get:\r\n responses:\r\n 200:\r\n $ref: '#/components/responses/test_array_response2'\r\n\r\ncomponents:\r\n schemas:\r\n test:\r\n type: object\r\n properties:\r\n string:\r\n type: string\r\n number:\r\n type: number\r\n required:\r\n - string\r\n - number\r\n test_array:\r\n type: array\r\n items:\r\n $ref: '#/components/schemas/test'\r\n responses:\r\n test_response:\r\n description: Test response\r\n content:\r\n application/json:\r\n schema:\r\n $ref: '#/components/schemas/test'\r\n test_array_response:\r\n description: Test array response\r\n content:\r\n application/json:\r\n schema:\r\n type: array\r\n items:\r\n $ref: '#/components/schemas/test'\r\n test_array_response2:\r\n description: Test array response 2\r\n content:\r\n application/json:\r\n schema:\r\n $ref: '#/components/schemas/test_array'\r\n```\r\n\r\ngenerate:\r\n```\r\noapi-codegen \\\r\n -generate types,client,server,strict-server,spec \\\r\n -package api \\\r\n -o api/test.gen.go \\\r\n openapi.yaml\r\n```\r\n\r\nrun:\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"context\"\r\n\t\"github.com/labstack/echo/v4\"\r\n\t\"log\"\r\n\t\"test/api\"\r\n)\r\n\r\ntype impl struct{}\r\n\r\nfunc (i impl) GetTest4(ctx context.Context, request api.GetTest4RequestObject) (api.GetTest4ResponseObject, error) {\r\n\treturn api.GetTest4200JSONResponse{TestArrayResponse2JSONResponse: []api.Test{\r\n\t\t{String: \"s\", Number: 1},\r\n\t\t{String: \"str\", Number: 2},\r\n\t}}, nil\r\n}\r\n\r\nfunc (i impl) GetTest3(ctx context.Context, request api.GetTest3RequestObject) (api.GetTest3ResponseObject, error) {\r\n\treturn api.GetTest3200JSONResponse{TestArrayResponseJSONResponse: []api.Test{\r\n\t\t{String: \"s\", Number: 1},\r\n\t\t{String: \"str\", Number: 2},\r\n\t}}, nil\r\n}\r\n\r\nfunc (i impl) GetTest1(ctx context.Context, request api.GetTest1RequestObject) (api.GetTest1ResponseObject, error) {\r\n\treturn api.GetTest1200JSONResponse{String: \"string\", Number: 1}, nil\r\n}\r\n\r\nfunc (i impl) GetTest2(ctx context.Context, request api.GetTest2RequestObject) (api.GetTest2ResponseObject, error) {\r\n\treturn api.GetTest2200JSONResponse{\r\n\t\tTestResponseJSONResponse: api.TestResponseJSONResponse{String: \"string\", Number: 1},\r\n\t}, nil\r\n}\r\n\r\nfunc main() {\r\n\te := echo.New()\r\n\tsrv := api.NewStrictHandler(impl{}, nil)\r\n\tapi.RegisterHandlers(e, srv)\r\n\tlog.Fatal(e.Start(\"localhost:8080\"))\r\n}\r\n```\r\n\r\ncurl\r\n```\r\ncurl localhost:8080/test/1\r\n{\"number\":1,\"string\":\"string\"}\r\n\r\ncurl localhost:8080/test/2\r\n{\"number\":1,\"string\":\"string\"}\r\n\r\ncurl localhost:8080/test/3\r\n{\"TestArrayResponseJSONResponse\":[{\"number\":1,\"string\":\"s\"},{\"number\":2,\"string\":\"str\"}]}\r\n\r\ncurl localhost:8080/test/4\r\n{\"TestArrayResponse2JSONResponse\":[{\"number\":1,\"string\":\"s\"},{\"number\":2,\"string\":\"str\"}]}\r\n```\r\n\r\nLast 2 responses are not as as expected","author":{"url":"https://github.com/const-tmp","@type":"Person","name":"const-tmp"},"datePublished":"2023-07-15T20:26:42Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/1147"}
| 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:d582ba33-5335-0e90-75ac-b01ae78a73f3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93B2:DE4D0:2E3715D:3CEDC6D:6AF9CFEC |
| html-safe-nonce | 0d37c61cc5d25bb15e48d4e95eeddeb8ebadf539d7ebcfac23f13e1373fde94d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0IyOkRFNEQwOjJFMzcxNUQ6M0NFREM2RDo2QUY5Q0ZFQyIsInZpc2l0b3JfaWQiOiI1MDI2MDk3NDIwMjI0Mjg2NzAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c0a650ca13f1c3f8968b5ff6e7fd1f8df4a14599fd166c69995ccf034fe55001 |
| hovercard-subject-tag | issue:1806317746 |
| 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/1147/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be15dc8ae94b151385f3e1106ffd7218652b84c2503bb48f67fa9f17903798e6/oapi-codegen/oapi-codegen/issues/1147 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be15dc8ae94b151385f3e1106ffd7218652b84c2503bb48f67fa9f17903798e6/oapi-codegen/oapi-codegen/issues/1147 |
| og:image:alt | spec: # openapi.yaml openapi: 3.0.3 info: title: Test description: Test version: 1.0.0 paths: /test/1: get: responses: 200: description: OK content: application/json: schema: type: object propertie... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | const-tmp |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width