I have an endpoint with multiple request mappings like:
@PutMapping(path = {
"/A/{ACode}/B/{BCode}/C/{CCode}/D/{DCode}",
"/A/{ACode}/B/{BCode}/D/{DCode}",
"/A/{ACode}/C/{CCode}/D/{DCode}",
"/A/{ACode}/D/{DCode}"
})
where ACode, BCode, CCode and DCode are all path variables. B, C and their respective codes are optional while A, D and their respective codes are mandatory.
I can call the above API in these ways:
PUT /A/IN/B/delhi/C/central/D/110001
PUT /A/IN/B/delhi/D/110001
PUT /A/IN/C/central/D/110001
PUT /A/IN/D/110001
I'm trying to combine all of these request mappings into a single regex which can match all of these combinations.
I tried using this regex in mapping but it doesn't work:
@PutMapping(path = {
"A/{ACode:[A-Z]+}(/B/{BCode:[a-z0-9-]+})?(/C/{CCode:[a-z0-9-]+})?/D/{DCode:[a-z0-9-]+}"
})
And this one works, but it doesn't make B, C and respective codes optional, so cannot be used:
@PutMapping(path = {
"A/{ACode:[A-Z]+}/B/{BCode:[a-z0-9-]+}/C/{CCode:[a-z0-9-]+}/D/{DCode:[a-z0-9-]+}"
})
Is there anything wrong with the regex I used or is there any workaround for achieving this kind of functionality apart from using request params in place of path variables?
Thanks for help!