Many updates, you will need to update your configuration
Many changes to code generation
We've had many big changes which affect code generation on the back burner, for fear of breaking code dependent on previous behavior, but this was holding back many fixes, so this release, in its default behavior, breaks generated code to be incompatible with existing code. However, we've been able to provide configuration options to disable this new behavior in all cases. So, with small changes to how oapi-codegen
is invoked, you can continue to generate compatible code, however, you will not have these new changes, all of which fix bugs.
Configuration and flag changes
First, we are moving from flag based configuration of the tool, to using a configuration file. The configuration file is directly loaded into the Options struct used by the codegen
package. A number of the former flags are ignored, and the former configuration file will fail to load with default settings.
To help you migrate your configuration options, we've provided several new flags:
--old-config-style
: When set, we will correctly parse all flags and configuration files in the previous way. When it becomes inconvenient to maintain this flag, we will remove it.
--output-config
: When set, oapi-codegen
will output a new-style configuration file based from all flags and an existing configuration file. Combined with the previous flag, you can use the tool to update your configuration files.
If previously you were running a command like:
oapi-codegen --package=petshop --generate="types,client,server,spec" -alias-types petshop-expanded.yaml
You will now get an error:
error processing flags: flags --alias-types aren't supported in new config style, please use --old-style-config or update your configuration
By adding the --old-config-style
, code will be generated:
oapi-codegen --old-config-style --package=petshop --generate="types,client,server,spec" -alias-types petshop-expanded.yaml
But, we're moving away from flags, so you can generate a config file like so:
oapi-codegen --output-config --old-config-style --package=petshop --generate="types,client,server,spec" -alias-types petshop-expanded.yaml
And you will see this output:
package: petshop
generate:
echo-server: true
client: true
models: true
embedded-spec: true
You can save that to a config file, and use that to configure oapi-codegen in the future.
oapi-codegen --config config.yaml petshop-expanded.yaml
Schema merging for allOf
has been rewritten
The expanded petstore example contains an allOf
schema which merges NewPet
properties with an ID:
Pet:
allOf:
</tr></table>
... (truncated)