Skip to content

configuration for allow additional properties on any schema #881

@paivagustavo

Description

@paivagustavo

I would like to file a feature request to allow setting loose validation to all schemas.

I'm using oapi-codegen to generate the models for a very large and complex third-party schema. This third party schema can be updated with new fields at any time and might brake my API if I don't update it with these new fields.

Sadly I can't add the field struct to allow additional properties since these structs are auto generated. It would be helpful if I could have a way to allow additional properties for all my schemas.

As a workaround, i'm using the OnAddOperation to set it, but it would be so much better if it was possible to set it as part of the api configuration.

// Loosen up schema validation to allow additional properties
apiConfig.OnAddOperation = append(apiConfig.OnAddOperation, func(oapi *huma.OpenAPI, op *huma.Operation) {
	for _, schema := range oapi.Components.Schemas.Map() {
		schema.AdditionalProperties = true
	}
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions