Skip to content

Conversation

@percivalalb
Copy link
Contributor

@percivalalb percivalalb commented Apr 22, 2024

This MR adds a function (ReferencesComponentInRootDocument) to check if a component reference references the same document or element as another component reference in the root document's #/components/<type>. If it does, it returns the name of it in the form #/components/<type>/NameXXX.

It does this by keeping track of the source file paths of schemas in multi-file'd specs.

This enables the amalgamation of schemas which reference the same underlying model which removes very annoying to use anonymous structs in generated models when using codegen tools like oapi-codegen.

TODO: add MR in oapi-codegen displaying improved model generation. oapi-codegen/oapi-codegen#1573

@fenollp
Copy link
Collaborator

fenollp commented Apr 29, 2024

Hello!
How about a func that, given a doc and a Schema, returns a *SchemaRef (a ptr under doc) or nil? Would this not cover your use case?

Note: the refs.go file is generated.

@percivalalb
Copy link
Contributor Author

Hello!

How about a func that, given a doc and a Schema, returns a *SchemaRef (a ptr under doc) or nil? Would this not cover your use case?

Note: the refs.go file is generated.

Yes, if it also returned the name in the #components/schemas/...

Input: doc, Schema
Output: name, SchemaRef

I'll have a look at moving it out of the gen'ed file

@percivalalb
Copy link
Contributor Author

I've moved the alternations out of the code gen'ed files, sorry I'm still getting familar with the project setup and just thrown everything in the helper file. I'd like to ad some unit tests of couse but hopefully this is more to your liking.

@percivalalb percivalalb force-pushed the alb/reconsole-schema-refs branch 2 times, most recently from 3897eef to 11a0e6f Compare June 2, 2024 11:04
@percivalalb percivalalb changed the title Add function to check if a schema matches one in root document Draft: Add function to check if a schema matches one in root document Jun 2, 2024
@fenollp
Copy link
Collaborator

fenollp commented Jun 2, 2024

This is looking pretty good!
Could you re-push the docs? It fails CI.
Also please send your tests away :) And an Example that shows usage of the function.

@percivalalb
Copy link
Contributor Author

percivalalb commented Jun 2, 2024

Things to do:

Heads up I'll be away for 10 days, so I won't be developing this PR for a bit

It does this by keeping track of the source file paths of schemas in
multi-file'd specs.

This enables the amalgamation of schemas which reference the same underlying
model which removes *very annoying* to use anonymous structs in generated
models when using codegen tools like oapi-codegen.
And populate all ref types
@percivalalb percivalalb force-pushed the alb/reconsole-schema-refs branch from 8de52a7 to c3fe41b Compare June 15, 2024 07:20
@percivalalb
Copy link
Contributor Author

percivalalb commented Jun 15, 2024

Address most of the bullet points. Where is the best place for the example?

Edit: Added an example to the READMD.md

@percivalalb percivalalb changed the title Draft: Add function to check if a schema matches one in root document Add function to check if a schema matches one in root document Jun 15, 2024
@fenollp fenollp changed the title Add function to check if a schema matches one in root document openapi3: introduce ReferencesComponentInRootDocument(doc *T, ref componentRef) (string, bool) Jun 16, 2024
@fenollp fenollp merged commit 061c378 into getkin:master Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants