OpenAPITools / OpenAPITools/openapi-generator

[BUG] Erlang-server schema validation failure for json string body

Open
#2,926 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Erlang
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

Not sure if it's because of my spec, but I'm opening it to get some help.
Starting from the swagger 2 API spec in the below yaml, I run the generator for erlang-server.
THis produces the openapi.json priv file and .erl stuff.
Among my APIs I have a post with a json string body. This API fails with the following info log:

Unable to process request for 'RootPost': {wrong_param,binary,schema,#{error => {schema_not_found,"#/components/schemas/binary"},type => schema_invalid}}

The failure occurs in *_api.erl file around here:

validate_with_schema(Body, Definition, ValidatorState) ->
    jesse_schema_validator:validate_with_state(
        [{<<"$ref">>, Definition}],
        Body,
        ValidatorState
    ).

I took deps from the README.md

    {jesse,  {git, "https://github.com/for-GET/jesse.git", {tag, "1.5.2"}}},
    {jsx,               {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.9.0"}}},
    {cowboy,            {git, "https://github.com/ninenines/cowboy.git", {tag, "2.5.0"}}}
openapi-generator version

4.0.1-SNAPSHOT
not a regration afaik

OpenAPI declaration file content or url

This is the swagger 2 input yaml:

paths:
  /:
    post:
      tags:
        - index
      description: "Create a new Table Index"
      parameters:
      - name: "index"
        in: "body"
        description: "Table Index to create up"
        schema:
          type: "string"
      responses:
        201:
          description: "New Index Created"

This is the openapi3 output json from the cli

"paths" : {
    "/" : {
      "post" : {
        "tags" : [ "index" ],
        "description" : "Create a new Table Index",
        "requestBody" : {
          "description" : "Table Index to create up",
          "content" : {
            "*/*" : {
              "schema" : {
                "type" : "string"
              }
            }
          },
          "required" : false
        },
        "responses" : {
          "201" : {
            "description" : "New Index Created",
            "content" : { }
          }
        },
        "x-codegen-request-body-name" : "index"
      }
    },
Command line used for generation
docker run --rm \
	-v $(pwd):/local \
	openapitools/openapi-generator-cli \
	generate \
	-i /local/priv/swagger.yaml \
	-g erlang-server \
	-o /local/out/
Steps to reproduce

Start application and
curl -X POST "http://localhost:5678/" -H "Content-Type: application/json" -d '"hello"'

Suggest a fix

Possibly there should be no schema (no /components/schemas) to validate at all for a json string (?)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided swagger.yaml, generator command, and curl request, then inspect the generated *_api.erl around validate_with_schema/3 and compare it with the openapi.json output. Done means a JSON string body no longer produces schema_not_found for components/schemas/binary and the generated erlang-server request validation behaves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang, java, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.