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

Migrate to libopenapi

Open yozel opened this issue 1 year ago • 10 comments
trafficstars

This pull request is a complete migration to libopenapi. Almost the tests and examples generates the same code, except embedded swaggerSpec files. While semantically its the same, due to change of order of object keys in the Json, it generates a different gzipped base64.

~There is only one tests that fails, which is internal/test/issues/issue-removed-external-ref. And I believe it's related to this: https://github.com/pb33f/libopenapi/issues/219. I'm following/contributing to the thread to solve the issue.~

The generated code continues to use kin-api since validation logic depends on middleware repos, which still uses kin-api.

Test results:

$ go test ./...
?   	github.com/deepmap/oapi-codegen/v2/pkg/ecdsafile	[no test files]
?   	github.com/deepmap/oapi-codegen/v2/pkg/securityprovider	[no test files]
ok  	github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen	0.733s
ok  	github.com/deepmap/oapi-codegen/v2/pkg/codegen	6.210s
ok  	github.com/deepmap/oapi-codegen/v2/pkg/util	(cached)

The MR also includes regenerated *.gen.go files, so you can compare the difference.

$ cd ./internal/test
$ go generate -v ./...
all_of/doc.go
all_of/v1/openapi.gen.go
all_of/v2/openapi.gen.go
any_of/param/doc.go
any_of/param/param.gen.go
any_of/param/param_test.go
client/client.gen.go
client/client_test.go
client/doc.go
components/components.gen.go
components/components_test.go
components/doc.go
externalref/doc.go
externalref/externalref.gen.go
externalref/imports_test.go
externalref/packageA/doc.go
externalref/packageA/externalref.gen.go
externalref/packageB/doc.go
externalref/packageB/externalref.gen.go
issues/issue-1087/api.gen.go
issues/issue-1087/doc.go
issues/issue-1087/deps/deps.gen.go
issues/issue-1087/deps/doc.go
issues/issue-1093/doc.go
issues/issue-1093/issue_test.go
issues/issue-1093/api/child/child.gen.go
issues/issue-1093/api/parent/parent.gen.go
issues/issue-1127/api.gen.go
issues/issue-1127/doc.go
issues/issue-1168/api.gen.go
issues/issue-1168/doc.go
issues/issue-1180/doc.go
issues/issue-1180/issue.gen.go
issues/issue-1180/issue_test.go
issues/issue-1182/pkg1/doc.go
issues/issue-1182/pkg1/pkg1.gen.go
issues/issue-1182/pkg2/doc.go
issues/issue-1182/pkg2/pkg2.gen.go
issues/issue-1189/doc.go
issues/issue-1189/issue1189.gen.go
issues/issue-1208-1209/doc.go
issues/issue-1208-1209/issue-multi-json.gen.go
issues/issue-1208-1209/issue-multi-json_test.go
issues/issue-1212/pkg1/doc.go
issues/issue-1212/pkg1/pkg1.gen.go
issues/issue-1212/pkg2/doc.go
issues/issue-1212/pkg2/pkg2.gen.go
issues/issue-1219/doc.go
issues/issue-1219/issue.gen.go
issues/issue-1219/issue_test.go
issues/issue-1298/doc.go
issues/issue-1298/issue1298.gen.go
issues/issue-1298/issue1298_test.go
issues/issue-312/doc.go
issues/issue-312/issue.gen.go
issues/issue-312/issue_test.go
issues/issue-52/doc.go
issues/issue-52/issue.gen.go
issues/issue-52/issue_test.go
issues/issue-579/gen.go
issues/issue-579/issue.gen.go
issues/issue-579/issue_test.go
issues/issue-832/generate.go
issues/issue-832/issue.gen.go
issues/issue-936/api.gen.go
issues/issue-936/gen.go
issues/issue-grab_import_names/doc.go
issues/issue-grab_import_names/issue.gen.go
issues/issue-grab_import_names/issue_test.go
issues/issue-head-digit-of-httpheader/doc.go
issues/issue-head-digit-of-httpheader/issue.gen.go
issues/issue-head-digit-of-operation-id/doc.go
issues/issue-head-digit-of-operation-id/issue.gen.go
issues/issue-illegal_enum_names/doc.go
issues/issue-illegal_enum_names/issue.gen.go
issues/issue-illegal_enum_names/issue_test.go
issues/issue-removed-external-ref/doc.go
issues/issue-removed-external-ref/gen/spec_base/issue.gen.go
issues/issue-removed-external-ref/gen/spec_ext/issue.gen.go
parameters/doc.go
parameters/parameters.gen.go
parameters/parameters_test.go
schemas/doc.go
schemas/schemas.gen.go
server/doc.go
server/server.gen.go
server/server_test.go
strict-server/strict_test.go
strict-server/chi/server.gen.go
strict-server/chi/server.go
strict-server/chi/types.gen.go
strict-server/client/client.gen.go
strict-server/client/client.go
strict-server/echo/server.gen.go
strict-server/echo/server.go
strict-server/echo/types.gen.go
strict-server/fiber/server.gen.go
strict-server/fiber/server.go
strict-server/fiber/types.gen.go
strict-server/gin/server.gen.go
strict-server/gin/server.go
strict-server/gin/types.gen.go
strict-server/gorilla/server.gen.go
strict-server/gorilla/server.go
strict-server/gorilla/types.gen.go
strict-server/iris/server.gen.go
strict-server/iris/server.go
strict-server/iris/types.gen.go
$ cd examples
$ go generate -v ./...
authenticated-api/echo/main.go
authenticated-api/echo/api/api.gen.go
authenticated-api/echo/api/doc.go
authenticated-api/echo/server/fake_jws.go
authenticated-api/echo/server/jwt_authenticator.go
authenticated-api/echo/server/server.go
authenticated-api/echo/server/server_test.go
custom-client-type/custom-client-type.gen.go
custom-client-type/doc.go
no-vcs-version-override/echo/api/api.gen.go
no-vcs-version-override/echo/api/doc.go
petstore-expanded/petstore-client.gen.go
petstore-expanded/chi/petstore.go
petstore-expanded/chi/petstore_test.go
petstore-expanded/chi/api/petstore.gen.go
petstore-expanded/chi/api/petstore.go
petstore-expanded/echo/petstore.go
petstore-expanded/echo/petstore_test.go
petstore-expanded/echo/pkg_codegen_petstore_test.go
petstore-expanded/echo/api/petstore-server.gen.go
petstore-expanded/echo/api/petstore.go
petstore-expanded/echo/api/models/models.gen.go
petstore-expanded/fiber/petstore.go
petstore-expanded/fiber/petstore_test.go
petstore-expanded/fiber/api/petstore-server.gen.go
petstore-expanded/fiber/api/petstore-types.gen.go
petstore-expanded/fiber/api/petstore.go
petstore-expanded/gin/petstore.go
petstore-expanded/gin/petstore_test.go
petstore-expanded/gin/api/petstore-server.gen.go
petstore-expanded/gin/api/petstore-types.gen.go
petstore-expanded/gin/api/petstore.go
petstore-expanded/gorilla/petstore.go
petstore-expanded/gorilla/petstore_test.go
petstore-expanded/gorilla/api/petstore.gen.go
petstore-expanded/gorilla/api/petstore.go
petstore-expanded/internal/doc.go
petstore-expanded/iris/petstore.go
petstore-expanded/iris/petstore_test.go
petstore-expanded/iris/api/petstore-server.gen.go
petstore-expanded/iris/api/petstore-types.gen.go
petstore-expanded/iris/api/petstore.go
petstore-expanded/strict/petstore.go
petstore-expanded/strict/petstore_test.go
petstore-expanded/strict/api/petstore-server.gen.go
petstore-expanded/strict/api/petstore-types.gen.go
petstore-expanded/strict/api/petstore.go

yozel avatar Dec 18 '23 12:12 yozel

Hey, thanks very much for this PR! This is something I'd started looking at in #1211 but put on hold.

I'll try and have a look at it in a couple of weeks, as I'll need a bit of time to go through all the changes. Appreciate the hard work :raised_hands:

jamietanna avatar Dec 18 '23 16:12 jamietanna

I notice your email address isn't associated with your GitHub account - mind doing that, so it shows correctly in GitHub? (Right now https://github.com/deepmap/oapi-codegen/pull/1388/commits/6860428d084a589508b5d73e069ee073b8c2644b doesn't have your avatar next to it)

jamietanna avatar Dec 18 '23 16:12 jamietanna

@jamietanna thanks for noticing. I was not aware of that, now I added my work email into my account and it shows my avatar.

yozel avatar Dec 18 '23 16:12 yozel

Labelling the implementation right now as breaking - we'll look at what we can do to make it non-breaking if possible :crossed_fingers:

jamietanna avatar Dec 18 '23 16:12 jamietanna

There's a failing test:

--- FAIL: TestGetSwagger (0.00s)
    imports_test.go:27: 
                Error Trace:    /Users/yozel/Projects/oapi-codegen/internal/test/externalref/imports_test.go:27
                Error:          Expected nil, but got: &errors.errorString{s:"path not found: object_c.json"}
                Test:           TestGetSwagger

libopenapi doesn't have InternalizeRefs() which results with externally referencing spec embeddings. I'm also working on that issue (https://github.com/pb33f/libopenapi/issues/222)

yozel avatar Dec 18 '23 17:12 yozel

Any update on this?

zekth avatar Feb 22 '24 12:02 zekth

There's a failing test:

--- FAIL: TestGetSwagger (0.00s)
    imports_test.go:27: 
                Error Trace:    /Users/yozel/Projects/oapi-codegen/internal/test/externalref/imports_test.go:27
                Error:          Expected nil, but got: &errors.errorString{s:"path not found: object_c.json"}
                Test:           TestGetSwagger

libopenapi doesn't have InternalizeRefs() which results with externally referencing spec embeddings. I'm also working on that issue (https://github.com/pb33f/libopenapi/issues/222)

The issue is resolved now

SimonAM avatar Apr 21 '24 03:04 SimonAM

Hi! Is this PR still active? I was considering testing the branch as suggested by https://github.com/deepmap/oapi-codegen/issues/373#issuecomment-1969226056

amahdhaoui-ionos avatar May 02 '24 09:05 amahdhaoui-ionos

Testing this branch, I run into this, however when doing 3.1.0 validation it shows these is a valid spec

error generating code: error generating type definitions: error generating code for type definitions: duplicate typename 'DataStoreExtended_ConnectorEnvironment' detected, can't auto-rename, please use x-go-name to specify your own name for one of them

It is basically error on these and saying these are the same? Even though one has a single _ and the other has two __

CleanShot 2024-05-25 at 09 24 25@2x

But then even removing these,

It errors out again

: api.go:108456:28: '_' must separate successive digits (and 3 more errors)

CleanShot 2024-05-25 at 09 26 40@2x

Which seems like its because that struct type never got defined

TerminalFi avatar May 25 '24 14:05 TerminalFi