Skip to content

Conversation

@natsukagami
Copy link
Contributor

Short Description

Allow primitive types (ints, floats, string types) to be replaced with an option, primitive-mapping, in the YAML configuration.

Motivation

Sometimes it is desirable to use a custom wrappers or different types entirely for the hard-coded types generated in oapi-codegen.
One of such reasons is for tighter controls over JSON marshalling (e.g. check for missing fields or perform some custom validation).

This can already be done with x-go-type extension tag, but it is very painful to do for e.g. every integer parameter in the whole YAML spec.

What has changed?

This is not a breaking change, no code generation change is made if there is no configuration change.

  • A lot of functions now take the *Options object as an additional parameter.
  • A new option has been added, primitive-mapping, which maps the primitive type to the actual type (int32 => null.Int32 for example).
  • README has been updated to inform users of the new functionality.

Note that primitive-mapping is only available in the YAML configuration at the moment (no flags). I am not sure if it is desirable to add the flags / what is the best way to do it, so I left it out.

@jamietanna
Copy link
Member

@deepmap-marcinr is this one we can take inspiration from / will be replaced by your work in the v2 side of things?

@jamietanna jamietanna reopened this Jan 25, 2024
@jamietanna
Copy link
Member

Apologies, meant to close #458 🫣

danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
As noted in oapi-codegen#428, there are some cases where it can be useful to set the
field ordering.

This adds support for the `x-order` extension used by other OpenAPI
parsers and generators, and ensures that we return keys sorted by that
order, if present.

This also adds a relevant test case + unit tests to validate
functionality.

Closes oapi-codegen#428.

Co-authored-by: Filinto Duran <filinto@diagrid.io>
Signed-off-by: Filinto Duran <filinto@diagrid.io>
Co-authored-by: Andrew Rusakow <psihatter@gmail.com>
Co-authored-by: Jamie Tanna <jamie@jamietanna.co.uk>
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