[C++][Pistache-server] string with pattern (regex) is not treated
Created by: CyrilleBenard
Description
The generator does not consider the pattern "inside" a string type. I mean, when the openapi file describes the below syntax :
type: string
pattern: '^(pat-[0-9]+)$'
The generator does not take into account the pattern restriction. No dedicated code is generated
openapi-generator version
Current master : 3.3.1-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.0.0
info:
version: 1.0.0
title: Check generation of string + pattern
description: Internal ref filename is check_pattern.yaml
servers:
- url: http://localhost:8080
paths:
/stair1:
post:
summary: blabla
operationId: check_generation
tags:
- Stair1
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Content'
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
type: string
default:
description: Unexpected error
components:
schemas:
Content:
type: string
pattern: '^(pat-[0-9]+)$'
Command line used for generation
Generate :
openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -c ./config.json -o .
Compile :
g++ -c -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/Stair1Api.o api/Stair1Api.cpp
Steps to reproduce
Generate & compile
Related issues/PRs
N/A
Suggest a fix/enhancement
Each variable should be validated with the pattern before any other treatment, in case there is a pattern to apply, of course. If the string (other type ?) does not match, return a dedicated HTTP error code 4xx : 412 ? 422 ? or the "generic" 400
As the pattern is regex compliant, the C++ std::regex lib may be used and the pattern transmitted as this to the std::regex_match method.