You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working with the 'petstore-expanded' spec, since I'm new to oapi-codegen. Here's my project structure at the moment:
├──petstore-expanded.yaml
└──pet/
For my use case, I'm needing certain types to be defined within other packages (such as the pet package above). I originally followed what the readme mentions about this, but with this generator config file instead of just command arguments:
You'll notice I'm not using a full path like abc.com/path/to/package. I haven't published my project anywhere yet, so assuming a relative path like mine isn't valid, I guess my first question is: Why is there a reliance on a full path? Regardless, constructing that generator config file based on the guidelines in this part of the readme led me to cmd/oapi-codegen/oapi-codegen.go, and then I noticed that import-mapping is deprecated. I couldn't make sense of the "new format" that's mentioned in that deprecation comment, so if someone could provide an example of that, I'd appreciate it.
Anyway, while searching for the replacement of import-mapping, I ran into this comment on another thread (and many other threads referencing said comment), so I decided to try that method out, and replaced import-mapping with additional-imports, so that my top-level generator config looked like this
But when I execute oapi-codegen -config petstore.cfg.yaml petstore-expanded.yaml I get the error:
error loading swagger spec : map key "NewPet" not found
where the key it highlights could be any of the types defined in pet/spec.yaml (i.e., NewPet or Pet or Error).
I'm sure I've messed things up, by trying both methods. Whatever the correct way forward is, if I could get some guidance on how to separate certain types into their respective packages, I would greatly appreciate it!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently working with the 'petstore-expanded' spec, since I'm new to oapi-codegen. Here's my project structure at the moment:
For my use case, I'm needing certain types to be defined within other packages (such as the
pet
package above). I originally followed what the readme mentions about this, but with this generator config file instead of just command arguments:You'll notice I'm not using a full path like
abc.com/path/to/package
. I haven't published my project anywhere yet, so assuming a relative path like mine isn't valid, I guess my first question is: Why is there a reliance on a full path? Regardless, constructing that generator config file based on the guidelines in this part of the readme led me to cmd/oapi-codegen/oapi-codegen.go, and then I noticed that import-mapping is deprecated. I couldn't make sense of the "new format" that's mentioned in that deprecation comment, so if someone could provide an example of that, I'd appreciate it.Anyway, while searching for the replacement of import-mapping, I ran into this comment on another thread (and many other threads referencing said comment), so I decided to try that method out, and replaced
import-mapping
withadditional-imports
, so that my top-level generator config looked like thisAnd at this point my directory tree looked like this:
where
petstore-expanded.yaml
containsafter moving the schemas to
pet/spec.yaml
, it containsand my generator config inside the
pet
package containsBut when I execute
oapi-codegen -config petstore.cfg.yaml petstore-expanded.yaml
I get the error:error loading swagger spec : map key "NewPet" not found
where the key it highlights could be any of the types defined in
pet/spec.yaml
(i.e.,NewPet
orPet
orError
).I'm sure I've messed things up, by trying both methods. Whatever the correct way forward is, if I could get some guidance on how to separate certain types into their respective packages, I would greatly appreciate it!
Beta Was this translation helpful? Give feedback.
All reactions