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
A big change has come in which handling of external references (also called import mappings) is much more resilient and predictable for generated code.
This allows cases where multiple files referencing each other (for instance if you've split your API across multiple files, and join them using $refs) now correctly generate code.
There are a few cases that won't be covered, that we'll complete in #1440 but until then, it hopefully should work better.
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
-
🔊 Notable features
Nullable
typesIt's possible that you want to be able to determine whether a field isn't sent, is sent as
null
or has a value.For instance, if you had the following OpenAPI property:
The current behaviour in oapi-codegen is to generate:
However, you lose the ability to understand the three cases, as there's no way to distinguish two of the types from each other:
S.Field == nil
)null
? (Can be checked withS.Field == nil
)S.Field != nil && *S.Field == "123"
)Therefore, as requested in #1039, this is now possible to represent with the
nullable.Nullable
type from our new library, oapi-codegen/nullable.If you configure your generator's Output Options as so:
You will now receive the following output:
Note that this is opt-in only, due to it being a break in existing signatures and behaviour.
You can find out more about how this works in a blog post with further details.
External references are now handled better
A big change has come in which handling of external references (also called import mappings) is much more resilient and predictable for generated code.
This allows cases where multiple files referencing each other (for instance if you've split your API across multiple files, and join them using
$ref
s) now correctly generate code.There are a few cases that won't be covered, that we'll complete in #1440 but until then, it hopefully should work better.
Thank you to Ejendomstorvet for sponsoring this work.
🚀 New features and improvements
nullable.Nullable
for nullable properties (Allow generatingnullable.Nullable
for nullable properties #1404) @sonasingh46IsMediaTypeJson
(Support media type parameters forIsMediaTypeJson
#1386) @jamietanna.Required
toBindStyledParameterWithLocation
andBindStyledParameter
(Pass.Required
toBindStyledParameterWithLocation
andBindStyledParameter
#1315) @renom🐛 Bug fixes
os.Exit(1)
only frommain()
(refactor(cmd): Useos.Exit(1)
only frommain()
#1398) @alexandear.Required
toBindStyledParameterWithLocation
andBindStyledParameter
(Pass.Required
toBindStyledParameterWithLocation
andBindStyledParameter
#1315) @renom📝 Documentation updates
import-mapping
with URLs (Document how to useimport-mapping
with URLs #1428) @jamietanna👻 Maintenance
📦 Dependency updates
New Contributors
.Required
toBindStyledParameterWithLocation
andBindStyledParameter
#1315This discussion was created from the release v2.1.0: Nullable, external reference improvements, x-order, and many more!.
Beta Was this translation helpful? Give feedback.
All reactions