Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !9251

[C++] [Pistache] Model validation, general overhaul

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/JulianGmp/pistache_overhaul into master Apr 13, 2021
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 40

Created by: JulianGmp

This PR includes a variety of smaller changes, as well as implementing model validation for the Pistache C++ server.

List of changes:

  • Implemented validation of model data through mustache templates, this validation includes...

    • enum values (both “inline” enums and enums as their own schema)
    • date and date-time formatted strings as per full-date/date-time in RFC3339
    • string length (min and max) using std::string::length
    • numeric validations for
      • min value (exclusive and non-exclusive)
      • max value (exclusive and non-exclusive)
      • multipleOf (Note this may cause issues for float/double, see https://swagger.io/docs/specification/data-models/data-types/ section “Multiples”)
    • Array length (min and max)
    • Unique array elements
    • Recursive validation for array elements, this includes all checks mentioned above
  • Generate arrays with uniqueItems: true as std::vectors. The current implementation used a type called Set which did not exist and caused build issues. The standard vector was chosen above a set to ensure the order of items remains intact (see https://github.com/OpenAPITools/openapi-generator/pull/5466#issuecomment-593305650);

  • Implement the == operator (and !=) for model classes. This is needed for checking if an array only has unique elements.

  • Change get functions for array type. They now just return a vector, instead of a const reference to the vector. This copies the underlying vector, which is expensive. My justification is: returning a const reference may still allow the caller to modify the individual elements of the vector, thus the get function may not be declared as const. This currently causes the issue that you have to use a const cast in your API impl, since the model is always passed by const reference. By copying the vector the get function can safely be declared as const, and the original data cannot be modified.

  • Create virtual methods handleParsingException and handleOperationException for API classes. These will map a thrown exception to an HTTP status code and a response. The intended use is to overload these if needed, to ensure a certain return structure for error cases that are handled in the API class (such as a json parsing error).

  • Made the API classes' base property static const. That way you can read the base path without having to create an instance of the API.

  • Smaller visual changes, for example one line namespace declarations.

  • Minor cleanups, for example passing an int32_t by value, not by const reference.

Caveats

  1. The template possibly generates some dead code arrays, see the discussion in https://github.com/OpenAPITools/openapi-generator/pull/9251#discussion_r624503266.
  2. The template does not validate all string formats, currently only date and date-time. Custom regex checking could be possible, but has not been implemented in this PR, See #1170.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

C++ technical committee: @ravinikam @stkrwork @etherealjoy @MartinDelille @muttleyxd

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/JulianGmp/pistache_overhaul