OpenAPITools / OpenAPITools/openapi-generator
[REQ] Feature Request Description
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hello,
I have a question about the groups validation constraints. There is a way to specify differents validations constraints the same property fields on a data model for different endpoints ?
The idea is to have only one data model and specify different constraints validations for put, post, patch, ... .
I know it's possible to do it if we specify group validations and add the @Validated(groups {...}) in requestMapping definition.
If it's not possible, the other way will be to use inheritance in the openapi contract and isolate validation rules directly in the childs model.
Like that, we can (re)defined the validations rules for each properties.
For example :
/medicalBook/patient:
post:
tags:
- medicalBook
operationId: addPatient
requestBody:
description: create new patient
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/PatientCreateRequest"
put:
tags:
- medicalBook
operationId: addPatient
requestBody:
description: create new patient
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/PatientUpdateRequest"
PatientRequest:
title: Object mapping for patient creation
type: object
properties:
firstname:
description: patient's firstname
type: string
lastname:
description: patient's lastname
type: string
email:
description: patient's email
type: string
format: email
PatientCreateRequest:
allOf:
- $ref: '#/components/schemas/PatientRequest'
- type: object
required:
- lastname
PatientUpdateRequest:
allOf:
- $ref: '#/components/schemas/PatientRequest'
- type: object
required:
- email
Like that, if we use the PatientUpdateRequest in the put endpoint, only email will be required.
I don't know if my explanation are good.
Thank you for reading.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points. Start by locating OpenAPI Generator handling for validation groups and schema inheritance, then determine whether differing constraints for POST, PUT, and PATCH are supported. Done would require an agreed behavior and tests covering the requested endpoint-specific constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100