Skip to content

[BUG][C++] special characters and case sensitivity and key "operator" in properties not respected #4320

Closed
@AIexG

Description

@AIexG

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When generating a server stub, cpp-restbed-server in my case, all functions reading the values through the keys of a JSON request will automatically stripe certain special characters from the keys set the first letter to uppercase and add an underscore to certain keywords (e.g. operator). This causes the pt.put(), pt.get() etc, which apparently are case sensitive to fail aquiring and passing data to and from a JSON file/array.

The OAS also states that keys are case sensitive

All field names in the specification are case sensitive. This includes all fields that are used as keys in a map, except where explicitly noted that keys are case insensitive.

I haven't confirmed if any other languages/generators are affected by this problem, but it might be possible!

openapi-generator version
  • 4.1.3
  • 4.2.0-SNAPSHOT
OpenAPI declaration file content or url

caseSensitive.yaml

openapi: 3.0.1
info:
  title: Case Sensitivity Demo
  contact:
    email: mail@example.com
  version: 1.0.0

paths:
  /demo:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/demoSchema'
        required: true
      responses:
        '405':
          description: 'Validation error'
          content: {}

components:
  schemas:      
    demoSchema:
      type: object
      properties:
        $dollarsign:
          type: string
        §paragraph:
          type: string
        operator:
          type: string
        Firstupper:
          type: string
        noupper: 
          type: string
        midUpper: 
          type: string
        ALLUPPER:
          type: string

Generates the following function toJsonString():

std::string DemoSchema::toJsonString()
{
	std::stringstream ss;
	ptree pt;
	pt.put("dollarsign", m_dollarsign); // should be "$dollarsign"
	pt.put("paragraph", m_paragraph); // should be "§paragraph"
	pt.put("_operator", m__operator); // should be "operator"
	pt.put("Firstupper", m_Firstupper); // alright
	pt.put("Noupper", m_Noupper); // should be "noupper"
	pt.put("MidUpper", m_MidUpper); // should be "midUpper"
	pt.put("ALLUPPER", m_ALLUPPER); // alright
	write_json(ss, pt, false);
	return ss.str();
}

comments indicate the expected output

Command line used for generation

java -jar openapi-generator-cli.jar generate -i .\caseSensitive.yaml -g cpp-restbed-server -o .\openapi-server\

Steps to reproduce

Simply don't use an uppercase letter as first character for a property key.

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions