oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Reconcile matching schemas in root document to avoid anonymous structs

Open percivalalb opened this issue 1 year ago • 2 comments

For https://github.com/deepmap/oapi-codegen/issues/1362

OpenAPI specifications can be spread across different files for maintainability. However this is not great for code-gen which can't recognise when two schema refs refer to the same model. This results in the code-gen using duplicating anonymous structs (which can't easily be used).

I have added a patch to kin upstream (https://github.com/getkin/kin-openapi/pull/945) which identifies when a ref refers to a schema from the root #/components/schemas and makes use of the go model generated from that.

See https://github.com/oapi-codegen/oapi-codegen/pull/1573/commits/f71a97a6c8d289616263a2a864ddf1da51ffbd0d which shows the change codegen changes:

image

Note: Also adds test spec to test for regression against #1572

percivalalb avatar Apr 22 '24 20:04 percivalalb

The changes needed to the kin-openapi library are present in v0.126.0, I'll wait for https://github.com/oapi-codegen/oapi-codegen/pull/1689 to be merged before completing this PR

percivalalb avatar Jul 07 '24 15:07 percivalalb

This is now ready for review

percivalalb avatar Jul 09 '24 10:07 percivalalb