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

Generate anonymous objects referenced in schemas

Open jamietanna opened this issue 3 years ago • 8 comments

Closes #626, #636.

jamietanna avatar Jun 30 '22 08:06 jamietanna

I am very interested to try it, when it is finished, as I think it is solving a similar issue I am experiencing... :+1:

veger avatar Jul 13 '22 15:07 veger

Hi guys, I was wondering if there was any update on that issue ?

riftsin avatar Nov 17 '22 07:11 riftsin

@deepmap-marcinr I think I may need a hand with the PascalSchema error, currently trying to work out the intent of those tests to work out what handling needs to be added

jamietanna avatar Nov 23 '22 16:11 jamietanna

I've got this working finally :clap:

If you're happy with it, @deepmap-marcinr, I'll sort out the Git history then merge it.

I'll test it out with a few other specs that have been mentioned to be affected, too

jamietanna avatar Nov 25 '22 17:11 jamietanna

Got a couple of tweaks to make:

  • anonymous requestBodies
  • ~anonymous parameters~
  • handle when there's i.e. content: {}

jamietanna avatar Nov 27 '22 13:11 jamietanna

Bump

mmorells avatar May 09 '23 15:05 mmorells

Is there any updated on this? It is impacting using go generate for k8s Object DeepCopy etc, as the inlined anonymous structs cannot be consumed to generate the functions.

Simplifying the issue, we have this generated code:

type MyBucket struct {
	Spec *struct {
		
		ArchivePeriod *BucketSpecArchivePeriod `json:"archivePeriod,omitempty"`
	 	Cors          *struct {
	 		 ...
	 	}
	 	// other fields
}       

when running go generated ./generated we get the following error:

└─( go generate ./generated
command-line-arguments:-: name requested for invalid type: struct{Cors *struct{MaxAgeSeconds *float32 "json:\"maxAgeSeconds,omitempty\""; Methods *[]string "json:\"methods,omitempty\""; Origins *[]string "json:\"origins,omitempty\""; ResponseHeaders *[]string "json:\"responseHeaders,omitempty\""} "json:\"cors,omitempty\""; Status *struct{FromProvider *map[string]interface{} "json:\"fromProvider,omitempty\""} "json:\"status,omitempty\""}
Error: not all generators ran successfully
run `controller-gen object paths=types.gen.go -w` to see all available markers, or `controller-gen object paths=types.gen.go -h` for usage
generated/types.gen.go:6: running "controller-gen": exit status 1

By trying a few different combinations, it appears that the anonymoust structs are the cause of the error. Thanks!

massenz avatar Oct 03 '23 00:10 massenz