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
  • Issues
  • #2734
Closed
Open
Issue created Apr 24, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][C++][Pistache-server] (Regression) Server rejects the input request

Created by: CyrilleBenard

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

The issue is almost new and seems to be related to the use of the new nlohmann::json API (?)

When a request has been described in YAML with a body content owning 2 fields (only one required), if the client sends the request with only one field, the pistache-server rejects and answer with a HTTP 500 - "[json.exception.out_of_range.403] key 'field2' not found"

I must add that the 'field2' was defined as a 'anyOf' string, see below.

openapi-generator version

Current master 4.0.0-SNAPSHOT

This is a regression. It has worked, at least, up to the commit 84b99fea546ec116e399625239a6991ebabd3a94

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check anyOf in request content
servers:
  - url: '{apiRoot}/'
    variables:
      apiRoot:
        default: https://example.com
        description: Internal ref filename is check_anyOf_in_req_content.yaml
paths:
  /CheckAnyOf:
    post:
      summary: Check AnyOf generation
      operationId: list
      tags:
        - Check
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Content"

      responses:
        '200':
          description: Everythings gonna be alright
          headers:
            x-next:
              description: Everythings gonna be alright
              schema:
                type: string
          content:
            application/json:
              schema:
                type: string
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                type: string

components:
  schemas:

    PresenceState:
      anyOf:
      - type: string
        enum:
          - "IN"
          - "OUT"
          - "UNKNOWN"
      - type: string

    Content:
      type: object
      required:
        - field1
      properties:
        field1:
          type: string
        field2:
          $ref: "#/components/schemas/PresenceState"
                                                                        
Command line used for generation

Generate :

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -c ./config.json -o .

Compile all files and link:

(cd impl && ln -s ../main-api-server.cpp ./main.cpp)

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/CheckApi.o api/CheckApi.cpp
g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/impl/CheckApiImpl.o impl/CheckApiImpl.cpp
g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/impl/main.o impl/main.cpp
g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/model/Content.o model/Content.cpp
g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/model/PresenceState.o model/PresenceState.cpp
g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/model/Helpers.o model/Helpers.cpp

ar -rc obj/model/libmodel.a obj/model/Content.o obj/model/PresenceState.o obj/model/Helpers.o

g++ -g   -o server-MsUnderTest obj/api/CheckApi.o obj/impl/CheckApiImpl.o obj/impl/main.o obj/model/libmodel.a -lpistache -lpthread
Steps to reproduce

Launch the generated server listening on the TCP port 8080

Send the request with only 1 field content, with curl (for example) :

curl -X POST "http://localhost:8080/CheckAnyson" -H  "Content-Type: application/json" -d "{\"field1\":\"string\"}"

The result will be :

[json.exception.out_of_range.403] key 'field2' not found

Send the request with the 2 fields :

curl -X POST "http://localhost:8080/CheckAnyOf" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"field1\":\"string\",\"field2\":\"string\"}"

The result will be :

"Everythings gonna be alright"
Related issues/PRs

N/A

Suggest a fix

One suggested fix in the comment below EDIT: One patch delivered to fix the appropriated code. See below

Assignee
Assign to
Time tracking